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/check_http.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'plugins/check_http.c') diff --git a/plugins/check_http.c b/plugins/check_http.c index 71f94b91..73e4f3b6 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -205,7 +205,8 @@ bool process_arguments(int argc, char **argv) { SNI_OPTION, MAX_REDIRS_OPTION, CONTINUE_AFTER_CHECK_CERT, - STATE_REGEX + STATE_REGEX, + TIMEOUT_RESULT }; int option = 0; @@ -247,6 +248,7 @@ bool process_arguments(int argc, char **argv) { {"extended-perfdata", no_argument, 0, 'E'}, {"show-body", no_argument, 0, 'B'}, {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, + {"timeout-result", required_argument, 0, TIMEOUT_RESULT}, {0, 0, 0, 0}}; if (argc < 2) { @@ -298,6 +300,21 @@ bool process_arguments(int argc, char **argv) { socket_timeout = atoi(optarg); } break; + case TIMEOUT_RESULT: + if (!strcmp(optarg, "0") || !strcasecmp(optarg, "ok")) { + socket_timeout_state = STATE_OK; + } else if (!strcmp(optarg, "1") || !strcasecmp(optarg, "warning")) { + socket_timeout_state = STATE_WARNING; + } else if (!strcmp(optarg, "2") || !strcasecmp(optarg, "critical")) { + socket_timeout_state = STATE_CRITICAL; + } else if (!strcmp(optarg, "3") || !strcasecmp(optarg, "unknown")) { + socket_timeout_state = STATE_UNKNOWN; + } else { + usage2(_("Invalid timeout-result state option, give either a return code or state " + "name in lowercase"), + optarg); + } + break; case 'c': /* critical time threshold */ critical_thresholds = optarg; break; @@ -1032,7 +1049,7 @@ int check_http(void) { printf("SSL initialized\n"); } if (result != STATE_OK) { - die(STATE_CRITICAL, _("HTTP CRITICAL - SSL error\n")); + die(STATE_CRITICAL, _("HTTP CRITICAL - SSL error\n")); } microsec_ssl = deltime(tv_temp); elapsed_time_ssl = (double)microsec_ssl / 1.0e6; @@ -1883,6 +1900,10 @@ void print_help(void) { printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); + printf(" %s\n", "--timeout-result=ok|warning|critical|unknown|0|1|2|3"); + printf(" %s\n", _("Timeouts default to returning STATE_CRITICAL.")); + printf(" %s\n", _("This argument changes the return state on timeouts.")); + printf(UT_VERBOSE); printf("\n"); -- cgit v1.2.3-74-g34f1