summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins-root/check_icmp.c18
-rw-r--r--plugins-root/check_icmp.d/check_icmp_helpers.c19
-rw-r--r--plugins-root/check_icmp.d/check_icmp_helpers.h2
-rw-r--r--plugins-root/t/check_icmp.t30
4 files changed, 16 insertions, 53 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 7360b435..55405b8a 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -431,8 +431,7 @@ check_icmp_config_wrapper process_arguments(int argc, char **argv) {
431 } 431 }
432 break; 432 break;
433 case 't': 433 case 't':
434 timeout = (unsigned int)strtoul(optarg, NULL, 0); 434 // WARNING Deprecated since execution time is determined by the other factors
435 // TODO die here and complain about wrong input
436 break; 435 break;
437 case 'H': { 436 case 'H': {
438 add_host_wrapper host_add_result = 437 add_host_wrapper host_add_result =
@@ -895,21 +894,6 @@ int main(int argc, char **argv) {
895 } 894 }
896 } 895 }
897 896
898 struct sigaction sig_action;
899 sig_action.sa_handler = NULL;
900 sig_action.sa_sigaction = check_icmp_timeout_handler;
901 sigfillset(&sig_action.sa_mask);
902 sig_action.sa_flags = SA_NODEFER | SA_RESTART | SA_SIGINFO;
903
904 sigaction(SIGINT, &sig_action, NULL);
905 sigaction(SIGHUP, &sig_action, NULL);
906 sigaction(SIGTERM, &sig_action, NULL);
907 sigaction(SIGALRM, &sig_action, NULL);
908 if (debug) {
909 printf("Setting alarm timeout to %u seconds\n", timeout);
910 }
911 alarm(timeout);
912
913 /* make sure we don't wait any longer than necessary */ 897 /* make sure we don't wait any longer than necessary */
914 struct timeval prog_start; 898 struct timeval prog_start;
915 gettimeofday(&prog_start, NULL); 899 gettimeofday(&prog_start, NULL);
diff --git a/plugins-root/check_icmp.d/check_icmp_helpers.c b/plugins-root/check_icmp.d/check_icmp_helpers.c
index 7a936cc9..ec786305 100644
--- a/plugins-root/check_icmp.d/check_icmp_helpers.c
+++ b/plugins-root/check_icmp.d/check_icmp_helpers.c
@@ -132,22 +132,3 @@ unsigned int ping_target_list_append(ping_target *list, ping_target *elem) {
132 132
133 return result; 133 return result;
134} 134}
135
136void check_icmp_timeout_handler(int signal, siginfo_t *info, void *ucontext) {
137 // Ignore unused arguments
138 (void)info;
139 (void)ucontext;
140 mp_subcheck timeout_sc = mp_subcheck_init();
141 timeout_sc = mp_set_subcheck_state(timeout_sc, socket_timeout_state);
142
143 if (signal == SIGALRM) {
144 xasprintf(&timeout_sc.output, _("timeout after %d seconds\n"), timeout);
145 } else {
146 xasprintf(&timeout_sc.output, _("timeout after %d seconds\n"), timeout);
147 }
148
149 mp_check overall = mp_check_init();
150 mp_add_subcheck_to_check(&overall, timeout_sc);
151
152 mp_exit(overall);
153}
diff --git a/plugins-root/check_icmp.d/check_icmp_helpers.h b/plugins-root/check_icmp.d/check_icmp_helpers.h
index 1b9372ce..dc6ea40b 100644
--- a/plugins-root/check_icmp.d/check_icmp_helpers.h
+++ b/plugins-root/check_icmp.d/check_icmp_helpers.h
@@ -66,5 +66,3 @@ typedef struct {
66 66
67ping_target_create_wrapper ping_target_create(struct sockaddr_storage address); 67ping_target_create_wrapper ping_target_create(struct sockaddr_storage address);
68unsigned int ping_target_list_append(ping_target *list, ping_target *elem); 68unsigned int ping_target_list_append(ping_target *list, ping_target *elem);
69
70void check_icmp_timeout_handler(int, siginfo_t *, void *);
diff --git a/plugins-root/t/check_icmp.t b/plugins-root/t/check_icmp.t
index 2c1d12e6..e68617cd 100644
--- a/plugins-root/t/check_icmp.t
+++ b/plugins-root/t/check_icmp.t
@@ -33,12 +33,12 @@ my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
33my $res; 33my $res;
34 34
35$res = NPTest->testCmd( 35$res = NPTest->testCmd(
36 "$sudo ./check_icmp -H $host_responsive -w 10000ms,100% -c 10000ms,100%" 36 "$sudo ./check_icmp -H $host_responsive -w 100ms,100% -c 100ms,100%"
37 ); 37 );
38is( $res->return_code, 0, "Syntax ok" ); 38is( $res->return_code, 0, "Syntax ok" );
39 39
40$res = NPTest->testCmd( 40$res = NPTest->testCmd(
41 "$sudo ./check_icmp -H $host_responsive -w 0ms,0% -c 10000ms,100%" 41 "$sudo ./check_icmp -H $host_responsive -w 0ms,0% -c 100ms,100%"
42 ); 42 );
43is( $res->return_code, 1, "Syntax ok, with forced warning" ); 43is( $res->return_code, 1, "Syntax ok, with forced warning" );
44 44
@@ -48,32 +48,32 @@ $res = NPTest->testCmd(
48is( $res->return_code, 2, "Syntax ok, with forced critical" ); 48is( $res->return_code, 2, "Syntax ok, with forced critical" );
49 49
50$res = NPTest->testCmd( 50$res = NPTest->testCmd(
51 "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -t 2" 51 "$sudo ./check_icmp -H $host_nonresponsive -w 100ms,100% -c 100ms,100%"
52 ); 52 );
53is( $res->return_code, 2, "Timeout - host nonresponsive" ); 53is( $res->return_code, 2, "Timeout - host nonresponsive" );
54 54
55$res = NPTest->testCmd( 55$res = NPTest->testCmd(
56 "$sudo ./check_icmp -w 10000ms,100% -c 10000ms,100%" 56 "$sudo ./check_icmp -w 100ms,100% -c 100ms,100%"
57 ); 57 );
58is( $res->return_code, 3, "No hostname" ); 58is( $res->return_code, 3, "No hostname" );
59 59
60$res = NPTest->testCmd( 60$res = NPTest->testCmd(
61 "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 0 -t 2" 61 "$sudo ./check_icmp -H $host_nonresponsive -w 100ms,100% -c 100ms,100% -n 1 -m 0"
62 ); 62 );
63is( $res->return_code, 0, "One host nonresponsive - zero required" ); 63is( $res->return_code, 0, "One host nonresponsive - zero required" );
64 64
65$res = NPTest->testCmd( 65$res = NPTest->testCmd(
66 "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 1 -t 2" 66 "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 100ms,100% -c 100ms,100% -n 1 -m 1"
67 ); 67 );
68is( $res->return_code, 0, "One of two host nonresponsive - one required" ); 68is( $res->return_code, 0, "One of two host nonresponsive - one required" );
69 69
70$res = NPTest->testCmd( 70$res = NPTest->testCmd(
71 "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 2" 71 "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 100ms,100% -c 100ms,100% -n 1 -m 2"
72 ); 72 );
73is( $res->return_code, 2, "One of two host nonresponsive - two required" ); 73is( $res->return_code, 2, "One of two host nonresponsive - two required" );
74 74
75$res = NPTest->testCmd( 75$res = NPTest->testCmd(
76 "$sudo ./check_icmp -H $host_responsive -s 127.0.15.15 -w 10000ms,100% -c 10000ms,100% -n 1 -m 2" 76 "$sudo ./check_icmp -H $host_responsive -s 127.0.15.15 -w 100ms,100% -c 100ms,100% -n 1 -m 2"
77 ); 77 );
78is( $res->return_code, 0, "IPv4 source_ip accepted" ); 78is( $res->return_code, 0, "IPv4 source_ip accepted" );
79 79
@@ -83,35 +83,35 @@ $res = NPTest->testCmd(
83is( $res->return_code, 0, "Try max packet size" ); 83is( $res->return_code, 0, "Try max packet size" );
84 84
85$res = NPTest->testCmd( 85$res = NPTest->testCmd(
86 "$sudo ./check_icmp -H $host_responsive -R 100,100 -n 1 -t 2" 86 "$sudo ./check_icmp -H $host_responsive -R 100,100 -n 1"
87 ); 87 );
88is( $res->return_code, 0, "rta works" ); 88is( $res->return_code, 0, "rta works" );
89$res = NPTest->testCmd( 89$res = NPTest->testCmd(
90 "$sudo ./check_icmp -H $host_responsive -P 80,90 -n 1 -t 2" 90 "$sudo ./check_icmp -H $host_responsive -P 80,90 -n 1"
91 ); 91 );
92is( $res->return_code, 0, "pl works" ); 92is( $res->return_code, 0, "pl works" );
93 93
94$res = NPTest->testCmd( 94$res = NPTest->testCmd(
95 "$sudo ./check_icmp -H $host_responsive -J 80,90 -t 2" 95 "$sudo ./check_icmp -H $host_responsive -J 80,90"
96 ); 96 );
97is( $res->return_code, 0, "jitter works" ); 97is( $res->return_code, 0, "jitter works" );
98 98
99$res = NPTest->testCmd( 99$res = NPTest->testCmd(
100 "$sudo ./check_icmp -H $host_responsive -M 4,3 -t 2" 100 "$sudo ./check_icmp -H $host_responsive -M 4,3"
101 ); 101 );
102is( $res->return_code, 0, "mos works" ); 102is( $res->return_code, 0, "mos works" );
103 103
104$res = NPTest->testCmd( 104$res = NPTest->testCmd(
105 "$sudo ./check_icmp -H $host_responsive -S 80,70 -t 2" 105 "$sudo ./check_icmp -H $host_responsive -S 80,70"
106 ); 106 );
107is( $res->return_code, 0, "score works" ); 107is( $res->return_code, 0, "score works" );
108 108
109$res = NPTest->testCmd( 109$res = NPTest->testCmd(
110 "$sudo ./check_icmp -H $host_responsive -O -t 2" 110 "$sudo ./check_icmp -H $host_responsive -O"
111 ); 111 );
112is( $res->return_code, 0, "order works" ); 112is( $res->return_code, 0, "order works" );
113 113
114$res = NPTest->testCmd( 114$res = NPTest->testCmd(
115 "$sudo ./check_icmp -H $host_responsive -O -S 80,70 -M 4,3 -J 80,90 -P 80,90 -R 100,100 -t 2" 115 "$sudo ./check_icmp -H $host_responsive -O -S 80,70 -M 4,3 -J 80,90 -P 80,90 -R 100,100"
116 ); 116 );
117is( $res->return_code, 0, "order works" ); 117is( $res->return_code, 0, "order works" );