diff options
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index f81026f8..f54f4ab8 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' */ | ||
577 | static int | ||
578 | expected_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 | ||
578 | static void | 596 | static void |
579 | check_document_dates (const char *headers) | 597 | check_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"); |