diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2024-04-07 18:01:54 (GMT) |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2024-04-07 18:01:54 (GMT) |
commit | f29785f5035e489576d2ba74be774273b73dd149 (patch) | |
tree | 70cb8a4857e22b224152731253dd627572907458 /plugins/check_http.c | |
parent | 4c4031100a4520fe1e9a835e56b00e32b841f63e (diff) | |
download | monitoring-plugins-f29785f5035e489576d2ba74be774273b73dd149.tar.gz |
check_http/check_curl: added a --regex-state option to change the state of a regex check
from the default CRITICAL to something else (#1213)
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index edcb3fe..cdf768c 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -85,6 +85,7 @@ char errbuf[MAX_INPUT_BUFFER]; | |||
85 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; | 85 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; |
86 | int errcode; | 86 | int errcode; |
87 | int invert_regex = 0; | 87 | int invert_regex = 0; |
88 | int state_regex = STATE_CRITICAL; | ||
88 | 89 | ||
89 | struct timeval tv; | 90 | struct timeval tv; |
90 | struct timeval tv_temp; | 91 | struct timeval tv_temp; |
@@ -210,7 +211,8 @@ bool process_arguments (int argc, char **argv) | |||
210 | INVERT_REGEX = CHAR_MAX + 1, | 211 | INVERT_REGEX = CHAR_MAX + 1, |
211 | SNI_OPTION, | 212 | SNI_OPTION, |
212 | MAX_REDIRS_OPTION, | 213 | MAX_REDIRS_OPTION, |
213 | CONTINUE_AFTER_CHECK_CERT | 214 | CONTINUE_AFTER_CHECK_CERT, |
215 | STATE_REGEX | ||
214 | }; | 216 | }; |
215 | 217 | ||
216 | int option = 0; | 218 | int option = 0; |
@@ -246,6 +248,7 @@ bool process_arguments (int argc, char **argv) | |||
246 | {"content-type", required_argument, 0, 'T'}, | 248 | {"content-type", required_argument, 0, 'T'}, |
247 | {"pagesize", required_argument, 0, 'm'}, | 249 | {"pagesize", required_argument, 0, 'm'}, |
248 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, | 250 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, |
251 | {"state-regex", required_argument, 0, STATE_REGEX}, | ||
249 | {"use-ipv4", no_argument, 0, '4'}, | 252 | {"use-ipv4", no_argument, 0, '4'}, |
250 | {"use-ipv6", no_argument, 0, '6'}, | 253 | {"use-ipv6", no_argument, 0, '6'}, |
251 | {"extended-perfdata", no_argument, 0, 'E'}, | 254 | {"extended-perfdata", no_argument, 0, 'E'}, |
@@ -511,6 +514,13 @@ bool process_arguments (int argc, char **argv) | |||
511 | case INVERT_REGEX: | 514 | case INVERT_REGEX: |
512 | invert_regex = 1; | 515 | invert_regex = 1; |
513 | break; | 516 | break; |
517 | case STATE_REGEX: | ||
518 | if (!strcmp (optarg, "critical")) | ||
519 | state_regex = STATE_CRITICAL; | ||
520 | else if (!strcmp (optarg, "warning")) | ||
521 | state_regex = STATE_WARNING; | ||
522 | else usage2 (_("Invalid state-regex option"), optarg); | ||
523 | break; | ||
514 | case '4': | 524 | case '4': |
515 | address_family = AF_INET; | 525 | address_family = AF_INET; |
516 | break; | 526 | break; |
@@ -1317,7 +1327,7 @@ check_http (void) | |||
1317 | xasprintf (&msg, _("%spattern not found, "), msg); | 1327 | xasprintf (&msg, _("%spattern not found, "), msg); |
1318 | else | 1328 | else |
1319 | xasprintf (&msg, _("%spattern found, "), msg); | 1329 | xasprintf (&msg, _("%spattern found, "), msg); |
1320 | result = STATE_CRITICAL; | 1330 | result = state_regex; |
1321 | } | 1331 | } |
1322 | else { | 1332 | else { |
1323 | /* FIXME: Shouldn't that be UNKNOWN? */ | 1333 | /* FIXME: Shouldn't that be UNKNOWN? */ |
@@ -1793,7 +1803,10 @@ print_help (void) | |||
1793 | printf (" %s\n", "-R, --eregi=STRING"); | 1803 | printf (" %s\n", "-R, --eregi=STRING"); |
1794 | printf (" %s\n", _("Search page for case-insensitive regex STRING")); | 1804 | printf (" %s\n", _("Search page for case-insensitive regex STRING")); |
1795 | printf (" %s\n", "--invert-regex"); | 1805 | printf (" %s\n", "--invert-regex"); |
1796 | printf (" %s\n", _("Return CRITICAL if found, OK if not\n")); | 1806 | printf (" %s\n", _("Return STATE if found, OK if not (STATE is CRITICAL, per default)")); |
1807 | printf (" %s\n", _("can be changed with --state--regex)")); | ||
1808 | printf (" %s\n", "--regex-state=STATE"); | ||
1809 | printf (" %s\n", _("Return STATE if regex is found, OK if not\n")); | ||
1797 | 1810 | ||
1798 | printf (" %s\n", "-a, --authorization=AUTH_PAIR"); | 1811 | printf (" %s\n", "-a, --authorization=AUTH_PAIR"); |
1799 | printf (" %s\n", _("Username:password on sites with basic authentication")); | 1812 | printf (" %s\n", _("Username:password on sites with basic authentication")); |