summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5fd2550)
raw | patch | inline | side by side (parent: 5fd2550)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 25 May 2006 15:34:54 +0000 (15:34 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 25 May 2006 15:34:54 +0000 (15:34 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1404 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_http.c | patch | blob | history | |
plugins/t/check_http.t | patch | blob | history |
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 1869837ef32e555a025c6e072a6bc3506312ef42..8eadc62ed9e495375e6ed3be50034d969164018f 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
char errbuf[MAX_INPUT_BUFFER];
int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE;
int errcode;
+int invert_regex = 0;
struct timeval tv;
{
int c = 1;
+ enum {
+ INVERT_REGEX = CHAR_MAX + 1
+ };
+
int option = 0;
static struct option longopts[] = {
STD_LONG_OPTS,
{"max-age", required_argument, 0, 'M'},
{"content-type", required_argument, 0, 'T'},
{"pagesize", required_argument, 0, 'm'},
+ {"invert-regex", no_argument, NULL, INVERT_REGEX},
{"use-ipv4", no_argument, 0, '4'},
{"use-ipv6", no_argument, 0, '6'},
{0, 0, 0, 0}
return ERROR;
}
break;
+ case INVERT_REGEX:
+ invert_regex = 1;
+ break;
case '4':
address_family = AF_INET;
break;
if (strlen (regexp)) {
errcode = regexec (&preg, page, REGS, pmatch, 0);
- if (errcode == 0) {
+ if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) {
printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"),
status_line, elapsed_time,
timestamp, (display_html ? "</A>" : ""),
perfd_time (elapsed_time), perfd_size (pagesize));
exit (STATE_OK);
}
+ else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) {
+ if (invert_regex == 0)
+ msg = strdup(_("pattern not found"));
+ else
+ msg = strdup(_("pattern found"));
+ printf (_("%s - %s%s|%s %s\n"),
+ _("CRITICAL"),
+ msg,
+ (display_html ? "</A>" : ""),
+ perfd_time (elapsed_time), perfd_size (pagesize));
+ exit (STATE_CRITICAL);
+ }
else {
- if (errcode == REG_NOMATCH) {
- printf (_("CRITICAL - pattern not found%s|%s %s\n"),
- (display_html ? "</A>" : ""),
- perfd_time (elapsed_time), perfd_size (pagesize));
- exit (STATE_CRITICAL);
- }
- else {
- regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
- printf (_("CRITICAL - Execute Error: %s\n"), errbuf);
- exit (STATE_CRITICAL);
- }
+ regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
+ printf (_("CRITICAL - Execute Error: %s\n"), errbuf);
+ exit (STATE_CRITICAL);
}
}
-r, --regex, --ereg=STRING\n\
Search page for regex STRING\n\
-R, --eregi=STRING\n\
- Search page for case-insensitive regex STRING\n"));
+ Search page for case-insensitive regex STRING\n\
+ --invert-regex\n\
+ Return CRITICAL if found, OK if not\n"));
printf (_("\
-a, --authorization=AUTH_PAIR\n\
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 3154151f9b8b941bb3695e42f73838d5fcb4eb42..4e3c06cb73b1c14a756c4034de793a01a740e4a6 100644 (file)
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
use Test::More;
use NPTest;
-plan tests => 14;
+plan tests => 21;
my $successOutput = '/OK.*HTTP.*second/';
);
cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" );
-
+$res = NPTest->testCmd( "./check_http -H altinity.com -r 'nagios'" );
+cmp_ok( $res->return_code, "==", 0, "Got a reference to 'nagios'");
+
+$res = NPTest->testCmd( "./check_http -H altinity.com -r 'nAGiOs'" );
+cmp_ok( $res->return_code, "==", 2, "Not got 'nAGiOs'");
+like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'");
+
+$res = NPTest->testCmd( "./check_http -H altinity.com -R 'nAGiOs'" );
+cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'nAGiOs'");
+
+$res = NPTest->testCmd( "./check_http -H altinity.com -r 'nagios' --invert-regex" );
+cmp_ok( $res->return_code, "==", 2, "Invert results work when found");
+like ( $res->output, "/pattern found/", "Error message says 'pattern found'");
+
+$res = NPTest->testCmd( "./check_http -H altinity.com -r 'nAGiOs' --invert-regex" );
+cmp_ok( $res->return_code, "==", 0, "And also when not found");