diff options
-rw-r--r-- | plugins/check_http.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 3ec9e499..6b952c37 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -90,6 +90,7 @@ char server_type[6] = "http"; | |||
90 | char *server_address; | 90 | char *server_address; |
91 | char *host_name; | 91 | char *host_name; |
92 | char *server_url; | 92 | char *server_url; |
93 | char *user_agent; | ||
93 | int server_url_length; | 94 | int server_url_length; |
94 | int server_expect_yn = 0; | 95 | int server_expect_yn = 0; |
95 | char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; | 96 | char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; |
@@ -130,6 +131,8 @@ main (int argc, char **argv) | |||
130 | /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */ | 131 | /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */ |
131 | server_url = strdup(HTTP_URL); | 132 | server_url = strdup(HTTP_URL); |
132 | server_url_length = strlen(server_url); | 133 | server_url_length = strlen(server_url); |
134 | asprintf (&user_agent, "User-Agent: check_http/%s (nagios-plugins %s)", | ||
135 | clean_revstring (revision), VERSION); | ||
133 | 136 | ||
134 | if (process_arguments (argc, argv) == ERROR) | 137 | if (process_arguments (argc, argv) == ERROR) |
135 | usage (_("check_http: could not parse arguments\n")); | 138 | usage (_("check_http: could not parse arguments\n")); |
@@ -472,6 +475,9 @@ check_http (void) | |||
472 | int sslerr; | 475 | int sslerr; |
473 | #endif | 476 | #endif |
474 | 477 | ||
478 | if (verbose) | ||
479 | printf ("%s://%s:%d%s [%s]\n", server_type, server_address, server_port, server_url, host_name); | ||
480 | |||
475 | /* try to connect to the host at the given port number */ | 481 | /* try to connect to the host at the given port number */ |
476 | #ifdef HAVE_SSL | 482 | #ifdef HAVE_SSL |
477 | if (use_ssl == TRUE) { | 483 | if (use_ssl == TRUE) { |
@@ -497,22 +503,21 @@ check_http (void) | |||
497 | } | 503 | } |
498 | #endif | 504 | #endif |
499 | 505 | ||
500 | asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url); | 506 | asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent); |
501 | 507 | ||
502 | /* optionally send the host header info (not clear if it's usable) */ | 508 | /* optionally send the host header info */ |
503 | if (host_name) | 509 | if (host_name) |
504 | asprintf (&buf, "%sHost: %s\r\n", buf, host_name); | 510 | asprintf (&buf, "%sHost: %s\r\n", buf, host_name); |
505 | 511 | ||
506 | /* send user agent */ | ||
507 | asprintf (&buf, "%sUser-Agent: check_http/%s (nagios-plugins %s)\r\n", | ||
508 | buf, clean_revstring (revision), VERSION); | ||
509 | |||
510 | /* optionally send the authentication info */ | 512 | /* optionally send the authentication info */ |
511 | if (strlen(user_auth)) { | 513 | if (strlen(user_auth)) { |
512 | auth = base64 (user_auth, strlen (user_auth)); | 514 | auth = base64 (user_auth, strlen (user_auth)); |
513 | asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); | 515 | asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); |
514 | } | 516 | } |
515 | 517 | ||
518 | if (verbose) | ||
519 | printf ("%s://%s:%d%s\n", server_type, server_address, server_port, server_url); | ||
520 | |||
516 | /* either send http POST data */ | 521 | /* either send http POST data */ |
517 | if (http_post_data) { | 522 | if (http_post_data) { |
518 | asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); | 523 | asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); |
@@ -524,6 +529,9 @@ check_http (void) | |||
524 | asprintf (&buf, "%s%s", buf, CRLF); | 529 | asprintf (&buf, "%s%s", buf, CRLF); |
525 | } | 530 | } |
526 | 531 | ||
532 | if (verbose) | ||
533 | printf ("%s\n", buf); | ||
534 | |||
527 | #ifdef HAVE_SSL | 535 | #ifdef HAVE_SSL |
528 | if (use_ssl == TRUE) { | 536 | if (use_ssl == TRUE) { |
529 | if (SSL_write (ssl, buf, (int)strlen(buf)) == -1) { | 537 | if (SSL_write (ssl, buf, (int)strlen(buf)) == -1) { |
@@ -617,7 +625,6 @@ check_http (void) | |||
617 | die (STATE_CRITICAL, "%s", msg); | 625 | die (STATE_CRITICAL, "%s", msg); |
618 | } | 626 | } |
619 | 627 | ||
620 | |||
621 | /* 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 */ |
622 | if ( server_expect_yn ) { | 629 | if ( server_expect_yn ) { |
623 | asprintf (&msg, _("HTTP OK: Status line output matched \"%s\"\n"), | 630 | asprintf (&msg, _("HTTP OK: Status line output matched \"%s\"\n"), |
@@ -860,9 +867,15 @@ redir (char *pos, char *status_line) | |||
860 | 867 | ||
861 | server_port = i; | 868 | server_port = i; |
862 | strcpy (server_type, type); | 869 | strcpy (server_type, type); |
863 | asprintf (&host_name, "%s", addr); | 870 | |
864 | asprintf (&server_address, "%s", addr); | 871 | free (host_name); |
865 | asprintf (&server_url, "%s", url); | 872 | host_name = strdup (addr); |
873 | |||
874 | free (server_address); | ||
875 | server_address = strdup (addr); | ||
876 | |||
877 | free (server_url); | ||
878 | server_url = strdup (url); | ||
866 | 879 | ||
867 | return check_http (); | 880 | return check_http (); |
868 | } | 881 | } |