summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b89172b)
raw | patch | inline | side by side (parent: b89172b)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Mon, 15 Sep 2003 05:03:47 +0000 (05:03 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Mon, 15 Sep 2003 05:03:47 +0000 (05:03 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@722 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_http.c | patch | blob | history |
diff --git a/plugins/check_http.c b/plugins/check_http.c
index db949329ff77ca52ec5f99b34a3e92961dfa1191..4dcf1a5a8db8fa0ea0c33cfa32b8b786b1c7b8c3 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
{
char *msg;
char *status_line;
+ char *status_code;
char *header;
char *page;
char *auth;
+ int http_status;
int i = 0;
size_t pagesize = 0;
char *full_page;
/* make sure the status line matches the response we are looking for */
if (!strstr (status_line, server_expect)) {
if (server_port == HTTP_PORT)
- asprintf (&msg, _("Invalid HTTP response received from host\n"));
+ asprintf (&msg,
+ _("Invalid HTTP response received from host\n"));
else
asprintf (&msg,
- _("Invalid HTTP response received from host on port %d\n"),
- server_port);
+ _("Invalid HTTP response received from host on port %d\n"),
+ server_port);
die (STATE_CRITICAL, "%s", msg);
}
/* Exit here if server_expect was set by user and not default */
if ( server_expect_yn ) {
- asprintf (&msg, _("HTTP OK: Status line output matched \"%s\"\n"),
- server_expect);
+ asprintf (&msg,
+ _("HTTP OK: Status line output matched \"%s\"\n"),
+ server_expect);
if (verbose)
printf ("%s\n",msg);
-
}
else {
-
+ /* Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF */
+ /* HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT */
+ /* Status-Code = 3 DIGITS */
+
+ status_code = strchr (status_line, ' ') + sizeof (char);
+ if (strspn (status_code, "1234567890") != 3)
+ die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status Line (%s)\n"), status_line);
+
+ http_status = atoi (status_code);
/* check the return code */
+
+ if (http_status >= 600 || http_status < 100)
+ die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status (%s)\n"), status_line);
+
/* server errors result in a critical state */
- if (strstr (status_line, "500") || strstr (status_line, "501") ||
- strstr (status_line, "502") || strstr (status_line, "503") ||
- strstr (status_line, "504") || strstr (status_line, "505")) {
+ else if (http_status >= 500)
die (STATE_CRITICAL, _("HTTP CRITICAL: %s\n"), status_line);
- }
/* client errors result in a warning state */
- if (strstr (status_line, "400") || strstr (status_line, "401") ||
- strstr (status_line, "402") || strstr (status_line, "403") ||
- strstr (status_line, "404") || strstr (status_line, "405") ||
- strstr (status_line, "406") || strstr (status_line, "407") ||
- strstr (status_line, "408") || strstr (status_line, "409") ||
- strstr (status_line, "410") || strstr (status_line, "411") ||
- strstr (status_line, "412") || strstr (status_line, "413") ||
- strstr (status_line, "414") || strstr (status_line, "415") ||
- strstr (status_line, "416") || strstr (status_line, "417")) {
+ else if (http_status >= 400)
die (STATE_WARNING, _("HTTP WARNING: %s\n"), status_line);
- }
/* check redirected page if specified */
- if (strstr (status_line, "300") || strstr (status_line, "301") ||
- strstr (status_line, "302") || strstr (status_line, "303") ||
- strstr (status_line, "304") || strstr (status_line, "305") ||
- strstr (status_line, "306")) {
+ else if (http_status >= 300) {
if (onredirect == STATE_DEPENDENT)
redir (header, status_line);
status_line, elapsed_time, timestamp,
(display_html ? "</A>" : ""),
perfd_time (microsec), perfd_size (pagesize));
- } /* end if (strstr (status_line, "30[0-4]") */
-
+ } /* end if (http_status >= 300) */
} /* end else (server_expect_yn) */
-
/* check elapsed time */
microsec = deltime (tv);