summaryrefslogtreecommitdiffstats
path: root/plugins/check_http.c
diff options
context:
space:
mode:
authorHolger Weiss <hweiss@users.sourceforge.net>2008-08-25 11:42:57 (GMT)
committerHolger Weiss <hweiss@users.sourceforge.net>2008-08-25 11:42:57 (GMT)
commitc349438e32a99d1d3171bb4cef6c70815c138c45 (patch)
treec966452dcd503dad1909ca6ff86e504db04f57e3 /plugins/check_http.c
parente61022df19da2c1b1ab02cd8cc2a6932b4ef9413 (diff)
downloadmonitoring-plugins-c349438e32a99d1d3171bb4cef6c70815c138c45.tar.gz
The "-e" option now accepts a comma-delimited list of expected status
lines (Sven Nierlein - 1894496). git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2046 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r--plugins/check_http.c30
1 files changed, 25 insertions, 5 deletions
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");