diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-13 12:49:06 +0200 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-13 12:49:06 +0200 |
| commit | 6ae8ba911018571afddcf51c08e3d32f5efa3b5a (patch) | |
| tree | 9ec1e2cdcf6aafcf6685a27569ec087907bb5045 /plugins/check_curl.c | |
| parent | 9afb5e2a6964aad149ca3ef0c175fcd510220505 (diff) | |
| download | monitoring-plugins-6ae8ba911018571afddcf51c08e3d32f5efa3b5a.tar.gz | |
check_curl: test adaption and output adaption
Diffstat (limited to 'plugins/check_curl.c')
| -rw-r--r-- | plugins/check_curl.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 17fb5564..89173808 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
| @@ -238,7 +238,28 @@ mp_subcheck check_http(const check_curl_config config, check_curl_working_state | |||
| 238 | return sc_result; | 238 | return sc_result; |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | xasprintf(&sc_curl.output, "cURL performed query"); | 241 | /* get status line of answer, check sanity of HTTP code */ |
| 242 | if (curlhelp_parse_statusline(curl_state.header_buf->buf, curl_state.status_line) < 0) { | ||
| 243 | sc_result = mp_set_subcheck_state(sc_result, STATE_CRITICAL); | ||
| 244 | /* we cannot know the major/minor version here for sure as we cannot parse the first | ||
| 245 | * line */ | ||
| 246 | xasprintf(&sc_result.output, "HTTP/x.x unknown - Unparsable status line"); | ||
| 247 | return sc_result; | ||
| 248 | } | ||
| 249 | |||
| 250 | curl_state.status_line_initialized = true; | ||
| 251 | |||
| 252 | size_t page_len = get_content_length(curl_state.header_buf, curl_state.body_buf); | ||
| 253 | |||
| 254 | double total_time; | ||
| 255 | handle_curl_option_return_code( | ||
| 256 | curl_easy_getinfo(curl_state.curl, CURLINFO_TOTAL_TIME, &total_time), | ||
| 257 | "CURLINFO_TOTAL_TIME"); | ||
| 258 | |||
| 259 | xasprintf( | ||
| 260 | &sc_curl.output, "%s %d %s - %ld bytes in %.3f second response time", | ||
| 261 | string_statuscode(curl_state.status_line->http_major, curl_state.status_line->http_minor), | ||
| 262 | curl_state.status_line->http_code, curl_state.status_line->msg, page_len, total_time); | ||
| 242 | sc_curl = mp_set_subcheck_state(sc_curl, STATE_OK); | 263 | sc_curl = mp_set_subcheck_state(sc_curl, STATE_OK); |
| 243 | mp_add_subcheck_to_subcheck(&sc_result, sc_curl); | 264 | mp_add_subcheck_to_subcheck(&sc_result, sc_curl); |
| 244 | 265 | ||
| @@ -264,10 +285,6 @@ mp_subcheck check_http(const check_curl_config config, check_curl_working_state | |||
| 264 | 285 | ||
| 265 | // total time the query took | 286 | // total time the query took |
| 266 | mp_perfdata pd_total_time = perfdata_init(); | 287 | mp_perfdata pd_total_time = perfdata_init(); |
| 267 | double total_time; | ||
| 268 | handle_curl_option_return_code( | ||
| 269 | curl_easy_getinfo(curl_state.curl, CURLINFO_TOTAL_TIME, &total_time), | ||
| 270 | "CURLINFO_TOTAL_TIME"); | ||
| 271 | mp_perfdata_value pd_val_total_time = mp_create_pd_value(total_time); | 288 | mp_perfdata_value pd_val_total_time = mp_create_pd_value(total_time); |
| 272 | pd_total_time.value = pd_val_total_time; | 289 | pd_total_time.value = pd_val_total_time; |
| 273 | pd_total_time = mp_pd_set_thresholds(pd_total_time, config.thlds); | 290 | pd_total_time = mp_pd_set_thresholds(pd_total_time, config.thlds); |
| @@ -360,17 +377,6 @@ mp_subcheck check_http(const check_curl_config config, check_curl_working_state | |||
| 360 | return sc_result; | 377 | return sc_result; |
| 361 | } | 378 | } |
| 362 | 379 | ||
| 363 | /* get status line of answer, check sanity of HTTP code */ | ||
| 364 | if (curlhelp_parse_statusline(curl_state.header_buf->buf, curl_state.status_line) < 0) { | ||
| 365 | sc_result = mp_set_subcheck_state(sc_result, STATE_CRITICAL); | ||
| 366 | /* we cannot know the major/minor version here for sure as we cannot parse the first | ||
| 367 | * line */ | ||
| 368 | xasprintf(&sc_result.output, "HTTP/x.x unknown - Unparsable status line"); | ||
| 369 | return sc_result; | ||
| 370 | } | ||
| 371 | |||
| 372 | curl_state.status_line_initialized = true; | ||
| 373 | |||
| 374 | /* get result code from cURL */ | 380 | /* get result code from cURL */ |
| 375 | long httpReturnCode; | 381 | long httpReturnCode; |
| 376 | handle_curl_option_return_code( | 382 | handle_curl_option_return_code( |
| @@ -578,7 +584,6 @@ mp_subcheck check_http(const check_curl_config config, check_curl_working_state | |||
| 578 | 584 | ||
| 579 | // size a.k.a. page length | 585 | // size a.k.a. page length |
| 580 | mp_perfdata pd_page_length = perfdata_init(); | 586 | mp_perfdata pd_page_length = perfdata_init(); |
| 581 | size_t page_len = get_content_length(curl_state.header_buf, curl_state.body_buf); | ||
| 582 | mp_perfdata_value pd_val_page_length = mp_create_pd_value(page_len); | 587 | mp_perfdata_value pd_val_page_length = mp_create_pd_value(page_len); |
| 583 | pd_page_length.value = pd_val_page_length; | 588 | pd_page_length.value = pd_val_page_length; |
| 584 | pd_page_length.label = "size"; | 589 | pd_page_length.label = "size"; |
