[Nagiosplug-checkins] CVS: nagiosplug/plugins check_http.c,1.53,1.54
Karl DeBisschop
kdebisschop at users.sourceforge.net
Sun Sep 14 22:05:13 CEST 2003
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv18155
Modified Files:
check_http.c
Log Message:
make status code extensible (thanks to Chris Wilson <chris at netservers.co.uk>)
Index: check_http.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_http.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -r1.53 -r1.54
*** check_http.c 11 Sep 2003 11:50:45 -0000 1.53
--- check_http.c 15 Sep 2003 05:03:47 -0000 1.54
***************
*** 464,470 ****
--- 464,472 ----
char *msg;
char *status_line;
+ char *status_code;
char *header;
char *page;
char *auth;
+ int http_status;
int i = 0;
size_t pagesize = 0;
***************
*** 615,623 ****
if (!strstr (status_line, server_expect)) {
if (server_port == HTTP_PORT)
! asprintf (&msg, _("Invalid HTTP response received from host\n"));
else
asprintf (&msg,
! _("Invalid HTTP response received from host on port %d\n"),
! server_port);
die (STATE_CRITICAL, "%s", msg);
}
--- 617,626 ----
if (!strstr (status_line, server_expect)) {
if (server_port == HTTP_PORT)
! asprintf (&msg,
! _("Invalid HTTP response received from host\n"));
else
asprintf (&msg,
! _("Invalid HTTP response received from host on port %d\n"),
! server_port);
die (STATE_CRITICAL, "%s", msg);
}
***************
*** 625,663 ****
/* 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);
if (verbose)
printf ("%s\n",msg);
-
}
else {
!
/* check the return code */
/* 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")) {
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")) {
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")) {
if (onredirect == STATE_DEPENDENT)
--- 628,663 ----
/* 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);
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 */
! else if (http_status >= 500)
die (STATE_CRITICAL, _("HTTP CRITICAL: %s\n"), status_line);
/* client errors result in a warning state */
! else if (http_status >= 400)
die (STATE_WARNING, _("HTTP WARNING: %s\n"), status_line);
/* check redirected page if specified */
! else if (http_status >= 300) {
if (onredirect == STATE_DEPENDENT)
***************
*** 678,686 ****
(display_html ? "</A>" : ""),
perfd_time (microsec), perfd_size (pagesize));
! } /* end if (strstr (status_line, "30[0-4]") */
!
} /* end else (server_expect_yn) */
-
/* check elapsed time */
--- 678,684 ----
(display_html ? "</A>" : ""),
perfd_time (microsec), perfd_size (pagesize));
! } /* end if (http_status >= 300) */
} /* end else (server_expect_yn) */
/* check elapsed time */
More information about the Commits
mailing list