summaryrefslogtreecommitdiffstats
path: root/plugins/check_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r--plugins/check_http.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 2e393eb2..e2298b17 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -120,12 +120,14 @@ int use_ssl = FALSE;
120int use_sni = FALSE; 120int use_sni = FALSE;
121int verbose = FALSE; 121int verbose = FALSE;
122int show_extended_perfdata = FALSE; 122int show_extended_perfdata = FALSE;
123int show_body = FALSE;
123int sd; 124int sd;
124int min_page_len = 0; 125int min_page_len = 0;
125int max_page_len = 0; 126int max_page_len = 0;
126int redir_depth = 0; 127int redir_depth = 0;
127int max_depth = 15; 128int max_depth = 15;
128char *http_method; 129char *http_method;
130char *http_method_proxy;
129char *http_post_data; 131char *http_post_data;
130char *http_content_type; 132char *http_content_type;
131char buffer[MAX_INPUT_BUFFER]; 133char buffer[MAX_INPUT_BUFFER];
@@ -239,6 +241,7 @@ process_arguments (int argc, char **argv)
239 {"use-ipv4", no_argument, 0, '4'}, 241 {"use-ipv4", no_argument, 0, '4'},
240 {"use-ipv6", no_argument, 0, '6'}, 242 {"use-ipv6", no_argument, 0, '6'},
241 {"extended-perfdata", no_argument, 0, 'E'}, 243 {"extended-perfdata", no_argument, 0, 'E'},
244 {"show-body", no_argument, 0, 'B'},
242 {0, 0, 0, 0} 245 {0, 0, 0, 0}
243 }; 246 };
244 247
@@ -259,7 +262,7 @@ process_arguments (int argc, char **argv)
259 } 262 }
260 263
261 while (1) { 264 while (1) {
262 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);
263 if (c == -1 || c == EOF) 266 if (c == -1 || c == EOF)
264 break; 267 break;
265 268
@@ -446,6 +449,12 @@ process_arguments (int argc, char **argv)
446 if (http_method) 449 if (http_method)
447 free(http_method); 450 free(http_method);
448 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 }
449 break; 458 break;
450 case 'd': /* string or substring */ 459 case 'd': /* string or substring */
451 strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1); 460 strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1);
@@ -540,6 +549,9 @@ process_arguments (int argc, char **argv)
540 case 'E': /* show extended perfdata */ 549 case 'E': /* show extended perfdata */
541 show_extended_perfdata = TRUE; 550 show_extended_perfdata = TRUE;
542 break; 551 break;
552 case 'B': /* print body content after status line */
553 show_body = TRUE;
554 break;
543 } 555 }
544 } 556 }
545 557
@@ -566,6 +578,9 @@ process_arguments (int argc, char **argv)
566 if (http_method == NULL) 578 if (http_method == NULL)
567 http_method = strdup ("GET"); 579 http_method = strdup ("GET");
568 580
581 if (http_method_proxy == NULL)
582 http_method_proxy = strdup ("GET");
583
569 if (client_cert && !client_privkey) 584 if (client_cert && !client_privkey)
570 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"));
571 586
@@ -965,7 +980,7 @@ check_http (void)
965 980
966 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 981 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
967 && host_name != NULL && use_ssl == TRUE) 982 && host_name != NULL && use_ssl == TRUE)
968 asprintf (&buf, "%s %s %s\r\n%s\r\n", "GET", server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); 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);
969 else 984 else
970 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); 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);
971 986
@@ -1155,6 +1170,8 @@ check_http (void)
1155 xasprintf (&msg, 1170 xasprintf (&msg,
1156 _("Invalid HTTP response received from host on port %d: %s\n"), 1171 _("Invalid HTTP response received from host on port %d: %s\n"),
1157 server_port, status_line); 1172 server_port, status_line);
1173 if (show_body)
1174 xasprintf (&msg, _("%s\n%s"), msg, page);
1158 die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); 1175 die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg);
1159 } 1176 }
1160 1177
@@ -1305,6 +1322,9 @@ check_http (void)
1305 perfd_time (elapsed_time), 1322 perfd_time (elapsed_time),
1306 perfd_size (page_len)); 1323 perfd_size (page_len));
1307 1324
1325 if (show_body)
1326 xasprintf (&msg, _("%s\n%s"), msg, page);
1327
1308 result = max_state_alt(get_status(elapsed_time, thlds), result); 1328 result = max_state_alt(get_status(elapsed_time, thlds), result);
1309 1329
1310 die (result, "HTTP %s: %s\n", state_text(result), msg); 1330 die (result, "HTTP %s: %s\n", state_text(result), msg);
@@ -1596,7 +1616,7 @@ print_help (void)
1596 printf (" %s\n", _("URL to GET or POST (default: /)")); 1616 printf (" %s\n", _("URL to GET or POST (default: /)"));
1597 printf (" %s\n", "-P, --post=STRING"); 1617 printf (" %s\n", "-P, --post=STRING");
1598 printf (" %s\n", _("URL encoded http POST data")); 1618 printf (" %s\n", _("URL encoded http POST data"));
1599 printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)"); 1619 printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)");
1600 printf (" %s\n", _("Set HTTP method.")); 1620 printf (" %s\n", _("Set HTTP method."));
1601 printf (" %s\n", "-N, --no-body"); 1621 printf (" %s\n", "-N, --no-body");
1602 printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); 1622 printf (" %s\n", _("Don't wait for document body: stop reading after headers."));
@@ -1626,6 +1646,8 @@ print_help (void)
1626 printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers")); 1646 printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers"));
1627 printf (" %s\n", "-E, --extended-perfdata"); 1647 printf (" %s\n", "-E, --extended-perfdata");
1628 printf (" %s\n", _("Print additional performance data")); 1648 printf (" %s\n", _("Print additional performance data"));
1649 printf (" %s\n", "-B, --show-body");
1650 printf (" %s\n", _("Print body content below status line"));
1629 printf (" %s\n", "-L, --link"); 1651 printf (" %s\n", "-L, --link");
1630 printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); 1652 printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)"));
1631 printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>"); 1653 printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>");
@@ -1683,7 +1705,8 @@ print_help (void)
1683 printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>")); 1705 printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>"));
1684 printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); 1706 printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds"));
1685 printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); 1707 printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,"));
1686 printf (" %s\n", _("a STATE_CRITICAL will be returned.")); 1708 printf (" %s\n", _("a STATE_CRITICAL will be returned. By adding a colon to the method you can set the method used"));
1709 printf (" %s\n", _("inside the proxied connection: -j CONNECT:POST"));
1687 1710
1688#endif 1711#endif
1689 1712