diff options
Diffstat (limited to 'plugins/check_http.c')
| -rw-r--r-- | plugins/check_http.c | 216 |
1 files changed, 176 insertions, 40 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 51679975..34fb4f01 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
| @@ -72,7 +72,7 @@ int maximum_age = -1; | |||
| 72 | 72 | ||
| 73 | enum { | 73 | enum { |
| 74 | REGS = 2, | 74 | REGS = 2, |
| 75 | MAX_RE_SIZE = 256 | 75 | MAX_RE_SIZE = 1024 |
| 76 | }; | 76 | }; |
| 77 | #include "regex.h" | 77 | #include "regex.h" |
| 78 | regex_t preg; | 78 | regex_t preg; |
| @@ -91,10 +91,12 @@ struct timeval tv_temp; | |||
| 91 | 91 | ||
| 92 | int specify_port = FALSE; | 92 | int specify_port = FALSE; |
| 93 | int server_port = HTTP_PORT; | 93 | int server_port = HTTP_PORT; |
| 94 | int virtual_port = 0; | ||
| 94 | char server_port_text[6] = ""; | 95 | char server_port_text[6] = ""; |
| 95 | char server_type[6] = "http"; | 96 | char server_type[6] = "http"; |
| 96 | char *server_address; | 97 | char *server_address; |
| 97 | char *host_name; | 98 | char *host_name; |
| 99 | int host_name_length; | ||
| 98 | char *server_url; | 100 | char *server_url; |
| 99 | char *user_agent; | 101 | char *user_agent; |
| 100 | int server_url_length; | 102 | int server_url_length; |
| @@ -118,12 +120,14 @@ int use_ssl = FALSE; | |||
| 118 | int use_sni = FALSE; | 120 | int use_sni = FALSE; |
| 119 | int verbose = FALSE; | 121 | int verbose = FALSE; |
| 120 | int show_extended_perfdata = FALSE; | 122 | int show_extended_perfdata = FALSE; |
| 123 | int show_body = FALSE; | ||
| 121 | int sd; | 124 | int sd; |
| 122 | int min_page_len = 0; | 125 | int min_page_len = 0; |
| 123 | int max_page_len = 0; | 126 | int max_page_len = 0; |
| 124 | int redir_depth = 0; | 127 | int redir_depth = 0; |
| 125 | int max_depth = 15; | 128 | int max_depth = 15; |
| 126 | char *http_method; | 129 | char *http_method; |
| 130 | char *http_method_proxy; | ||
| 127 | char *http_post_data; | 131 | char *http_post_data; |
| 128 | char *http_content_type; | 132 | char *http_content_type; |
| 129 | char buffer[MAX_INPUT_BUFFER]; | 133 | char buffer[MAX_INPUT_BUFFER]; |
| @@ -237,6 +241,7 @@ process_arguments (int argc, char **argv) | |||
| 237 | {"use-ipv4", no_argument, 0, '4'}, | 241 | {"use-ipv4", no_argument, 0, '4'}, |
| 238 | {"use-ipv6", no_argument, 0, '6'}, | 242 | {"use-ipv6", no_argument, 0, '6'}, |
| 239 | {"extended-perfdata", no_argument, 0, 'E'}, | 243 | {"extended-perfdata", no_argument, 0, 'E'}, |
| 244 | {"show-body", no_argument, 0, 'B'}, | ||
| 240 | {0, 0, 0, 0} | 245 | {0, 0, 0, 0} |
| 241 | }; | 246 | }; |
| 242 | 247 | ||
| @@ -257,7 +262,7 @@ process_arguments (int argc, char **argv) | |||
| 257 | } | 262 | } |
| 258 | 263 | ||
| 259 | while (1) { | 264 | while (1) { |
| 260 | c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NE", longopts, &option); | 265 | c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NEB", longopts, &option); |
| 261 | if (c == -1 || c == EOF) | 266 | if (c == -1 || c == EOF) |
| 262 | break; | 267 | break; |
| 263 | 268 | ||
| @@ -267,11 +272,11 @@ process_arguments (int argc, char **argv) | |||
| 267 | break; | 272 | break; |
| 268 | case 'h': /* help */ | 273 | case 'h': /* help */ |
| 269 | print_help (); | 274 | print_help (); |
| 270 | exit (STATE_OK); | 275 | exit (STATE_UNKNOWN); |
| 271 | break; | 276 | break; |
| 272 | case 'V': /* version */ | 277 | case 'V': /* version */ |
| 273 | print_revision (progname, NP_VERSION); | 278 | print_revision (progname, NP_VERSION); |
| 274 | exit (STATE_OK); | 279 | exit (STATE_UNKNOWN); |
| 275 | break; | 280 | break; |
| 276 | case 't': /* timeout period */ | 281 | case 't': /* timeout period */ |
| 277 | if (!is_intnonneg (optarg)) | 282 | if (!is_intnonneg (optarg)) |
| @@ -343,9 +348,20 @@ process_arguments (int argc, char **argv) | |||
| 343 | parameters, like -S and -C combinations */ | 348 | parameters, like -S and -C combinations */ |
| 344 | use_ssl = TRUE; | 349 | use_ssl = TRUE; |
| 345 | if (c=='S' && optarg != NULL) { | 350 | if (c=='S' && optarg != NULL) { |
| 346 | ssl_version = atoi(optarg); | 351 | int got_plus = strchr(optarg, '+') != NULL; |
| 347 | if (ssl_version < 1 || ssl_version > 3) | 352 | |
| 348 | usage4 (_("Invalid option - Valid values for SSL Version are 1 (TLSv1), 2 (SSLv2) or 3 (SSLv3)")); | 353 | if (!strncmp (optarg, "1.2", 3)) |
| 354 | ssl_version = got_plus ? MP_TLSv1_2_OR_NEWER : MP_TLSv1_2; | ||
| 355 | else if (!strncmp (optarg, "1.1", 3)) | ||
| 356 | ssl_version = got_plus ? MP_TLSv1_1_OR_NEWER : MP_TLSv1_1; | ||
| 357 | else if (optarg[0] == '1') | ||
| 358 | ssl_version = got_plus ? MP_TLSv1_OR_NEWER : MP_TLSv1; | ||
| 359 | else if (optarg[0] == '3') | ||
| 360 | ssl_version = got_plus ? MP_SSLv3_OR_NEWER : MP_SSLv3; | ||
| 361 | else if (optarg[0] == '2') | ||
| 362 | ssl_version = got_plus ? MP_SSLv2_OR_NEWER : MP_SSLv2; | ||
| 363 | else | ||
| 364 | usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2 (with optional '+' suffix)")); | ||
| 349 | } | 365 | } |
| 350 | if (specify_port == FALSE) | 366 | if (specify_port == FALSE) |
| 351 | server_port = HTTPS_PORT; | 367 | server_port = HTTPS_PORT; |
| @@ -380,11 +396,25 @@ process_arguments (int argc, char **argv) | |||
| 380 | case 'H': /* Host Name (virtual host) */ | 396 | case 'H': /* Host Name (virtual host) */ |
| 381 | host_name = strdup (optarg); | 397 | host_name = strdup (optarg); |
| 382 | if (host_name[0] == '[') { | 398 | if (host_name[0] == '[') { |
| 383 | if ((p = strstr (host_name, "]:")) != NULL) /* [IPv6]:port */ | 399 | if ((p = strstr (host_name, "]:")) != NULL) { /* [IPv6]:port */ |
| 384 | server_port = atoi (p + 2); | 400 | virtual_port = atoi (p + 2); |
| 401 | /* cut off the port */ | ||
| 402 | host_name_length = strlen (host_name) - strlen (p) - 1; | ||
| 403 | free (host_name); | ||
| 404 | host_name = strndup (optarg, host_name_length); | ||
| 405 | if (specify_port == FALSE) | ||
| 406 | server_port = virtual_port; | ||
| 407 | } | ||
| 385 | } else if ((p = strchr (host_name, ':')) != NULL | 408 | } else if ((p = strchr (host_name, ':')) != NULL |
| 386 | && strchr (++p, ':') == NULL) /* IPv4:port or host:port */ | 409 | && strchr (++p, ':') == NULL) { /* IPv4:port or host:port */ |
| 387 | server_port = atoi (p); | 410 | virtual_port = atoi (p); |
| 411 | /* cut off the port */ | ||
| 412 | host_name_length = strlen (host_name) - strlen (p) - 1; | ||
| 413 | free (host_name); | ||
| 414 | host_name = strndup (optarg, host_name_length); | ||
| 415 | if (specify_port == FALSE) | ||
| 416 | server_port = virtual_port; | ||
| 417 | } | ||
| 388 | break; | 418 | break; |
| 389 | case 'I': /* Server IP-address */ | 419 | case 'I': /* Server IP-address */ |
| 390 | server_address = strdup (optarg); | 420 | server_address = strdup (optarg); |
| @@ -419,6 +449,12 @@ process_arguments (int argc, char **argv) | |||
| 419 | if (http_method) | 449 | if (http_method) |
| 420 | free(http_method); | 450 | free(http_method); |
| 421 | http_method = strdup (optarg); | 451 | http_method = strdup (optarg); |
| 452 | char *tmp; | ||
| 453 | if ((tmp = strstr(http_method, ":")) > 0) { | ||
| 454 | tmp[0] = '\0'; | ||
| 455 | http_method = http_method; | ||
| 456 | http_method_proxy = ++tmp; | ||
| 457 | } | ||
| 422 | break; | 458 | break; |
| 423 | case 'd': /* string or substring */ | 459 | case 'd': /* string or substring */ |
| 424 | strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1); | 460 | strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1); |
| @@ -513,6 +549,9 @@ process_arguments (int argc, char **argv) | |||
| 513 | case 'E': /* show extended perfdata */ | 549 | case 'E': /* show extended perfdata */ |
| 514 | show_extended_perfdata = TRUE; | 550 | show_extended_perfdata = TRUE; |
| 515 | break; | 551 | break; |
| 552 | case 'B': /* print body content after status line */ | ||
| 553 | show_body = TRUE; | ||
| 554 | break; | ||
| 516 | } | 555 | } |
| 517 | } | 556 | } |
| 518 | 557 | ||
| @@ -539,9 +578,15 @@ process_arguments (int argc, char **argv) | |||
| 539 | if (http_method == NULL) | 578 | if (http_method == NULL) |
| 540 | http_method = strdup ("GET"); | 579 | http_method = strdup ("GET"); |
| 541 | 580 | ||
| 542 | if (client_cert && !client_privkey) | 581 | if (http_method_proxy == NULL) |
| 582 | http_method_proxy = strdup ("GET"); | ||
| 583 | |||
| 584 | if (client_cert && !client_privkey) | ||
| 543 | usage4 (_("If you use a client certificate you must also specify a private key file")); | 585 | usage4 (_("If you use a client certificate you must also specify a private key file")); |
| 544 | 586 | ||
| 587 | if (virtual_port == 0) | ||
| 588 | virtual_port = server_port; | ||
| 589 | |||
| 545 | return TRUE; | 590 | return TRUE; |
| 546 | } | 591 | } |
| 547 | 592 | ||
| @@ -869,53 +914,115 @@ check_http (void) | |||
| 869 | double elapsed_time_transfer = 0.0; | 914 | double elapsed_time_transfer = 0.0; |
| 870 | int page_len = 0; | 915 | int page_len = 0; |
| 871 | int result = STATE_OK; | 916 | int result = STATE_OK; |
| 917 | char *force_host_header = NULL; | ||
| 872 | 918 | ||
| 873 | /* try to connect to the host at the given port number */ | 919 | /* try to connect to the host at the given port number */ |
| 874 | gettimeofday (&tv_temp, NULL); | 920 | gettimeofday (&tv_temp, NULL); |
| 875 | if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) | 921 | if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) |
| 876 | die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); | 922 | die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); |
| 877 | microsec_connect = deltime (tv_temp); | 923 | microsec_connect = deltime (tv_temp); |
| 924 | |||
| 925 | /* if we are called with the -I option, the -j method is CONNECT and */ | ||
| 926 | /* we received -S for SSL, then we tunnel the request through a proxy*/ | ||
| 927 | /* @20100414, public[at]frank4dd.com, http://www.frank4dd.com/howto */ | ||
| 928 | |||
| 929 | if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 | ||
| 930 | && host_name != NULL && use_ssl == TRUE) { | ||
| 931 | |||
| 932 | if (verbose) printf ("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", server_address, server_port, host_name, HTTPS_PORT); | ||
| 933 | asprintf (&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, HTTPS_PORT, user_agent); | ||
| 934 | if (strlen(proxy_auth)) { | ||
| 935 | base64_encode_alloc (proxy_auth, strlen (proxy_auth), &auth); | ||
| 936 | xasprintf (&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); | ||
| 937 | } | ||
| 938 | /* optionally send any other header tag */ | ||
| 939 | if (http_opt_headers_count) { | ||
| 940 | for (i = 0; i < http_opt_headers_count ; i++) { | ||
| 941 | if (force_host_header != http_opt_headers[i]) { | ||
| 942 | xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); | ||
| 943 | } | ||
| 944 | } | ||
| 945 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ | ||
| 946 | /* Covered in a testcase in tests/check_http.t */ | ||
| 947 | /* free(http_opt_headers); */ | ||
| 948 | } | ||
| 949 | asprintf (&buf, "%sProxy-Connection: keep-alive\r\n", buf); | ||
| 950 | asprintf (&buf, "%sHost: %s\r\n", buf, host_name); | ||
| 951 | /* we finished our request, send empty line with CRLF */ | ||
| 952 | asprintf (&buf, "%s%s", buf, CRLF); | ||
| 953 | if (verbose) printf ("%s\n", buf); | ||
| 954 | send(sd, buf, strlen (buf), 0); | ||
| 955 | buf[0]='\0'; | ||
| 956 | |||
| 957 | if (verbose) printf ("Receive response from proxy\n"); | ||
| 958 | read (sd, buffer, MAX_INPUT_BUFFER-1); | ||
| 959 | if (verbose) printf ("%s", buffer); | ||
| 960 | /* Here we should check if we got HTTP/1.1 200 Connection established */ | ||
| 961 | } | ||
| 878 | #ifdef HAVE_SSL | 962 | #ifdef HAVE_SSL |
| 879 | elapsed_time_connect = (double)microsec_connect / 1.0e6; | 963 | elapsed_time_connect = (double)microsec_connect / 1.0e6; |
| 880 | if (use_ssl == TRUE) { | 964 | if (use_ssl == TRUE) { |
| 881 | gettimeofday (&tv_temp, NULL); | 965 | gettimeofday (&tv_temp, NULL); |
| 882 | result = np_net_ssl_init_with_hostname_version_and_cert(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey); | 966 | result = np_net_ssl_init_with_hostname_version_and_cert(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey); |
| 967 | if (verbose) printf ("SSL initialized\n"); | ||
| 883 | if (result != STATE_OK) | 968 | if (result != STATE_OK) |
| 884 | die (STATE_CRITICAL, NULL); | 969 | die (STATE_CRITICAL, NULL); |
| 885 | microsec_ssl = deltime (tv_temp); | 970 | microsec_ssl = deltime (tv_temp); |
| 886 | elapsed_time_ssl = (double)microsec_ssl / 1.0e6; | 971 | elapsed_time_ssl = (double)microsec_ssl / 1.0e6; |
| 887 | if (check_cert == TRUE) { | 972 | if (check_cert == TRUE) { |
| 888 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); | 973 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); |
| 889 | np_net_ssl_cleanup(); | ||
| 890 | if (sd) close(sd); | 974 | if (sd) close(sd); |
| 975 | np_net_ssl_cleanup(); | ||
| 891 | return result; | 976 | return result; |
| 892 | } | 977 | } |
| 893 | } | 978 | } |
| 894 | #endif /* HAVE_SSL */ | 979 | #endif /* HAVE_SSL */ |
| 895 | 980 | ||
| 896 | xasprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); | 981 | if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 |
| 982 | && host_name != NULL && use_ssl == TRUE) | ||
| 983 | asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method_proxy, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); | ||
| 984 | else | ||
| 985 | asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); | ||
| 897 | 986 | ||
| 898 | /* tell HTTP/1.1 servers not to keep the connection alive */ | 987 | /* tell HTTP/1.1 servers not to keep the connection alive */ |
| 899 | xasprintf (&buf, "%sConnection: close\r\n", buf); | 988 | xasprintf (&buf, "%sConnection: close\r\n", buf); |
| 900 | 989 | ||
| 990 | /* check if Host header is explicitly set in options */ | ||
| 991 | if (http_opt_headers_count) { | ||
| 992 | for (i = 0; i < http_opt_headers_count ; i++) { | ||
| 993 | if (strncmp(http_opt_headers[i], "Host:", 5) == 0) { | ||
| 994 | force_host_header = http_opt_headers[i]; | ||
| 995 | } | ||
| 996 | } | ||
| 997 | } | ||
| 998 | |||
| 901 | /* optionally send the host header info */ | 999 | /* optionally send the host header info */ |
| 902 | if (host_name) { | 1000 | if (host_name) { |
| 903 | /* | 1001 | if (force_host_header) { |
| 904 | * Specify the port only if we're using a non-default port (see RFC 2616, | 1002 | xasprintf (&buf, "%s%s\r\n", buf, force_host_header); |
| 905 | * 14.23). Some server applications/configurations cause trouble if the | 1003 | } |
| 906 | * (default) port is explicitly specified in the "Host:" header line. | 1004 | else { |
| 907 | */ | 1005 | /* |
| 908 | if ((use_ssl == FALSE && server_port == HTTP_PORT) || | 1006 | * Specify the port only if we're using a non-default port (see RFC 2616, |
| 909 | (use_ssl == TRUE && server_port == HTTPS_PORT)) | 1007 | * 14.23). Some server applications/configurations cause trouble if the |
| 910 | xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); | 1008 | * (default) port is explicitly specified in the "Host:" header line. |
| 911 | else | 1009 | */ |
| 912 | xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); | 1010 | if ((use_ssl == FALSE && virtual_port == HTTP_PORT) || |
| 1011 | (use_ssl == TRUE && virtual_port == HTTPS_PORT) || | ||
| 1012 | (server_address != NULL && strcmp(http_method, "CONNECT") == 0 | ||
| 1013 | && host_name != NULL && use_ssl == TRUE)) | ||
| 1014 | xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); | ||
| 1015 | else | ||
| 1016 | xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, virtual_port); | ||
| 1017 | } | ||
| 913 | } | 1018 | } |
| 914 | 1019 | ||
| 915 | /* optionally send any other header tag */ | 1020 | /* optionally send any other header tag */ |
| 916 | if (http_opt_headers_count) { | 1021 | if (http_opt_headers_count) { |
| 917 | for (i = 0; i < http_opt_headers_count ; i++) { | 1022 | for (i = 0; i < http_opt_headers_count ; i++) { |
| 918 | xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); | 1023 | if (force_host_header != http_opt_headers[i]) { |
| 1024 | xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); | ||
| 1025 | } | ||
| 919 | } | 1026 | } |
| 920 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ | 1027 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ |
| 921 | /* Covered in a testcase in tests/check_http.t */ | 1028 | /* Covered in a testcase in tests/check_http.t */ |
| @@ -964,6 +1071,10 @@ check_http (void) | |||
| 964 | microsec_firstbyte = deltime (tv_temp); | 1071 | microsec_firstbyte = deltime (tv_temp); |
| 965 | elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6; | 1072 | elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6; |
| 966 | } | 1073 | } |
| 1074 | while (pos = memchr(buffer, '\0', i)) { | ||
| 1075 | /* replace nul character with a blank */ | ||
| 1076 | *pos = ' '; | ||
| 1077 | } | ||
| 967 | buffer[i] = '\0'; | 1078 | buffer[i] = '\0'; |
| 968 | xasprintf (&full_page_new, "%s%s", full_page, buffer); | 1079 | xasprintf (&full_page_new, "%s%s", full_page, buffer); |
| 969 | free (full_page); | 1080 | free (full_page); |
| @@ -1005,10 +1116,10 @@ check_http (void) | |||
| 1005 | die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host\n")); | 1116 | die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host\n")); |
| 1006 | 1117 | ||
| 1007 | /* close the connection */ | 1118 | /* close the connection */ |
| 1119 | if (sd) close(sd); | ||
| 1008 | #ifdef HAVE_SSL | 1120 | #ifdef HAVE_SSL |
| 1009 | np_net_ssl_cleanup(); | 1121 | np_net_ssl_cleanup(); |
| 1010 | #endif | 1122 | #endif |
| 1011 | if (sd) close(sd); | ||
| 1012 | 1123 | ||
| 1013 | /* Save check time */ | 1124 | /* Save check time */ |
| 1014 | microsec = deltime (tv); | 1125 | microsec = deltime (tv); |
| @@ -1059,6 +1170,8 @@ check_http (void) | |||
| 1059 | xasprintf (&msg, | 1170 | xasprintf (&msg, |
| 1060 | _("Invalid HTTP response received from host on port %d: %s\n"), | 1171 | _("Invalid HTTP response received from host on port %d: %s\n"), |
| 1061 | server_port, status_line); | 1172 | server_port, status_line); |
| 1173 | if (show_body) | ||
| 1174 | xasprintf (&msg, _("%s\n%s"), msg, page); | ||
| 1062 | die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); | 1175 | die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); |
| 1063 | } | 1176 | } |
| 1064 | 1177 | ||
| @@ -1209,6 +1322,9 @@ check_http (void) | |||
| 1209 | perfd_time (elapsed_time), | 1322 | perfd_time (elapsed_time), |
| 1210 | perfd_size (page_len)); | 1323 | perfd_size (page_len)); |
| 1211 | 1324 | ||
| 1325 | if (show_body) | ||
| 1326 | xasprintf (&msg, _("%s\n%s"), msg, page); | ||
| 1327 | |||
| 1212 | result = max_state_alt(get_status(elapsed_time, thlds), result); | 1328 | result = max_state_alt(get_status(elapsed_time, thlds), result); |
| 1213 | 1329 | ||
| 1214 | die (result, "HTTP %s: %s\n", state_text(result), msg); | 1330 | die (result, "HTTP %s: %s\n", state_text(result), msg); |
| @@ -1337,8 +1453,8 @@ redir (char *pos, char *status_line) | |||
| 1337 | !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) && | 1453 | !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) && |
| 1338 | (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) && | 1454 | (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) && |
| 1339 | !strcmp(server_url, url)) | 1455 | !strcmp(server_url, url)) |
| 1340 | die (STATE_WARNING, | 1456 | die (STATE_CRITICAL, |
| 1341 | _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), | 1457 | _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"), |
| 1342 | type, addr, i, url, (display_html ? "</A>" : "")); | 1458 | type, addr, i, url, (display_html ? "</A>" : "")); |
| 1343 | 1459 | ||
| 1344 | strcpy (server_type, type); | 1460 | strcpy (server_type, type); |
| @@ -1363,6 +1479,9 @@ redir (char *pos, char *status_line) | |||
| 1363 | MAX_PORT, server_type, server_address, server_port, server_url, | 1479 | MAX_PORT, server_type, server_address, server_port, server_url, |
| 1364 | display_html ? "</A>" : ""); | 1480 | display_html ? "</A>" : ""); |
| 1365 | 1481 | ||
| 1482 | /* reset virtual port */ | ||
| 1483 | virtual_port = server_port; | ||
| 1484 | |||
| 1366 | if (verbose) | 1485 | if (verbose) |
| 1367 | printf (_("Redirection to %s://%s:%d%s\n"), server_type, | 1486 | printf (_("Redirection to %s://%s:%d%s\n"), server_type, |
| 1368 | host_name ? host_name : server_address, server_port, server_url); | 1487 | host_name ? host_name : server_address, server_port, server_url); |
| @@ -1395,32 +1514,32 @@ char *perfd_time (double elapsed_time) | |||
| 1395 | return fperfdata ("time", elapsed_time, "s", | 1514 | return fperfdata ("time", elapsed_time, "s", |
| 1396 | thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0, | 1515 | thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0, |
| 1397 | thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0, | 1516 | thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0, |
| 1398 | TRUE, 0, FALSE, 0); | 1517 | TRUE, 0, TRUE, socket_timeout); |
| 1399 | } | 1518 | } |
| 1400 | 1519 | ||
| 1401 | char *perfd_time_connect (double elapsed_time_connect) | 1520 | char *perfd_time_connect (double elapsed_time_connect) |
| 1402 | { | 1521 | { |
| 1403 | return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | 1522 | return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); |
| 1404 | } | 1523 | } |
| 1405 | 1524 | ||
| 1406 | char *perfd_time_ssl (double elapsed_time_ssl) | 1525 | char *perfd_time_ssl (double elapsed_time_ssl) |
| 1407 | { | 1526 | { |
| 1408 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | 1527 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); |
| 1409 | } | 1528 | } |
| 1410 | 1529 | ||
| 1411 | char *perfd_time_headers (double elapsed_time_headers) | 1530 | char *perfd_time_headers (double elapsed_time_headers) |
| 1412 | { | 1531 | { |
| 1413 | return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | 1532 | return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); |
| 1414 | } | 1533 | } |
| 1415 | 1534 | ||
| 1416 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) | 1535 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) |
| 1417 | { | 1536 | { |
| 1418 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | 1537 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); |
| 1419 | } | 1538 | } |
| 1420 | 1539 | ||
| 1421 | char *perfd_time_transfer (double elapsed_time_transfer) | 1540 | char *perfd_time_transfer (double elapsed_time_transfer) |
| 1422 | { | 1541 | { |
| 1423 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | 1542 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); |
| 1424 | } | 1543 | } |
| 1425 | 1544 | ||
| 1426 | char *perfd_size (int page_len) | 1545 | char *perfd_size (int page_len) |
| @@ -1448,6 +1567,10 @@ print_help (void) | |||
| 1448 | 1567 | ||
| 1449 | print_usage (); | 1568 | print_usage (); |
| 1450 | 1569 | ||
| 1570 | #ifdef HAVE_SSL | ||
| 1571 | printf (_("In the first form, make an HTTP request.")); | ||
| 1572 | printf (_("In the second form, connect to the server and check the TLS certificate.")); | ||
| 1573 | #endif | ||
| 1451 | printf (_("NOTE: One or both of -H and -I must be specified")); | 1574 | printf (_("NOTE: One or both of -H and -I must be specified")); |
| 1452 | 1575 | ||
| 1453 | printf ("\n"); | 1576 | printf ("\n"); |
| @@ -1467,9 +1590,10 @@ print_help (void) | |||
| 1467 | printf (UT_IPv46); | 1590 | printf (UT_IPv46); |
| 1468 | 1591 | ||
| 1469 | #ifdef HAVE_SSL | 1592 | #ifdef HAVE_SSL |
| 1470 | printf (" %s\n", "-S, --ssl=VERSION"); | 1593 | printf (" %s\n", "-S, --ssl=VERSION[+]"); |
| 1471 | printf (" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); | 1594 | printf (" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); |
| 1472 | printf (" %s\n", _("auto-negotiation (1 = TLSv1, 2 = SSLv2, 3 = SSLv3).")); | 1595 | printf (" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); |
| 1596 | printf (" %s\n", _("1.2 = TLSv1.2). With a '+' suffix, newer versions are also accepted.")); | ||
| 1473 | printf (" %s\n", "--sni"); | 1597 | printf (" %s\n", "--sni"); |
| 1474 | printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); | 1598 | printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); |
| 1475 | printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]"); | 1599 | printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]"); |
| @@ -1496,7 +1620,7 @@ print_help (void) | |||
| 1496 | printf (" %s\n", _("URL to GET or POST (default: /)")); | 1620 | printf (" %s\n", _("URL to GET or POST (default: /)")); |
| 1497 | printf (" %s\n", "-P, --post=STRING"); | 1621 | printf (" %s\n", "-P, --post=STRING"); |
| 1498 | printf (" %s\n", _("URL encoded http POST data")); | 1622 | printf (" %s\n", _("URL encoded http POST data")); |
| 1499 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE)"); | 1623 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)"); |
| 1500 | printf (" %s\n", _("Set HTTP method.")); | 1624 | printf (" %s\n", _("Set HTTP method.")); |
| 1501 | printf (" %s\n", "-N, --no-body"); | 1625 | printf (" %s\n", "-N, --no-body"); |
| 1502 | printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); | 1626 | printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); |
| @@ -1526,6 +1650,8 @@ print_help (void) | |||
| 1526 | printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers")); | 1650 | printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers")); |
| 1527 | printf (" %s\n", "-E, --extended-perfdata"); | 1651 | printf (" %s\n", "-E, --extended-perfdata"); |
| 1528 | printf (" %s\n", _("Print additional performance data")); | 1652 | printf (" %s\n", _("Print additional performance data")); |
| 1653 | printf (" %s\n", "-B, --show-body"); | ||
| 1654 | printf (" %s\n", _("Print body content below status line")); | ||
| 1529 | printf (" %s\n", "-L, --link"); | 1655 | printf (" %s\n", "-L, --link"); |
| 1530 | printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); | 1656 | printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); |
| 1531 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>"); | 1657 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>"); |
| @@ -1544,7 +1670,7 @@ print_help (void) | |||
| 1544 | printf ("%s\n", _("Notes:")); | 1670 | printf ("%s\n", _("Notes:")); |
| 1545 | printf (" %s\n", _("This plugin will attempt to open an HTTP connection with the host.")); | 1671 | printf (" %s\n", _("This plugin will attempt to open an HTTP connection with the host.")); |
| 1546 | printf (" %s\n", _("Successful connects return STATE_OK, refusals and timeouts return STATE_CRITICAL")); | 1672 | printf (" %s\n", _("Successful connects return STATE_OK, refusals and timeouts return STATE_CRITICAL")); |
| 1547 | printf (" %s\n", _("other errors return STATE_UNKNOWN. Successful connects, but incorrect reponse")); | 1673 | printf (" %s\n", _("other errors return STATE_UNKNOWN. Successful connects, but incorrect response")); |
| 1548 | printf (" %s\n", _("messages from the host result in STATE_WARNING return values. If you are")); | 1674 | printf (" %s\n", _("messages from the host result in STATE_WARNING return values. If you are")); |
| 1549 | printf (" %s\n", _("checking a virtual server that uses 'host headers' you must supply the FQDN")); | 1675 | printf (" %s\n", _("checking a virtual server that uses 'host headers' you must supply the FQDN")); |
| 1550 | printf (" %s\n", _("(fully qualified domain name) as the [host_name] argument.")); | 1676 | printf (" %s\n", _("(fully qualified domain name) as the [host_name] argument.")); |
| @@ -1570,7 +1696,7 @@ print_help (void) | |||
| 1570 | printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,")); | 1696 | printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,")); |
| 1571 | printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); | 1697 | printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); |
| 1572 | printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when")); | 1698 | printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when")); |
| 1573 | printf (" %s\n", _("the certificate is expired.")); | 1699 | printf (" %s\n\n", _("the certificate is expired.")); |
| 1574 | printf ("\n"); | 1700 | printf ("\n"); |
| 1575 | printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14"); | 1701 | printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14"); |
| 1576 | printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,")); | 1702 | printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,")); |
| @@ -1578,6 +1704,14 @@ print_help (void) | |||
| 1578 | printf (" %s\n", _("30 days, but more than 14 days, a STATE_WARNING is returned.")); | 1704 | printf (" %s\n", _("30 days, but more than 14 days, a STATE_WARNING is returned.")); |
| 1579 | printf (" %s\n", _("A STATE_CRITICAL will be returned when certificate expires in less than 14 days")); | 1705 | printf (" %s\n", _("A STATE_CRITICAL will be returned when certificate expires in less than 14 days")); |
| 1580 | 1706 | ||
| 1707 | printf (" %s\n\n", "CHECK SSL WEBSERVER CONTENT VIA PROXY USING HTTP 1.1 CONNECT: "); | ||
| 1708 | printf (" %s\n", _("check_http -I 192.168.100.35 -p 80 -u https://www.verisign.com/ -S -j CONNECT -H www.verisign.com ")); | ||
| 1709 | printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>")); | ||
| 1710 | printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); | ||
| 1711 | printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); | ||
| 1712 | printf (" %s\n", _("a STATE_CRITICAL will be returned. By adding a colon to the method you can set the method used")); | ||
| 1713 | printf (" %s\n", _("inside the proxied connection: -j CONNECT:POST")); | ||
| 1714 | |||
| 1581 | #endif | 1715 | #endif |
| 1582 | 1716 | ||
| 1583 | printf (UT_SUPPORT); | 1717 | printf (UT_SUPPORT); |
| @@ -1596,6 +1730,8 @@ print_usage (void) | |||
| 1596 | printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); | 1730 | printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); |
| 1597 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); | 1731 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); |
| 1598 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 1732 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
| 1599 | printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); | 1733 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); |
| 1600 | printf (" [-T <content-type>] [-j method]\n"); | 1734 | printf (" [-T <content-type>] [-j method]\n"); |
| 1735 | printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname); | ||
| 1736 | printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); | ||
| 1601 | } | 1737 | } |
