1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
Index: THANKS.in
===================================================================
--- THANKS.in (revision 2045)
+++ THANKS.in (working copy)
@@ -237,3 +237,4 @@
Rob Windsor
Hilko Bengen
Michael Harris
+Sven Nierlein
Index: NEWS
===================================================================
--- NEWS (revision 2045)
+++ NEWS (working copy)
@@ -10,6 +10,7 @@
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
Index: plugins/check_http.c
===================================================================
--- plugins/check_http.c (revision 2045)
+++ plugins/check_http.c (working copy)
@@ -573,8 +573,22 @@
}
}
+/* Checks if the server 'reply' is one of the expected 'statuscodes' */
+static int
+expected_statuscode (const char *reply, const char *statuscodes)
+{
+ char *expected, *code;
+ 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)
+ return 1;
+
+ return 0;
+}
+
static void
check_document_dates (const char *headers)
{
@@ -878,14 +892,15 @@
(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);
}
@@ -1262,7 +1277,8 @@
#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\n", _("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");
|