diff options
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index b3b2263..3ba406a 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -222,9 +222,9 @@ main (int argc, char **argv) | |||
222 | 222 | ||
223 | if (strstr (timestamp, ":")) { | 223 | if (strstr (timestamp, ":")) { |
224 | if (strstr (server_url, "?")) | 224 | if (strstr (server_url, "?")) |
225 | server_url = ssprintf (server_url, "%s&%s", server_url, timestamp); | 225 | asprintf (&server_url, "%s&%s", server_url, timestamp); |
226 | else | 226 | else |
227 | server_url = ssprintf (server_url, "%s?%s", server_url, timestamp); | 227 | asprintf (&server_url, "%s?%s", server_url, timestamp); |
228 | } | 228 | } |
229 | 229 | ||
230 | if (display_html == TRUE) | 230 | if (display_html == TRUE) |
@@ -539,10 +539,8 @@ check_http (void) | |||
539 | #ifdef HAVE_SSL | 539 | #ifdef HAVE_SSL |
540 | if (use_ssl == TRUE) { | 540 | if (use_ssl == TRUE) { |
541 | 541 | ||
542 | if (connect_SSL () != OK) { | 542 | if (connect_SSL () != OK) |
543 | msg = ssprintf (msg, "Unable to open TCP socket"); | 543 | terminate (STATE_CRITICAL, "Unable to open TCP socket"); |
544 | terminate (STATE_CRITICAL, msg); | ||
545 | } | ||
546 | 544 | ||
547 | if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) { | 545 | if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) { |
548 | X509_free (server_cert); | 546 | X509_free (server_cert); |
@@ -552,7 +550,7 @@ check_http (void) | |||
552 | return STATE_CRITICAL; | 550 | return STATE_CRITICAL; |
553 | } | 551 | } |
554 | 552 | ||
555 | buf = ssprintf (buf, "%s %s HTTP/1.0\r\n", http_method, server_url); | 553 | asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url); |
556 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { | 554 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { |
557 | ERR_print_errors_fp (stderr); | 555 | ERR_print_errors_fp (stderr); |
558 | return STATE_CRITICAL; | 556 | return STATE_CRITICAL; |
@@ -560,7 +558,7 @@ check_http (void) | |||
560 | 558 | ||
561 | /* optionally send the host header info (not clear if it's usable) */ | 559 | /* optionally send the host header info (not clear if it's usable) */ |
562 | if (strcmp (host_name, "")) { | 560 | if (strcmp (host_name, "")) { |
563 | buf = ssprintf (buf, "Host: %s\r\n", host_name); | 561 | asprintf (&buf, "Host: %s\r\n", host_name); |
564 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { | 562 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { |
565 | ERR_print_errors_fp (stderr); | 563 | ERR_print_errors_fp (stderr); |
566 | return STATE_CRITICAL; | 564 | return STATE_CRITICAL; |
@@ -568,7 +566,7 @@ check_http (void) | |||
568 | } | 566 | } |
569 | 567 | ||
570 | /* send user agent */ | 568 | /* send user agent */ |
571 | buf = ssprintf (buf, "User-Agent: check_http/%s (nagios-plugins %s)\r\n", | 569 | asprintf (&buf, "User-Agent: check_http/%s (nagios-plugins %s)\r\n", |
572 | clean_revstring (REVISION), PACKAGE_VERSION); | 570 | clean_revstring (REVISION), PACKAGE_VERSION); |
573 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { | 571 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { |
574 | ERR_print_errors_fp (stderr); | 572 | ERR_print_errors_fp (stderr); |
@@ -578,7 +576,7 @@ check_http (void) | |||
578 | /* optionally send the authentication info */ | 576 | /* optionally send the authentication info */ |
579 | if (strcmp (user_auth, "")) { | 577 | if (strcmp (user_auth, "")) { |
580 | auth = base64 (user_auth, strlen (user_auth)); | 578 | auth = base64 (user_auth, strlen (user_auth)); |
581 | buf = ssprintf (buf, "Authorization: Basic %s\r\n", auth); | 579 | asprintf (&buf, "Authorization: Basic %s\r\n", auth); |
582 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { | 580 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { |
583 | ERR_print_errors_fp (stderr); | 581 | ERR_print_errors_fp (stderr); |
584 | return STATE_CRITICAL; | 582 | return STATE_CRITICAL; |
@@ -587,12 +585,12 @@ check_http (void) | |||
587 | 585 | ||
588 | /* optionally send http POST data */ | 586 | /* optionally send http POST data */ |
589 | if (http_post_data) { | 587 | if (http_post_data) { |
590 | buf = ssprintf (buf, "Content-Type: application/x-www-form-urlencoded\r\n"); | 588 | asprintf (&buf, "Content-Type: application/x-www-form-urlencoded\r\n"); |
591 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { | 589 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { |
592 | ERR_print_errors_fp (stderr); | 590 | ERR_print_errors_fp (stderr); |
593 | return STATE_CRITICAL; | 591 | return STATE_CRITICAL; |
594 | } | 592 | } |
595 | buf = ssprintf (buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data)); | 593 | asprintf (&buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data)); |
596 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { | 594 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { |
597 | ERR_print_errors_fp (stderr); | 595 | ERR_print_errors_fp (stderr); |
598 | return STATE_CRITICAL; | 596 | return STATE_CRITICAL; |
@@ -605,7 +603,7 @@ check_http (void) | |||
605 | } | 603 | } |
606 | 604 | ||
607 | /* send a newline so the server knows we're done with the request */ | 605 | /* send a newline so the server knows we're done with the request */ |
608 | buf = ssprintf (buf, "\r\n\r\n"); | 606 | asprintf (&buf, "\r\n\r\n"); |
609 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { | 607 | if (SSL_write (ssl, buf, strlen (buf)) == -1) { |
610 | ERR_print_errors_fp (stderr); | 608 | ERR_print_errors_fp (stderr); |
611 | return STATE_CRITICAL; | 609 | return STATE_CRITICAL; |
@@ -614,23 +612,21 @@ check_http (void) | |||
614 | } | 612 | } |
615 | else { | 613 | else { |
616 | #endif | 614 | #endif |
617 | if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) { | 615 | if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) |
618 | msg = ssprintf (msg, "Unable to open TCP socket"); | 616 | terminate (STATE_CRITICAL, "Unable to open TCP socket"); |
619 | terminate (STATE_CRITICAL, msg); | 617 | asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url); |
620 | } | ||
621 | buf = ssprintf (buf, "%s %s HTTP/1.0\r\n", http_method, server_url); | ||
622 | send (sd, buf, strlen (buf), 0); | 618 | send (sd, buf, strlen (buf), 0); |
623 | 619 | ||
624 | 620 | ||
625 | 621 | ||
626 | /* optionally send the host header info */ | 622 | /* optionally send the host header info */ |
627 | if (strcmp (host_name, "")) { | 623 | if (strcmp (host_name, "")) { |
628 | buf = ssprintf (buf, "Host: %s\r\n", host_name); | 624 | asprintf (&buf, "Host: %s\r\n", host_name); |
629 | send (sd, buf, strlen (buf), 0); | 625 | send (sd, buf, strlen (buf), 0); |
630 | } | 626 | } |
631 | 627 | ||
632 | /* send user agent */ | 628 | /* send user agent */ |
633 | buf = ssprintf (buf, | 629 | asprintf (&buf, |
634 | "User-Agent: check_http/%s (nagios-plugins %s)\r\n", | 630 | "User-Agent: check_http/%s (nagios-plugins %s)\r\n", |
635 | clean_revstring (REVISION), PACKAGE_VERSION); | 631 | clean_revstring (REVISION), PACKAGE_VERSION); |
636 | send (sd, buf, strlen (buf), 0); | 632 | send (sd, buf, strlen (buf), 0); |
@@ -638,23 +634,23 @@ check_http (void) | |||
638 | /* optionally send the authentication info */ | 634 | /* optionally send the authentication info */ |
639 | if (strcmp (user_auth, "")) { | 635 | if (strcmp (user_auth, "")) { |
640 | auth = base64 (user_auth, strlen (user_auth)); | 636 | auth = base64 (user_auth, strlen (user_auth)); |
641 | buf = ssprintf (buf, "Authorization: Basic %s\r\n", auth); | 637 | asprintf (&buf, "Authorization: Basic %s\r\n", auth); |
642 | send (sd, buf, strlen (buf), 0); | 638 | send (sd, buf, strlen (buf), 0); |
643 | } | 639 | } |
644 | 640 | ||
645 | /* optionally send http POST data */ | 641 | /* optionally send http POST data */ |
646 | /* written by Chris Henesy <lurker@shadowtech.org> */ | 642 | /* written by Chris Henesy <lurker@shadowtech.org> */ |
647 | if (http_post_data) { | 643 | if (http_post_data) { |
648 | buf = ssprintf (buf, "Content-Type: application/x-www-form-urlencoded\r\n"); | 644 | asprintf (&buf, "Content-Type: application/x-www-form-urlencoded\r\n"); |
649 | send (sd, buf, strlen (buf), 0); | 645 | send (sd, buf, strlen (buf), 0); |
650 | buf = ssprintf (buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data)); | 646 | asprintf (&buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data)); |
651 | send (sd, buf, strlen (buf), 0); | 647 | send (sd, buf, strlen (buf), 0); |
652 | http_post_data = strscat (http_post_data, "\r\n"); | 648 | http_post_data = strscat (http_post_data, "\r\n"); |
653 | send (sd, http_post_data, strlen (http_post_data), 0); | 649 | send (sd, http_post_data, strlen (http_post_data), 0); |
654 | } | 650 | } |
655 | 651 | ||
656 | /* send a newline so the server knows we're done with the request */ | 652 | /* send a newline so the server knows we're done with the request */ |
657 | buf = ssprintf (buf, "\r\n\r\n"); | 653 | asprintf (&buf, "\r\n\r\n"); |
658 | send (sd, buf, strlen (buf), 0); | 654 | send (sd, buf, strlen (buf), 0); |
659 | #ifdef HAVE_SSL | 655 | #ifdef HAVE_SSL |
660 | } | 656 | } |
@@ -663,7 +659,7 @@ check_http (void) | |||
663 | /* fetch the page */ | 659 | /* fetch the page */ |
664 | pagesize = (size_t) 0; | 660 | pagesize = (size_t) 0; |
665 | while ((i = my_recv ()) > 0) { | 661 | while ((i = my_recv ()) > 0) { |
666 | buffer[i] = "\0"; | 662 | buffer[i] = '\0'; |
667 | full_page = strscat (full_page, buffer); | 663 | full_page = strscat (full_page, buffer); |
668 | pagesize += i; | 664 | pagesize += i; |
669 | } | 665 | } |
@@ -716,9 +712,9 @@ check_http (void) | |||
716 | /* make sure the status line matches the response we are looking for */ | 712 | /* make sure the status line matches the response we are looking for */ |
717 | if (!strstr (status_line, server_expect)) { | 713 | if (!strstr (status_line, server_expect)) { |
718 | if (server_port == HTTP_PORT) | 714 | if (server_port == HTTP_PORT) |
719 | msg = ssprintf (msg, "Invalid HTTP response received from host\n"); | 715 | asprintf (&msg, "Invalid HTTP response received from host\n"); |
720 | else | 716 | else |
721 | msg = ssprintf (msg, | 717 | asprintf (&msg, |
722 | "Invalid HTTP response received from host on port %d\n", | 718 | "Invalid HTTP response received from host on port %d\n", |
723 | server_port); | 719 | server_port); |
724 | terminate (STATE_CRITICAL, msg); | 720 | terminate (STATE_CRITICAL, msg); |
@@ -727,7 +723,7 @@ check_http (void) | |||
727 | 723 | ||
728 | /* Exit here if server_expect was set by user and not default */ | 724 | /* Exit here if server_expect was set by user and not default */ |
729 | if ( server_expect_yn ) { | 725 | if ( server_expect_yn ) { |
730 | msg = ssprintf (msg, "HTTP OK: Status line output matched \"%s\"\n", | 726 | asprintf (&msg, "HTTP OK: Status line output matched \"%s\"\n", |
731 | server_expect); | 727 | server_expect); |
732 | if (verbose) | 728 | if (verbose) |
733 | printf ("%s\n",msg); | 729 | printf ("%s\n",msg); |
@@ -742,8 +738,7 @@ check_http (void) | |||
742 | strstr (status_line, "501") || | 738 | strstr (status_line, "501") || |
743 | strstr (status_line, "502") || | 739 | strstr (status_line, "502") || |
744 | strstr (status_line, "503")) { | 740 | strstr (status_line, "503")) { |
745 | msg = ssprintf (msg, "HTTP CRITICAL: %s\n", status_line); | 741 | terminate (STATE_CRITICAL, "HTTP CRITICAL: %s\n", status_line); |
746 | terminate (STATE_CRITICAL, msg); | ||
747 | } | 742 | } |
748 | 743 | ||
749 | /* client errors result in a warning state */ | 744 | /* client errors result in a warning state */ |
@@ -752,8 +747,7 @@ check_http (void) | |||
752 | strstr (status_line, "402") || | 747 | strstr (status_line, "402") || |
753 | strstr (status_line, "403") || | 748 | strstr (status_line, "403") || |
754 | strstr (status_line, "404")) { | 749 | strstr (status_line, "404")) { |
755 | msg = ssprintf (msg, "HTTP WARNING: %s\n", status_line); | 750 | terminate (STATE_WARNING, "HTTP WARNING: %s\n", status_line); |
756 | terminate (STATE_WARNING, msg); | ||
757 | } | 751 | } |
758 | 752 | ||
759 | /* check redirected page if specified */ | 753 | /* check redirected page if specified */ |
@@ -807,7 +801,7 @@ check_http (void) | |||
807 | else if (sscanf (pos, HDR_LOCATION URI_PATH, server_url) == 1) { | 801 | else if (sscanf (pos, HDR_LOCATION URI_PATH, server_url) == 1) { |
808 | if ((server_url[0] != '/') && (x = strrchr(orig_url, '/'))) { | 802 | if ((server_url[0] != '/') && (x = strrchr(orig_url, '/'))) { |
809 | *x = '\0'; | 803 | *x = '\0'; |
810 | server_url = ssprintf (server_url, "%s/%s", orig_url, server_url); | 804 | asprintf (&server_url, "%s/%s", orig_url, server_url); |
811 | } | 805 | } |
812 | check_http (); | 806 | check_http (); |
813 | } | 807 | } |
@@ -828,7 +822,7 @@ check_http (void) | |||
828 | else if (onredirect == STATE_CRITICAL) | 822 | else if (onredirect == STATE_CRITICAL) |
829 | printf ("HTTP CRITICAL"); | 823 | printf ("HTTP CRITICAL"); |
830 | time (&end_time); | 824 | time (&end_time); |
831 | msg = ssprintf (msg, ": %s - %d second response time %s%s|time=%d\n", | 825 | asprintf (&msg, ": %s - %d second response time %s%s|time=%d\n", |
832 | status_line, (int) (end_time - start_time), timestamp, | 826 | status_line, (int) (end_time - start_time), timestamp, |
833 | (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 827 | (display_html ? "</A>" : ""), (int) (end_time - start_time)); |
834 | terminate (onredirect, msg); | 828 | terminate (onredirect, msg); |
@@ -840,7 +834,7 @@ check_http (void) | |||
840 | 834 | ||
841 | /* check elapsed time */ | 835 | /* check elapsed time */ |
842 | time (&end_time); | 836 | time (&end_time); |
843 | msg = ssprintf (msg, "HTTP problem: %s - %d second response time %s%s|time=%d\n", | 837 | asprintf (&msg, "HTTP problem: %s - %d second response time %s%s|time=%d\n", |
844 | status_line, (int) (end_time - start_time), timestamp, | 838 | status_line, (int) (end_time - start_time), timestamp, |
845 | (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 839 | (display_html ? "</A>" : ""), (int) (end_time - start_time)); |
846 | if (check_critical_time == TRUE && (end_time - start_time) > critical_time) | 840 | if (check_critical_time == TRUE && (end_time - start_time) > critical_time) |
@@ -889,7 +883,7 @@ check_http (void) | |||
889 | #endif | 883 | #endif |
890 | 884 | ||
891 | /* We only get here if all tests have been passed */ | 885 | /* We only get here if all tests have been passed */ |
892 | msg = ssprintf (msg, "HTTP ok: %s - %d second response time %s%s|time=%d\n", | 886 | asprintf (&msg, "HTTP ok: %s - %d second response time %s%s|time=%d\n", |
893 | status_line, (int) (end_time - start_time), | 887 | status_line, (int) (end_time - start_time), |
894 | timestamp, (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 888 | timestamp, (display_html ? "</A>" : ""), (int) (end_time - start_time)); |
895 | terminate (STATE_OK, msg); | 889 | terminate (STATE_OK, msg); |