summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--THANKS.in1
-rw-r--r--plugins/check_http.c30
-rwxr-xr-xplugins/tests/check_http.t11
4 files changed, 36 insertions, 7 deletions
diff --git a/NEWS b/NEWS
index 641e2f4..c2be902 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ This file documents the major additions and syntax changes between releases.
10 check_snmp now only prints perfdata for non numeric values (#1867716) 10 check_snmp now only prints perfdata for non numeric values (#1867716)
11 check_icmp now supports packet size modification 11 check_icmp now supports packet size modification
12 check_http now sends the Host header first to fix 301s on servers with vitrual hosts (Michael Harris). 12 check_http now sends the Host header first to fix 301s on servers with vitrual hosts (Michael Harris).
13 check_http -e now accepts a comma-delimited list of expected status codes
13 libtap now included with this distribution for easier testing. Run ./configure with --enable-libtap 14 libtap now included with this distribution for easier testing. Run ./configure with --enable-libtap
14 15
151.4.12 27th May 2008 161.4.12 27th May 2008
diff --git a/THANKS.in b/THANKS.in
index b9a4961..e63e9f6 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -237,3 +237,4 @@ Christian Schneemann
237Rob Windsor 237Rob Windsor
238Hilko Bengen 238Hilko Bengen
239Michael Harris 239Michael Harris
240Sven Nierlein
diff --git a/plugins/check_http.c b/plugins/check_http.c
index f81026f..f54f4ab 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -573,7 +573,25 @@ parse_time_string (const char *string)
573 } 573 }
574} 574}
575 575
576/* Checks if the server 'reply' is one of the expected 'statuscodes' */
577static int
578expected_statuscode (const char *reply, const char *statuscodes)
579{
580 char *expected, *code;
581 int result = 0;
582
583 if ((expected = strdup (statuscodes)) == NULL)
584 die (STATE_UNKNOWN, _("HTTP UNKNOWN - Memory allocation error\n"));
585
586 for (code = strtok (expected, ","); code != NULL; code = strtok (NULL, ","))
587 if (strstr (reply, code) != NULL) {
588 result = 1;
589 break;
590 }
576 591
592 free (expected);
593 return result;
594}
577 595
578static void 596static void
579check_document_dates (const char *headers) 597check_document_dates (const char *headers)
@@ -878,14 +896,15 @@ check_http (void)
878 (no_body ? " [[ skipped ]]" : page)); 896 (no_body ? " [[ skipped ]]" : page));
879 897
880 /* make sure the status line matches the response we are looking for */ 898 /* make sure the status line matches the response we are looking for */
881 if (!strstr (status_line, server_expect)) { 899 if (!expected_statuscode (status_line, server_expect)) {
882 if (server_port == HTTP_PORT) 900 if (server_port == HTTP_PORT)
883 asprintf (&msg, 901 asprintf (&msg,
884 _("Invalid HTTP response received from host\n")); 902 _("Invalid HTTP response received from host: %s\n"),
903 status_line);
885 else 904 else
886 asprintf (&msg, 905 asprintf (&msg,
887 _("Invalid HTTP response received from host on port %d\n"), 906 _("Invalid HTTP response received from host on port %d: %s\n"),
888 server_port); 907 server_port, status_line);
889 die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); 908 die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg);
890 } 909 }
891 910
@@ -1262,7 +1281,8 @@ print_help (void)
1262#endif 1281#endif
1263 1282
1264 printf (" %s\n", "-e, --expect=STRING"); 1283 printf (" %s\n", "-e, --expect=STRING");
1265 printf (" %s\n", _("String to expect in first (status) line of server response (default: ")); 1284 printf (" %s\n", _("Comma-delimited list of strings, at least one of them is expected in"));
1285 printf (" %s", _("the first (status) line of the server response (default: "));
1266 printf ("%s)\n", HTTP_EXPECT); 1286 printf ("%s)\n", HTTP_EXPECT);
1267 printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)")); 1287 printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)"));
1268 printf (" %s\n", "-s, --string=STRING"); 1288 printf (" %s\n", "-s, --string=STRING");
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index d5a7c82..e4d770b 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -18,6 +18,8 @@ my $pid = fork();
18if ($pid) { 18if ($pid) {
19 # Parent 19 # Parent
20 #print "parent\n"; 20 #print "parent\n";
21 # give our webserver some time to startup
22 sleep(1);
21} else { 23} else {
22 # Child 24 # Child
23 #print "child\n"; 25 #print "child\n";
@@ -58,7 +60,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
58} 60}
59 61
60if (-x "./check_http") { 62if (-x "./check_http") {
61 plan tests => 13; 63 plan tests => 15;
62} else { 64} else {
63 plan skip_all => "No check_http compiled"; 65 plan skip_all => "No check_http compiled";
64} 66}
@@ -97,5 +99,10 @@ like( $result->output, '/^HTTP OK HTTP/1.1 201 Created - 94 bytes in ([\d\.]+) s
97$cmd = "$command -u /statuscode/201 -e 200"; 99$cmd = "$command -u /statuscode/201 -e 200";
98$result = NPTest->testCmd( $cmd ); 100$result = NPTest->testCmd( $cmd );
99is( $result->return_code, 2, $cmd); 101is( $result->return_code, 2, $cmd);
100like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port /', "Output correct: ".$result->output ); 102like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port \d+: HTTP/1.1 201 Created/', "Output correct: ".$result->output );
103
104$cmd = "$command -u /statuscode/200 -e 200,201,202";
105$result = NPTest->testCmd( $cmd );
106is( $result->return_code, 0, $cmd);
107like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 89 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
101 108