diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-15 00:22:35 +0200 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-15 00:22:35 +0200 |
commit | 166ce184c67a95192de8ec7f862fd965ea672ba8 (patch) | |
tree | 73034a9b56fc368fa4ba4b3777f655ccb2e1566b | |
parent | def42dc686736107f95d66fe8f35d78528b77779 (diff) | |
download | monitoring-plugins-166ce184c67a95192de8ec7f862fd965ea672ba8.tar.gz |
Fix regex matching
-rw-r--r-- | plugins/check_curl.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 7cb9745f..f8adc3d9 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -564,18 +564,24 @@ mp_subcheck check_http(const check_curl_config config, check_curl_working_state | |||
564 | if (errcode == 0) { | 564 | if (errcode == 0) { |
565 | // got a match | 565 | // got a match |
566 | if (config.invert_regex) { | 566 | if (config.invert_regex) { |
567 | sc_body_regex = mp_set_subcheck_state(sc_body_regex, STATE_OK); | ||
568 | } else { | ||
569 | sc_body_regex = mp_set_subcheck_state(sc_body_regex, config.state_regex); | 567 | sc_body_regex = mp_set_subcheck_state(sc_body_regex, config.state_regex); |
568 | } else { | ||
569 | sc_body_regex = mp_set_subcheck_state(sc_body_regex, STATE_OK); | ||
570 | } | 570 | } |
571 | } else { | 571 | } else if (errcode == REG_NOMATCH) { |
572 | xasprintf(&sc_body_regex.output, "%s not", sc_body_regex.output); | 572 | xasprintf(&sc_body_regex.output, "%s not", sc_body_regex.output); |
573 | // got no match | 573 | // got no match |
574 | if (config.invert_regex) { | 574 | if (config.invert_regex) { |
575 | sc_body_regex = mp_set_subcheck_state(sc_body_regex, config.state_regex); | ||
576 | } else { | ||
577 | sc_body_regex = mp_set_subcheck_state(sc_body_regex, STATE_OK); | 575 | sc_body_regex = mp_set_subcheck_state(sc_body_regex, STATE_OK); |
576 | } else { | ||
577 | sc_body_regex = mp_set_subcheck_state(sc_body_regex, config.state_regex); | ||
578 | } | 578 | } |
579 | } else { | ||
580 | // error in regexec | ||
581 | char error_buffer[DEFAULT_BUFFER_SIZE]; | ||
582 | regerror(errcode, &config.compiled_regex, &error_buffer[0], DEFAULT_BUFFER_SIZE); | ||
583 | xasprintf(&sc_body_regex.output, "regexec error: %s", error_buffer); | ||
584 | sc_body_regex = mp_set_subcheck_state(sc_body_regex, STATE_UNKNOWN); | ||
579 | } | 585 | } |
580 | 586 | ||
581 | mp_add_subcheck_to_subcheck(&sc_result, sc_body_regex); | 587 | mp_add_subcheck_to_subcheck(&sc_result, sc_body_regex); |