diff options
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index db94932..4dcf1a5 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -463,9 +463,11 @@ check_http (void) | |||
463 | { | 463 | { |
464 | char *msg; | 464 | char *msg; |
465 | char *status_line; | 465 | char *status_line; |
466 | char *status_code; | ||
466 | char *header; | 467 | char *header; |
467 | char *page; | 468 | char *page; |
468 | char *auth; | 469 | char *auth; |
470 | int http_status; | ||
469 | int i = 0; | 471 | int i = 0; |
470 | size_t pagesize = 0; | 472 | size_t pagesize = 0; |
471 | char *full_page; | 473 | char *full_page; |
@@ -614,51 +616,49 @@ check_http (void) | |||
614 | /* make sure the status line matches the response we are looking for */ | 616 | /* make sure the status line matches the response we are looking for */ |
615 | if (!strstr (status_line, server_expect)) { | 617 | if (!strstr (status_line, server_expect)) { |
616 | if (server_port == HTTP_PORT) | 618 | if (server_port == HTTP_PORT) |
617 | asprintf (&msg, _("Invalid HTTP response received from host\n")); | 619 | asprintf (&msg, |
620 | _("Invalid HTTP response received from host\n")); | ||
618 | else | 621 | else |
619 | asprintf (&msg, | 622 | asprintf (&msg, |
620 | _("Invalid HTTP response received from host on port %d\n"), | 623 | _("Invalid HTTP response received from host on port %d\n"), |
621 | server_port); | 624 | server_port); |
622 | die (STATE_CRITICAL, "%s", msg); | 625 | die (STATE_CRITICAL, "%s", msg); |
623 | } | 626 | } |
624 | 627 | ||
625 | /* Exit here if server_expect was set by user and not default */ | 628 | /* Exit here if server_expect was set by user and not default */ |
626 | if ( server_expect_yn ) { | 629 | if ( server_expect_yn ) { |
627 | asprintf (&msg, _("HTTP OK: Status line output matched \"%s\"\n"), | 630 | asprintf (&msg, |
628 | server_expect); | 631 | _("HTTP OK: Status line output matched \"%s\"\n"), |
632 | server_expect); | ||
629 | if (verbose) | 633 | if (verbose) |
630 | printf ("%s\n",msg); | 634 | printf ("%s\n",msg); |
631 | |||
632 | } | 635 | } |
633 | else { | 636 | else { |
634 | 637 | /* Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF */ | |
638 | /* HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT */ | ||
639 | /* Status-Code = 3 DIGITS */ | ||
640 | |||
641 | status_code = strchr (status_line, ' ') + sizeof (char); | ||
642 | if (strspn (status_code, "1234567890") != 3) | ||
643 | die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status Line (%s)\n"), status_line); | ||
644 | |||
645 | http_status = atoi (status_code); | ||
635 | 646 | ||
636 | /* check the return code */ | 647 | /* check the return code */ |
648 | |||
649 | if (http_status >= 600 || http_status < 100) | ||
650 | die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status (%s)\n"), status_line); | ||
651 | |||
637 | /* server errors result in a critical state */ | 652 | /* server errors result in a critical state */ |
638 | if (strstr (status_line, "500") || strstr (status_line, "501") || | 653 | else if (http_status >= 500) |
639 | strstr (status_line, "502") || strstr (status_line, "503") || | ||
640 | strstr (status_line, "504") || strstr (status_line, "505")) { | ||
641 | die (STATE_CRITICAL, _("HTTP CRITICAL: %s\n"), status_line); | 654 | die (STATE_CRITICAL, _("HTTP CRITICAL: %s\n"), status_line); |
642 | } | ||
643 | 655 | ||
644 | /* client errors result in a warning state */ | 656 | /* client errors result in a warning state */ |
645 | if (strstr (status_line, "400") || strstr (status_line, "401") || | 657 | else if (http_status >= 400) |
646 | strstr (status_line, "402") || strstr (status_line, "403") || | ||
647 | strstr (status_line, "404") || strstr (status_line, "405") || | ||
648 | strstr (status_line, "406") || strstr (status_line, "407") || | ||
649 | strstr (status_line, "408") || strstr (status_line, "409") || | ||
650 | strstr (status_line, "410") || strstr (status_line, "411") || | ||
651 | strstr (status_line, "412") || strstr (status_line, "413") || | ||
652 | strstr (status_line, "414") || strstr (status_line, "415") || | ||
653 | strstr (status_line, "416") || strstr (status_line, "417")) { | ||
654 | die (STATE_WARNING, _("HTTP WARNING: %s\n"), status_line); | 658 | die (STATE_WARNING, _("HTTP WARNING: %s\n"), status_line); |
655 | } | ||
656 | 659 | ||
657 | /* check redirected page if specified */ | 660 | /* check redirected page if specified */ |
658 | if (strstr (status_line, "300") || strstr (status_line, "301") || | 661 | else if (http_status >= 300) { |
659 | strstr (status_line, "302") || strstr (status_line, "303") || | ||
660 | strstr (status_line, "304") || strstr (status_line, "305") || | ||
661 | strstr (status_line, "306")) { | ||
662 | 662 | ||
663 | if (onredirect == STATE_DEPENDENT) | 663 | if (onredirect == STATE_DEPENDENT) |
664 | redir (header, status_line); | 664 | redir (header, status_line); |
@@ -677,11 +677,9 @@ check_http (void) | |||
677 | status_line, elapsed_time, timestamp, | 677 | status_line, elapsed_time, timestamp, |
678 | (display_html ? "</A>" : ""), | 678 | (display_html ? "</A>" : ""), |
679 | perfd_time (microsec), perfd_size (pagesize)); | 679 | perfd_time (microsec), perfd_size (pagesize)); |
680 | } /* end if (strstr (status_line, "30[0-4]") */ | 680 | } /* end if (http_status >= 300) */ |
681 | |||
682 | 681 | ||
683 | } /* end else (server_expect_yn) */ | 682 | } /* end else (server_expect_yn) */ |
684 | |||
685 | 683 | ||
686 | /* check elapsed time */ | 684 | /* check elapsed time */ |
687 | microsec = deltime (tv); | 685 | microsec = deltime (tv); |