From 0f8690c19b352549961c46c75c7307814e255db0 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 9 Jun 2025 12:33:15 +0200 Subject: Remove check_icmp text regex tests --- plugins-root/t/check_icmp.t | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'plugins-root/t/check_icmp.t') diff --git a/plugins-root/t/check_icmp.t b/plugins-root/t/check_icmp.t index de1d88d2..2c1d12e6 100644 --- a/plugins-root/t/check_icmp.t +++ b/plugins-root/t/check_icmp.t @@ -18,9 +18,6 @@ if ($allow_sudo eq "yes" or $> == 0) { } my $sudo = $> == 0 ? '' : 'sudo'; -my $successOutput = '/OK - .*? rta (?:[\d\.]+ms)|(?:nan), lost \d+%/'; -my $failureOutput = '/(WARNING|CRITICAL) - .*? rta (?:[\d\.]+ms > [\d\.]+ms|nan)/'; - my $host_responsive = getTestParameter( "NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", "localhost" ); @@ -39,105 +36,82 @@ $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -w 10000ms,100% -c 10000ms,100%" ); is( $res->return_code, 0, "Syntax ok" ); -like( $res->output, $successOutput, "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -w 0ms,0% -c 10000ms,100%" ); is( $res->return_code, 1, "Syntax ok, with forced warning" ); -like( $res->output, $failureOutput, "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -w 0,0% -c 0,0%" ); is( $res->return_code, 2, "Syntax ok, with forced critical" ); -like( $res->output, $failureOutput, "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -t 2" ); is( $res->return_code, 2, "Timeout - host nonresponsive" ); -like( $res->output, '/pl=100%/', "Error contains 'pl=100%' string (for 100% packet loss)" ); -like( $res->output, '/rta=U/', "Error contains 'rta=U' string" ); $res = NPTest->testCmd( "$sudo ./check_icmp -w 10000ms,100% -c 10000ms,100%" ); is( $res->return_code, 3, "No hostname" ); -like( $res->output, '/No hosts to check/', "Output with appropriate error message"); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 0 -t 2" ); is( $res->return_code, 0, "One host nonresponsive - zero required" ); -like( $res->output, $successOutput, "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 1 -t 2" ); is( $res->return_code, 0, "One of two host nonresponsive - one required" ); -like( $res->output, $successOutput, "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 2" ); is( $res->return_code, 2, "One of two host nonresponsive - two required" ); -like( $res->output, $failureOutput, "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -s 127.0.15.15 -w 10000ms,100% -c 10000ms,100% -n 1 -m 2" ); is( $res->return_code, 0, "IPv4 source_ip accepted" ); -like( $res->output, $successOutput, "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -b 65507" ); is( $res->return_code, 0, "Try max packet size" ); -like( $res->output, $successOutput, "Output OK - Didn't overflow" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -R 100,100 -n 1 -t 2" ); is( $res->return_code, 0, "rta works" ); -like( $res->output, $successOutput, "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -P 80,90 -n 1 -t 2" ); is( $res->return_code, 0, "pl works" ); -like( $res->output, '/lost 0%/', "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -J 80,90 -t 2" ); is( $res->return_code, 0, "jitter works" ); -like( $res->output, '/jitter \d/', "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -M 4,3 -t 2" ); is( $res->return_code, 0, "mos works" ); -like( $res->output, '/MOS \d/', "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -S 80,70 -t 2" ); is( $res->return_code, 0, "score works" ); -like( $res->output, '/Score \d/', "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -O -t 2" ); is( $res->return_code, 0, "order works" ); -like( $res->output, '/Packets in order/', "Output OK" ); $res = NPTest->testCmd( "$sudo ./check_icmp -H $host_responsive -O -S 80,70 -M 4,3 -J 80,90 -P 80,90 -R 100,100 -t 2" ); is( $res->return_code, 0, "order works" ); -like( $res->output, '/Packets in order/', "Output OK" ); -like( $res->output, '/Score \d/', "Output OK" ); -like( $res->output, '/MOS \d/', "Output OK" ); -like( $res->output, '/jitter \d/', "Output OK" ); -like( $res->output, '/lost 0%/', "Output OK" ); -like( $res->output, $successOutput, "Output OK" ); -- cgit v1.2.3-74-g34f1 From 2bea8e9522af1c454d1a6a618402f9f342730406 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 20 Jun 2025 10:04:34 +0200 Subject: check_icmp: Remove signal handling and timeouts The timeout option was redundant in that the runtime of check_icmp was always limited by the input parameters and therefore timeout gets removed with this commit to avoid that confusion. The rest of the signal handlings was removed too, since the added complexity does not provide sufficient returns. If check_icmp gets a signal, it now dies like most other programs instead of trying to save some things and return a (arguably wrong) result. --- plugins-root/check_icmp.c | 18 +--------------- plugins-root/check_icmp.d/check_icmp_helpers.c | 19 ---------------- plugins-root/check_icmp.d/check_icmp_helpers.h | 2 -- plugins-root/t/check_icmp.t | 30 +++++++++++++------------- 4 files changed, 16 insertions(+), 53 deletions(-) (limited to 'plugins-root/t/check_icmp.t') 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) { } break; case 't': - timeout = (unsigned int)strtoul(optarg, NULL, 0); - // TODO die here and complain about wrong input + // WARNING Deprecated since execution time is determined by the other factors break; case 'H': { add_host_wrapper host_add_result = @@ -895,21 +894,6 @@ int main(int argc, char **argv) { } } - struct sigaction sig_action; - sig_action.sa_handler = NULL; - sig_action.sa_sigaction = check_icmp_timeout_handler; - sigfillset(&sig_action.sa_mask); - sig_action.sa_flags = SA_NODEFER | SA_RESTART | SA_SIGINFO; - - sigaction(SIGINT, &sig_action, NULL); - sigaction(SIGHUP, &sig_action, NULL); - sigaction(SIGTERM, &sig_action, NULL); - sigaction(SIGALRM, &sig_action, NULL); - if (debug) { - printf("Setting alarm timeout to %u seconds\n", timeout); - } - alarm(timeout); - /* make sure we don't wait any longer than necessary */ struct timeval prog_start; 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) { return result; } - -void check_icmp_timeout_handler(int signal, siginfo_t *info, void *ucontext) { - // Ignore unused arguments - (void)info; - (void)ucontext; - mp_subcheck timeout_sc = mp_subcheck_init(); - timeout_sc = mp_set_subcheck_state(timeout_sc, socket_timeout_state); - - if (signal == SIGALRM) { - xasprintf(&timeout_sc.output, _("timeout after %d seconds\n"), timeout); - } else { - xasprintf(&timeout_sc.output, _("timeout after %d seconds\n"), timeout); - } - - mp_check overall = mp_check_init(); - mp_add_subcheck_to_check(&overall, timeout_sc); - - mp_exit(overall); -} 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 { ping_target_create_wrapper ping_target_create(struct sockaddr_storage address); unsigned int ping_target_list_append(ping_target *list, ping_target *elem); - -void 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", my $res; $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -w 10000ms,100% -c 10000ms,100%" + "$sudo ./check_icmp -H $host_responsive -w 100ms,100% -c 100ms,100%" ); is( $res->return_code, 0, "Syntax ok" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -w 0ms,0% -c 10000ms,100%" + "$sudo ./check_icmp -H $host_responsive -w 0ms,0% -c 100ms,100%" ); is( $res->return_code, 1, "Syntax ok, with forced warning" ); @@ -48,32 +48,32 @@ $res = NPTest->testCmd( is( $res->return_code, 2, "Syntax ok, with forced critical" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -t 2" + "$sudo ./check_icmp -H $host_nonresponsive -w 100ms,100% -c 100ms,100%" ); is( $res->return_code, 2, "Timeout - host nonresponsive" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -w 10000ms,100% -c 10000ms,100%" + "$sudo ./check_icmp -w 100ms,100% -c 100ms,100%" ); is( $res->return_code, 3, "No hostname" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 0 -t 2" + "$sudo ./check_icmp -H $host_nonresponsive -w 100ms,100% -c 100ms,100% -n 1 -m 0" ); is( $res->return_code, 0, "One host nonresponsive - zero required" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 1 -t 2" + "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 100ms,100% -c 100ms,100% -n 1 -m 1" ); is( $res->return_code, 0, "One of two host nonresponsive - one required" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 2" + "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 100ms,100% -c 100ms,100% -n 1 -m 2" ); is( $res->return_code, 2, "One of two host nonresponsive - two required" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -s 127.0.15.15 -w 10000ms,100% -c 10000ms,100% -n 1 -m 2" + "$sudo ./check_icmp -H $host_responsive -s 127.0.15.15 -w 100ms,100% -c 100ms,100% -n 1 -m 2" ); is( $res->return_code, 0, "IPv4 source_ip accepted" ); @@ -83,35 +83,35 @@ $res = NPTest->testCmd( is( $res->return_code, 0, "Try max packet size" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -R 100,100 -n 1 -t 2" + "$sudo ./check_icmp -H $host_responsive -R 100,100 -n 1" ); is( $res->return_code, 0, "rta works" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -P 80,90 -n 1 -t 2" + "$sudo ./check_icmp -H $host_responsive -P 80,90 -n 1" ); is( $res->return_code, 0, "pl works" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -J 80,90 -t 2" + "$sudo ./check_icmp -H $host_responsive -J 80,90" ); is( $res->return_code, 0, "jitter works" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -M 4,3 -t 2" + "$sudo ./check_icmp -H $host_responsive -M 4,3" ); is( $res->return_code, 0, "mos works" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -S 80,70 -t 2" + "$sudo ./check_icmp -H $host_responsive -S 80,70" ); is( $res->return_code, 0, "score works" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -O -t 2" + "$sudo ./check_icmp -H $host_responsive -O" ); is( $res->return_code, 0, "order works" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -O -S 80,70 -M 4,3 -J 80,90 -P 80,90 -R 100,100 -t 2" + "$sudo ./check_icmp -H $host_responsive -O -S 80,70 -M 4,3 -J 80,90 -P 80,90 -R 100,100" ); is( $res->return_code, 0, "order works" ); -- cgit v1.2.3-74-g34f1 From 6bc2e75199519d0a7677dff09137558ef6eb761c Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 20 Jun 2025 10:28:45 +0200 Subject: Fix test with weird arguments --- plugins-root/t/check_icmp.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins-root/t/check_icmp.t') diff --git a/plugins-root/t/check_icmp.t b/plugins-root/t/check_icmp.t index e68617cd..cbf3dda5 100644 --- a/plugins-root/t/check_icmp.t +++ b/plugins-root/t/check_icmp.t @@ -73,7 +73,7 @@ $res = NPTest->testCmd( is( $res->return_code, 2, "One of two host nonresponsive - two required" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -s 127.0.15.15 -w 100ms,100% -c 100ms,100% -n 1 -m 2" + "$sudo ./check_icmp -H $host_responsive -s 127.0.15.15 -w 100ms,100% -c 100ms,100% -n 1" ); is( $res->return_code, 0, "IPv4 source_ip accepted" ); -- cgit v1.2.3-74-g34f1 From d2735eecd4c44ba4a2504304963e861a427e393e Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 20 Jun 2025 10:53:46 +0200 Subject: Fix number of tests --- plugins-root/t/check_icmp.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins-root/t/check_icmp.t') diff --git a/plugins-root/t/check_icmp.t b/plugins-root/t/check_icmp.t index cbf3dda5..d414c3c7 100644 --- a/plugins-root/t/check_icmp.t +++ b/plugins-root/t/check_icmp.t @@ -12,7 +12,7 @@ my $allow_sudo = getTestParameter( "NP_ALLOW_SUDO", "no" ); if ($allow_sudo eq "yes" or $> == 0) { - plan tests => 40; + plan tests => 17; } else { plan skip_all => "Need sudo to test check_icmp"; } -- cgit v1.2.3-74-g34f1