summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e61022d)
raw | patch | inline | side by side (parent: e61022d)
author | Holger Weiss <hweiss@users.sourceforge.net> | |
Mon, 25 Aug 2008 11:42:57 +0000 (11:42 +0000) | ||
committer | Holger Weiss <hweiss@users.sourceforge.net> | |
Mon, 25 Aug 2008 11:42:57 +0000 (11:42 +0000) |
lines (Sven Nierlein - 1894496).
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2046 f882894a-f735-0410-b71e-b25c423dba1c
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2046 f882894a-f735-0410-b71e-b25c423dba1c
NEWS | patch | blob | history | |
THANKS.in | patch | blob | history | |
plugins/check_http.c | patch | blob | history | |
plugins/tests/check_http.t | patch | blob | history |
index 641e2f4d2d2eb0c1c46a70939270769eddf60ffc..c2be90293dc8394932ce4a5291e689bf5d2863c4 100644 (file)
--- a/NEWS
+++ b/NEWS
check_snmp now only prints perfdata for non numeric values (#1867716)
check_icmp now supports packet size modification
check_http now sends the Host header first to fix 301s on servers with vitrual hosts (Michael Harris).
+ check_http -e now accepts a comma-delimited list of expected status codes
libtap now included with this distribution for easier testing. Run ./configure with --enable-libtap
1.4.12 27th May 2008
diff --git a/THANKS.in b/THANKS.in
index b9a496157deee14fd4261fb0dd9097ce24341eae..e63e9f626125816a19fd14aa8906ee49c9b7d2ac 100644 (file)
--- a/THANKS.in
+++ b/THANKS.in
Rob Windsor
Hilko Bengen
Michael Harris
+Sven Nierlein
diff --git a/plugins/check_http.c b/plugins/check_http.c
index f81026f8d0ef4995efc8cb1118e8b15bcb542b34..f54f4ab89c19db64bed785f8bdf8930e8d3d7576 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
}
}
+/* Checks if the server 'reply' is one of the expected 'statuscodes' */
+static int
+expected_statuscode (const char *reply, const char *statuscodes)
+{
+ char *expected, *code;
+ int result = 0;
+
+ if ((expected = strdup (statuscodes)) == NULL)
+ die (STATE_UNKNOWN, _("HTTP UNKNOWN - Memory allocation error\n"));
+
+ for (code = strtok (expected, ","); code != NULL; code = strtok (NULL, ","))
+ if (strstr (reply, code) != NULL) {
+ result = 1;
+ break;
+ }
+ free (expected);
+ return result;
+}
static void
check_document_dates (const char *headers)
(no_body ? " [[ skipped ]]" : page));
/* make sure the status line matches the response we are looking for */
- if (!strstr (status_line, server_expect)) {
+ if (!expected_statuscode (status_line, server_expect)) {
if (server_port == HTTP_PORT)
asprintf (&msg,
- _("Invalid HTTP response received from host\n"));
+ _("Invalid HTTP response received from host: %s\n"),
+ status_line);
else
asprintf (&msg,
- _("Invalid HTTP response received from host on port %d\n"),
- server_port);
+ _("Invalid HTTP response received from host on port %d: %s\n"),
+ server_port, status_line);
die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg);
}
#endif
printf (" %s\n", "-e, --expect=STRING");
- printf (" %s\n", _("String to expect in first (status) line of server response (default: "));
+ printf (" %s\n", _("Comma-delimited list of strings, at least one of them is expected in"));
+ printf (" %s", _("the first (status) line of the server response (default: "));
printf ("%s)\n", HTTP_EXPECT);
printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)"));
printf (" %s\n", "-s, --string=STRING");
index d5a7c8225a7350a18d747f79e8804601c53c19c9..e4d770b345983ae8149c58bb9de69117768a09f4 100755 (executable)
if ($pid) {
# Parent
#print "parent\n";
+ # give our webserver some time to startup
+ sleep(1);
} else {
# Child
#print "child\n";
}
if (-x "./check_http") {
- plan tests => 13;
+ plan tests => 15;
} else {
plan skip_all => "No check_http compiled";
}
$cmd = "$command -u /statuscode/201 -e 200";
$result = NPTest->testCmd( $cmd );
is( $result->return_code, 2, $cmd);
-like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port /', "Output correct: ".$result->output );
+like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output );
+
+$cmd = "$command -u /statuscode/200 -e 200,201,202";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 89 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );