Merge remote-tracking branch 'monitoring-plugins/pr/1476'

* monitoring-plugins/pr/1476:
  test: Add proxy tests via proxy
  Allow user to specify HTTP method after proxy CONNECT
This commit is contained in:
Holger Weiss 2018-11-06 12:49:18 +01:00
commit 0863a4cb93
5 changed files with 8023 additions and 5 deletions

View file

@ -55,6 +55,7 @@ install:
- sudo apt-get install -qq --no-install-recommends autoconf automake
- sudo apt-get install -qq --no-install-recommends faketime
- sudo apt-get install -qq --no-install-recommends libmonitoring-plugin-perl
- sudo apt-get install -qq --no-install-recommends squid3
# Trusty related dependencies (not yet provided)
- test "$(dpkg -l | grep -E "mysql-(client|server)-[0-9].[0-9]" | grep -c ^ii)" -gt 0 || sudo apt-get install -qq --no-install-recommends mariadb-client mariadb-server
# enable ssl apache
@ -62,6 +63,8 @@ install:
- sudo a2ensite default-ssl
- sudo make-ssl-cert generate-default-snakeoil --force-overwrite
- sudo service apache2 reload
- sudo cp tools/squid.conf /etc/squid3/squid.conf
- sudo service squid3 reload
before_script:
# ensure we have a test database in place for tests
@ -93,4 +96,3 @@ notifications:
skip_join: true
email:
# - team@monitoring-plugins.org

View file

@ -126,6 +126,7 @@ int max_page_len = 0;
int redir_depth = 0;
int max_depth = 15;
char *http_method;
char *http_method_proxy;
char *http_post_data;
char *http_content_type;
char buffer[MAX_INPUT_BUFFER];
@ -446,6 +447,12 @@ process_arguments (int argc, char **argv)
if (http_method)
free(http_method);
http_method = strdup (optarg);
char *tmp;
if ((tmp = strstr(http_method, ":")) > 0) {
tmp[0] = '\0';
http_method = http_method;
http_method_proxy = ++tmp;
}
break;
case 'd': /* string or substring */
strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1);
@ -566,6 +573,9 @@ process_arguments (int argc, char **argv)
if (http_method == NULL)
http_method = strdup ("GET");
if (http_method_proxy == NULL)
http_method_proxy = strdup ("GET");
if (client_cert && !client_privkey)
usage4 (_("If you use a client certificate you must also specify a private key file"));
@ -950,7 +960,7 @@ check_http (void)
if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0
&& host_name != NULL && use_ssl == TRUE)
asprintf (&buf, "%s %s %s\r\n%s\r\n", "GET", server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
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);
else
asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent);
@ -1581,7 +1591,7 @@ print_help (void)
printf (" %s\n", _("URL to GET or POST (default: /)"));
printf (" %s\n", "-P, --post=STRING");
printf (" %s\n", _("URL encoded http POST data"));
printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)");
printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)");
printf (" %s\n", _("Set HTTP method."));
printf (" %s\n", "-N, --no-body");
printf (" %s\n", _("Don't wait for document body: stop reading after headers."));
@ -1668,7 +1678,8 @@ print_help (void)
printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>"));
printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds"));
printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,"));
printf (" %s\n", _("a STATE_CRITICAL will be returned."));
printf (" %s\n", _("a STATE_CRITICAL will be returned. By adding a colon to the method you can set the method used"));
printf (" %s\n", _("inside the proxied connection: -j CONNECT:POST"));
#endif

View file

@ -59,4 +59,6 @@
'host_udp_time' => 'none',
'host_tls_http' => 'localhost',
'host_tls_cert' => 'localhost',
'NP_HOST_TCP_PROXY' => 'localhost',
'NP_PORT_TCP_PROXY' => '3128',
}

View file

@ -9,7 +9,7 @@ use Test::More;
use POSIX qw/mktime strftime/;
use NPTest;
plan tests => 49;
plan tests => 55;
my $successOutput = '/OK.*HTTP.*second/';
@ -42,6 +42,14 @@ my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
"A host providing an index page containing the string 'monitoring'",
"test.monitoring-plugins.org" );
my $host_tcp_proxy = getTestParameter( "NP_HOST_TCP_PROXY",
"A host providing a HTTP proxy with CONNECT support",
"localhost");
my $port_tcp_proxy = getTestParameter( "NP_PORT_TCP_PROXY",
"Port of the proxy with HTTP and CONNECT support",
"3128");
my $faketime = -x '/usr/bin/faketime' ? 1 : 0;
@ -198,3 +206,19 @@ SKIP: {
$res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" );
like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
}
SKIP: {
skip "No internet access or proxy configured", 6 if $internet_access eq "no" or ! $host_tcp_proxy;
$res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302");
is( $res->return_code, 0, "Proxy HTTP works");
like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent");
$res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT");
is( $res->return_code, 0, "Proxy HTTP CONNECT works");
like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent");
$res = NPTest->testCmd( "./check_http -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD");
is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method");
like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent");
}

7979
tools/squid.conf Normal file

File diff suppressed because it is too large Load diff