diff options
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 1869837e..8eadc62e 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -62,6 +62,7 @@ char regexp[MAX_RE_SIZE]; | |||
62 | char errbuf[MAX_INPUT_BUFFER]; | 62 | char errbuf[MAX_INPUT_BUFFER]; |
63 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; | 63 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; |
64 | int errcode; | 64 | int errcode; |
65 | int invert_regex = 0; | ||
65 | 66 | ||
66 | struct timeval tv; | 67 | struct timeval tv; |
67 | 68 | ||
@@ -156,6 +157,10 @@ process_arguments (int argc, char **argv) | |||
156 | { | 157 | { |
157 | int c = 1; | 158 | int c = 1; |
158 | 159 | ||
160 | enum { | ||
161 | INVERT_REGEX = CHAR_MAX + 1 | ||
162 | }; | ||
163 | |||
159 | int option = 0; | 164 | int option = 0; |
160 | static struct option longopts[] = { | 165 | static struct option longopts[] = { |
161 | STD_LONG_OPTS, | 166 | STD_LONG_OPTS, |
@@ -180,6 +185,7 @@ process_arguments (int argc, char **argv) | |||
180 | {"max-age", required_argument, 0, 'M'}, | 185 | {"max-age", required_argument, 0, 'M'}, |
181 | {"content-type", required_argument, 0, 'T'}, | 186 | {"content-type", required_argument, 0, 'T'}, |
182 | {"pagesize", required_argument, 0, 'm'}, | 187 | {"pagesize", required_argument, 0, 'm'}, |
188 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, | ||
183 | {"use-ipv4", no_argument, 0, '4'}, | 189 | {"use-ipv4", no_argument, 0, '4'}, |
184 | {"use-ipv6", no_argument, 0, '6'}, | 190 | {"use-ipv6", no_argument, 0, '6'}, |
185 | {0, 0, 0, 0} | 191 | {0, 0, 0, 0} |
@@ -346,6 +352,9 @@ process_arguments (int argc, char **argv) | |||
346 | return ERROR; | 352 | return ERROR; |
347 | } | 353 | } |
348 | break; | 354 | break; |
355 | case INVERT_REGEX: | ||
356 | invert_regex = 1; | ||
357 | break; | ||
349 | case '4': | 358 | case '4': |
350 | address_family = AF_INET; | 359 | address_family = AF_INET; |
351 | break; | 360 | break; |
@@ -985,25 +994,29 @@ check_http (void) | |||
985 | 994 | ||
986 | if (strlen (regexp)) { | 995 | if (strlen (regexp)) { |
987 | errcode = regexec (&preg, page, REGS, pmatch, 0); | 996 | errcode = regexec (&preg, page, REGS, pmatch, 0); |
988 | if (errcode == 0) { | 997 | if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) { |
989 | printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"), | 998 | printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"), |
990 | status_line, elapsed_time, | 999 | status_line, elapsed_time, |
991 | timestamp, (display_html ? "</A>" : ""), | 1000 | timestamp, (display_html ? "</A>" : ""), |
992 | perfd_time (elapsed_time), perfd_size (pagesize)); | 1001 | perfd_time (elapsed_time), perfd_size (pagesize)); |
993 | exit (STATE_OK); | 1002 | exit (STATE_OK); |
994 | } | 1003 | } |
1004 | else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { | ||
1005 | if (invert_regex == 0) | ||
1006 | msg = strdup(_("pattern not found")); | ||
1007 | else | ||
1008 | msg = strdup(_("pattern found")); | ||
1009 | printf (_("%s - %s%s|%s %s\n"), | ||
1010 | _("CRITICAL"), | ||
1011 | msg, | ||
1012 | (display_html ? "</A>" : ""), | ||
1013 | perfd_time (elapsed_time), perfd_size (pagesize)); | ||
1014 | exit (STATE_CRITICAL); | ||
1015 | } | ||
995 | else { | 1016 | else { |
996 | if (errcode == REG_NOMATCH) { | 1017 | regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); |
997 | printf (_("CRITICAL - pattern not found%s|%s %s\n"), | 1018 | printf (_("CRITICAL - Execute Error: %s\n"), errbuf); |
998 | (display_html ? "</A>" : ""), | 1019 | exit (STATE_CRITICAL); |
999 | perfd_time (elapsed_time), perfd_size (pagesize)); | ||
1000 | exit (STATE_CRITICAL); | ||
1001 | } | ||
1002 | else { | ||
1003 | regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | ||
1004 | printf (_("CRITICAL - Execute Error: %s\n"), errbuf); | ||
1005 | exit (STATE_CRITICAL); | ||
1006 | } | ||
1007 | } | 1020 | } |
1008 | } | 1021 | } |
1009 | 1022 | ||
@@ -1265,7 +1278,9 @@ certificate expiration times.")); | |||
1265 | -r, --regex, --ereg=STRING\n\ | 1278 | -r, --regex, --ereg=STRING\n\ |
1266 | Search page for regex STRING\n\ | 1279 | Search page for regex STRING\n\ |
1267 | -R, --eregi=STRING\n\ | 1280 | -R, --eregi=STRING\n\ |
1268 | Search page for case-insensitive regex STRING\n")); | 1281 | Search page for case-insensitive regex STRING\n\ |
1282 | --invert-regex\n\ | ||
1283 | Return CRITICAL if found, OK if not\n")); | ||
1269 | 1284 | ||
1270 | printf (_("\ | 1285 | printf (_("\ |
1271 | -a, --authorization=AUTH_PAIR\n\ | 1286 | -a, --authorization=AUTH_PAIR\n\ |