summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_http.c17
-rw-r--r--plugins/t/NPTest.cache.travis2
-rw-r--r--plugins/t/check_http.t26
3 files changed, 41 insertions, 4 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 86a36c2..1e2a54c 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -126,6 +126,7 @@ int max_page_len = 0;
126int redir_depth = 0; 126int redir_depth = 0;
127int max_depth = 15; 127int max_depth = 15;
128char *http_method; 128char *http_method;
129char *http_method_proxy;
129char *http_post_data; 130char *http_post_data;
130char *http_content_type; 131char *http_content_type;
131char buffer[MAX_INPUT_BUFFER]; 132char buffer[MAX_INPUT_BUFFER];
@@ -446,6 +447,12 @@ process_arguments (int argc, char **argv)
446 if (http_method) 447 if (http_method)
447 free(http_method); 448 free(http_method);
448 http_method = strdup (optarg); 449 http_method = strdup (optarg);
450 char *tmp;
451 if ((tmp = strstr(http_method, ":")) > 0) {
452 tmp[0] = '\0';
453 http_method = http_method;
454 http_method_proxy = ++tmp;
455 }
449 break; 456 break;
450 case 'd': /* string or substring */ 457 case 'd': /* string or substring */
451 strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1); 458 strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1);
@@ -566,6 +573,9 @@ process_arguments (int argc, char **argv)
566 if (http_method == NULL) 573 if (http_method == NULL)
567 http_method = strdup ("GET"); 574 http_method = strdup ("GET");
568 575
576 if (http_method_proxy == NULL)
577 http_method_proxy = strdup ("GET");
578
569 if (client_cert && !client_privkey) 579 if (client_cert && !client_privkey)
570 usage4 (_("If you use a client certificate you must also specify a private key file")); 580 usage4 (_("If you use a client certificate you must also specify a private key file"));
571 581
@@ -950,7 +960,7 @@ check_http (void)
950 960
951 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 961 if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
952 && host_name != NULL && use_ssl == TRUE) 962 && host_name != NULL && use_ssl == TRUE)
953 asprintf (&buf, "%s %s %s\r\n%s\r\n", "GET", server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); 963 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);
954 else 964 else
955 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); 965 asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
956 966
@@ -1581,7 +1591,7 @@ print_help (void)
1581 printf (" %s\n", _("URL to GET or POST (default: /)")); 1591 printf (" %s\n", _("URL to GET or POST (default: /)"));
1582 printf (" %s\n", "-P, --post=STRING"); 1592 printf (" %s\n", "-P, --post=STRING");
1583 printf (" %s\n", _("URL encoded http POST data")); 1593 printf (" %s\n", _("URL encoded http POST data"));
1584 printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)"); 1594 printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)");
1585 printf (" %s\n", _("Set HTTP method.")); 1595 printf (" %s\n", _("Set HTTP method."));
1586 printf (" %s\n", "-N, --no-body"); 1596 printf (" %s\n", "-N, --no-body");
1587 printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); 1597 printf (" %s\n", _("Don't wait for document body: stop reading after headers."));
@@ -1668,7 +1678,8 @@ print_help (void)
1668 printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>")); 1678 printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>"));
1669 printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); 1679 printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds"));
1670 printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); 1680 printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,"));
1671 printf (" %s\n", _("a STATE_CRITICAL will be returned.")); 1681 printf (" %s\n", _("a STATE_CRITICAL will be returned. By adding a colon to the method you can set the method used"));
1682 printf (" %s\n", _("inside the proxied connection: -j CONNECT:POST"));
1672 1683
1673#endif 1684#endif
1674 1685
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis
index e9705f3..28437a0 100644
--- a/plugins/t/NPTest.cache.travis
+++ b/plugins/t/NPTest.cache.travis
@@ -59,4 +59,6 @@
59 'host_udp_time' => 'none', 59 'host_udp_time' => 'none',
60 'host_tls_http' => 'localhost', 60 'host_tls_http' => 'localhost',
61 'host_tls_cert' => 'localhost', 61 'host_tls_cert' => 'localhost',
62 'NP_HOST_TCP_PROXY' => 'localhost',
63 'NP_PORT_TCP_PROXY' => '3128',
62} 64}
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 8bd484a..416fbbc 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -9,7 +9,7 @@ use Test::More;
9use POSIX qw/mktime strftime/; 9use POSIX qw/mktime strftime/;
10use NPTest; 10use NPTest;
11 11
12plan tests => 49; 12plan tests => 55;
13 13
14my $successOutput = '/OK.*HTTP.*second/'; 14my $successOutput = '/OK.*HTTP.*second/';
15 15
@@ -42,6 +42,14 @@ my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
42 "A host providing an index page containing the string 'monitoring'", 42 "A host providing an index page containing the string 'monitoring'",
43 "test.monitoring-plugins.org" ); 43 "test.monitoring-plugins.org" );
44 44
45my $host_tcp_proxy = getTestParameter( "NP_HOST_TCP_PROXY",
46 "A host providing a HTTP proxy with CONNECT support",
47 "localhost");
48
49my $port_tcp_proxy = getTestParameter( "NP_PORT_TCP_PROXY",
50 "Port of the proxy with HTTP and CONNECT support",
51 "3128");
52
45my $faketime = -x '/usr/bin/faketime' ? 1 : 0; 53my $faketime = -x '/usr/bin/faketime' ? 1 : 0;
46 54
47 55
@@ -198,3 +206,19 @@ SKIP: {
198 $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" ); 206 $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" );
199 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); 207 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
200} 208}
209
210SKIP: {
211 skip "No internet access or proxy configured", 6 if $internet_access eq "no" or ! $host_tcp_proxy;
212
213 $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302");
214 is( $res->return_code, 0, "Proxy HTTP works");
215 like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent");
216
217 $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT");
218 is( $res->return_code, 0, "Proxy HTTP CONNECT works");
219 like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent");
220
221 $res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD");
222 is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method");
223 like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent");
224}