From 178e9a02e367ab4527129ddbc623401e245d00b2 Mon Sep 17 00:00:00 2001 From: inqrphl <32687873+inqrphl@users.noreply.github.com> Date: Tue, 19 May 2026 16:01:43 +0200 Subject: check_http and check_curl: custom timeout return state (#2266) check_curl + check_http: hdd cli argument to return custom states on timeout --------- Co-authored-by: Ahmet Oeztuerk --- plugins/t/check_curl.t | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'plugins/t/check_curl.t') diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 0f4d0de7..7ec8ca06 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t @@ -13,7 +13,7 @@ use vars qw($tests $has_ipv6); BEGIN { use NPTest; $has_ipv6 = NPTest::has_ipv6(); - $tests = $has_ipv6 ? 57 : 92; + $tests = $has_ipv6 ? 65 : 100; plan tests => $tests; } @@ -69,7 +69,32 @@ $res = NPTest->testCmd( ); cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) -like( $res->output, "/cURL returned 28 - Connection timed out after/", "Output OK"); +like( $res->output, "/cURL returned 28 - (Connection|Operation) timed out after/", "Output OK"); + +# timeout return results can be changed using --timeout-result option +$res = NPTest->testCmd( + "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3 --timeout-result ok" + ); +like( $res->output, "/cURL returned 28 - (Connection|Operation) timed out after/", "Output OK"); +cmp_ok( $res->return_code, "==", 0, "Return code is correct due argument: --timeout-result ok"); + +$res = NPTest->testCmd( + "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3 --timeout-result warning" + ); +like( $res->output, "/cURL returned 28 - (Connection|Operation) timed out after/", "Output OK"); +cmp_ok( $res->return_code, "==", 1, "Return code is correct due argument: --timeout-result warning"); + +$res = NPTest->testCmd( + "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3 --timeout-result 2" + ); +like( $res->output, "/cURL returned 28 - (Connection|Operation) timed out after/", "Output OK"); +cmp_ok( $res->return_code, "==", 2, "Return code is correct due argument: --timeout-result 2"); + +$res = NPTest->testCmd( + "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3 --timeout-result 3" + ); +like( $res->output, "/cURL returned 28 - (Connection|Operation) timed out after/", "Output OK"); +cmp_ok( $res->return_code, "==", 3, "Return code is correct due argument: --timeout-result 3"); $res = NPTest->testCmd( "./$plugin $hostname_invalid -wt 1 -ct 2" -- cgit v1.2.3-74-g34f1