From 6969f5719268dec6459d9107e11a711dab3a18dd Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 11 Sep 2025 11:24:16 +0200 Subject: check_curl: improve option handling a bit --- plugins/check_curl.c | 10 +++++----- plugins/check_curl.d/config.h | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 0784fb8b..485a8744 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1139,7 +1139,7 @@ mp_state_enum check_http(const check_curl_config config, check_curl_working_stat } /* make sure the status line matches the response we are looking for */ - if (!expected_statuscode(global_state.status_line.first_line, config.server_expect)) { + if (!expected_statuscode(global_state.status_line.first_line, config.server_expect.string)) { if (workingState.serverPort == HTTP_PORT) { snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host: %s\n"), global_state.status_line.first_line); @@ -1153,7 +1153,7 @@ mp_state_enum check_http(const check_curl_config config, check_curl_working_stat } mp_state_enum result = STATE_OK; - if (config.server_expect_yn) { + if (config.server_expect.is_present) { snprintf(msg, DEFAULT_BUFFER_SIZE, _("Status line output matched \"%s\" - "), config.server_expect); if (verbose) { @@ -1893,9 +1893,9 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) { result.config.string_expect[MAX_INPUT_BUFFER - 1] = 0; break; case 'e': /* string or substring */ - strncpy(result.config.server_expect, optarg, MAX_INPUT_BUFFER - 1); - result.config.server_expect[MAX_INPUT_BUFFER - 1] = 0; - result.config.server_expect_yn = true; + strncpy(result.config.server_expect.string, optarg, MAX_INPUT_BUFFER - 1); + result.config.server_expect.string[MAX_INPUT_BUFFER - 1] = 0; + result.config.server_expect.is_present = true; break; case 'T': /* Content-type */ result.config.http_content_type = strdup(optarg); diff --git a/plugins/check_curl.d/config.h b/plugins/check_curl.d/config.h index 25cfeda3..7566b19c 100644 --- a/plugins/check_curl.d/config.h +++ b/plugins/check_curl.d/config.h @@ -105,8 +105,10 @@ typedef struct { thresholds *thlds; size_t min_page_len; size_t max_page_len; - char server_expect[MAX_INPUT_BUFFER]; - bool server_expect_yn; + struct { + char string[MAX_INPUT_BUFFER]; + bool is_present; + } server_expect; char string_expect[MAX_INPUT_BUFFER]; char header_expect[MAX_INPUT_BUFFER]; mp_state_enum onredirect; @@ -154,8 +156,11 @@ check_curl_config check_curl_config_init() { .thlds = NULL, .min_page_len = 0, .max_page_len = 0, - .server_expect = HTTP_EXPECT, - .server_expect_yn = false, + .server_expect = + { + .string = HTTP_EXPECT, + .is_present = false, + }, .string_expect = "", .header_expect = "", .onredirect = STATE_OK, -- cgit v1.2.3-74-g34f1