summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-11 11:24:16 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-11 11:24:16 +0200
commit6969f5719268dec6459d9107e11a711dab3a18dd (patch)
tree42424c36f4c3ffcb557cee7d6c670a874cd86640
parent977e0a7f8bd3700f8514b1409205296d42216ed9 (diff)
downloadmonitoring-plugins-6969f5719268dec6459d9107e11a711dab3a18dd.tar.gz
check_curl: improve option handling a bit
-rw-r--r--plugins/check_curl.c10
-rw-r--r--plugins/check_curl.d/config.h13
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
1139 } 1139 }
1140 1140
1141 /* make sure the status line matches the response we are looking for */ 1141 /* make sure the status line matches the response we are looking for */
1142 if (!expected_statuscode(global_state.status_line.first_line, config.server_expect)) { 1142 if (!expected_statuscode(global_state.status_line.first_line, config.server_expect.string)) {
1143 if (workingState.serverPort == HTTP_PORT) { 1143 if (workingState.serverPort == HTTP_PORT) {
1144 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host: %s\n"), 1144 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host: %s\n"),
1145 global_state.status_line.first_line); 1145 global_state.status_line.first_line);
@@ -1153,7 +1153,7 @@ mp_state_enum check_http(const check_curl_config config, check_curl_working_stat
1153 } 1153 }
1154 1154
1155 mp_state_enum result = STATE_OK; 1155 mp_state_enum result = STATE_OK;
1156 if (config.server_expect_yn) { 1156 if (config.server_expect.is_present) {
1157 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Status line output matched \"%s\" - "), 1157 snprintf(msg, DEFAULT_BUFFER_SIZE, _("Status line output matched \"%s\" - "),
1158 config.server_expect); 1158 config.server_expect);
1159 if (verbose) { 1159 if (verbose) {
@@ -1893,9 +1893,9 @@ check_curl_config_wrapper process_arguments(int argc, char **argv) {
1893 result.config.string_expect[MAX_INPUT_BUFFER - 1] = 0; 1893 result.config.string_expect[MAX_INPUT_BUFFER - 1] = 0;
1894 break; 1894 break;
1895 case 'e': /* string or substring */ 1895 case 'e': /* string or substring */
1896 strncpy(result.config.server_expect, optarg, MAX_INPUT_BUFFER - 1); 1896 strncpy(result.config.server_expect.string, optarg, MAX_INPUT_BUFFER - 1);
1897 result.config.server_expect[MAX_INPUT_BUFFER - 1] = 0; 1897 result.config.server_expect.string[MAX_INPUT_BUFFER - 1] = 0;
1898 result.config.server_expect_yn = true; 1898 result.config.server_expect.is_present = true;
1899 break; 1899 break;
1900 case 'T': /* Content-type */ 1900 case 'T': /* Content-type */
1901 result.config.http_content_type = strdup(optarg); 1901 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 {
105 thresholds *thlds; 105 thresholds *thlds;
106 size_t min_page_len; 106 size_t min_page_len;
107 size_t max_page_len; 107 size_t max_page_len;
108 char server_expect[MAX_INPUT_BUFFER]; 108 struct {
109 bool server_expect_yn; 109 char string[MAX_INPUT_BUFFER];
110 bool is_present;
111 } server_expect;
110 char string_expect[MAX_INPUT_BUFFER]; 112 char string_expect[MAX_INPUT_BUFFER];
111 char header_expect[MAX_INPUT_BUFFER]; 113 char header_expect[MAX_INPUT_BUFFER];
112 mp_state_enum onredirect; 114 mp_state_enum onredirect;
@@ -154,8 +156,11 @@ check_curl_config check_curl_config_init() {
154 .thlds = NULL, 156 .thlds = NULL,
155 .min_page_len = 0, 157 .min_page_len = 0,
156 .max_page_len = 0, 158 .max_page_len = 0,
157 .server_expect = HTTP_EXPECT, 159 .server_expect =
158 .server_expect_yn = false, 160 {
161 .string = HTTP_EXPECT,
162 .is_present = false,
163 },
159 .string_expect = "", 164 .string_expect = "",
160 .header_expect = "", 165 .header_expect = "",
161 .onredirect = STATE_OK, 166 .onredirect = STATE_OK,