--- plutins/check_http.c 2002-10-28 18:02:11.000000000 +0100 +++ plugins/check_http.c 2002-10-28 19:42:30.000000000 +0100 @@ -44,7 +44,7 @@ \(-H | -I ) [-u ] [-p ]\n\ [-w ] [-c ] [-t ] [-L]\n\ [-a auth] [-f ] [-e ]\n\ - [-s string] [-r | -R ]\n\ + [-s string] [-r | -R ] [-x]\n\ [-P string]" #define LONGOPTIONS "\ @@ -71,6 +71,8 @@ Seconds before connection times out (default: %d)\n\ -a, --authorization=AUTH_PAIR\n\ Username:password on sites with basic authentication\n\ + -x, --reverse\n\ + Reverse the result of -r|-R|-s (like grep -v)\n\ -L, --link=URL\n\ Wrap output in HTML link (obsoleted by urlize)\n\ -f, --onredirect=\n\ @@ -190,6 +192,7 @@ int server_expect_yn = 0; char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; char string_expect[MAX_INPUT_BUFFER] = ""; +int found_reverse = FALSE; /* grep -v */ double warning_time = 0; int check_warning_time = FALSE; double critical_time = 0; @@ -287,6 +290,7 @@ {"regex", required_argument, 0, 'r'}, {"ereg", required_argument, 0, 'r'}, {"eregi", required_argument, 0, 'R'}, + {"reverse", no_argument, 0, 'x'}, {"onredirect", required_argument, 0, 'f'}, {"certificate", required_argument, 0, 'C'}, {0, 0, 0, 0} @@ -309,7 +313,7 @@ strcpy (argv[c], "-n"); } -#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nLS" +#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nLSx" while (1) { #ifdef HAVE_GETOPT_H @@ -442,6 +446,9 @@ usage ("check_http: call for regex which was not a compiled option\n"); #endif break; + case 'x': /* grep -v */ + found_reverse = TRUE; + break; case 'v': /* verbose */ verbose = TRUE; break; @@ -849,31 +856,69 @@ if (strlen (string_expect)) { if (strstr (page, string_expect)) { - printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n", - status_line, elapsed_time, - timestamp, (display_html ? "" : ""), elapsed_time); - exit (STATE_OK); + if (found_reverse) { /* grep -v */ + printf ("HTTP CRITICAL: string found%s|time=%7.3f\n", + (display_html ? "" : ""), + elapsed_time); + exit (STATE_CRITICAL) ; + } else { + printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n", + status_line, elapsed_time, + timestamp, + (display_html ? "" : ""), + elapsed_time); + exit (STATE_OK); + } } - else { - printf ("HTTP CRITICAL: string not found%s|time=%7.3f\n", - (display_html ? "" : ""), elapsed_time); - exit (STATE_CRITICAL); + else { /* not found */ + if (found_reverse) { /* grep -v */ + printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n", + status_line, elapsed_time, + timestamp, + (display_html ? "" : ""), + elapsed_time); + exit (STATE_OK) ; + } else { + printf ("HTTP CRITICAL: string not found%s|time=%7.3f\n", + (display_html ? "" : ""), elapsed_time); + exit (STATE_CRITICAL); + } } } #ifdef HAVE_REGEX_H if (strlen (regexp)) { errcode = regexec (&preg, page, REGS, pmatch, 0); if (errcode == 0) { - printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n", - status_line, elapsed_time, - timestamp, (display_html ? "" : ""), elapsed_time); - exit (STATE_OK); + if (found_reverse) { /* grep -v */ + printf ("HTTP CRITICAL: pattern found%s|time=%7.3f\n", + (display_html ? "" : ""), + elapsed_time); + exit (STATE_CRITICAL); + } else { + printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n", + status_line, elapsed_time, + timestamp, + (display_html ? "" : ""), + elapsed_time); + exit (STATE_OK); + } } else { if (errcode == REG_NOMATCH) { - printf ("HTTP CRITICAL: pattern not found%s|time=%7.3f\n", - (display_html ? "" : ""), elapsed_time); - exit (STATE_CRITICAL); + if (found_reverse) { /* grep -v */ + printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n", + status_line, elapsed_time, + timestamp, + (display_html ? "" : ""), + elapsed_time); + exit (STATE_OK); + + } else { + printf ("HTTP CRITICAL: pattern not found%s|time=%7.3f\n", + (display_html ? "" : ""), + elapsed_time); + exit (STATE_CRITICAL); + } } else { regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);