aboutsummaryrefslogtreecommitdiff
path: root/plugins/t/check_http.t
diff options
context:
space:
mode:
authorGravatar Andreas Baumann <mail@andreasbaumann.cc> 2019-04-04 13:09:15 +0200
committerGravatar Andreas Baumann <mail@andreasbaumann.cc> 2019-04-04 13:09:15 +0200
commit2f4d6764d78cf085601b34ac92486405bd11095d (patch)
tree550601dc79e74fd4c184dc96a95687d1d1238b43 /plugins/t/check_http.t
parentfaea5899ba3264581bf75649e4b399d0b69bd125 (diff)
parent5f16ba81c4af1a05e67806ca989a1dd46248a5fd (diff)
downloadmonitoring-plugins-2f4d6764d78cf085601b34ac92486405bd11095d.tar.gz
Merge branch 'master' into feature_check_curl
Diffstat (limited to 'plugins/t/check_http.t')
-rw-r--r--plugins/t/check_http.t58
1 files changed, 26 insertions, 32 deletions
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 281fa362..e92681e9 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -9,7 +9,7 @@ use Test::More;
use POSIX qw/mktime strftime/;
use NPTest;
-plan tests => 49;
+plan tests => 50;
my $successOutput = '/OK.*HTTP.*second/';
@@ -17,32 +17,15 @@ my $res;
my $plugin = 'check_http';
$plugin = 'check_curl' if $0 =~ m/check_curl/mx;
-my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP",
- "A host providing the HTTP Service (a web server)",
- "localhost" );
-
-my $host_tls_http = getTestParameter( "host_tls_http", "NP_HOST_TLS_HTTP", "localhost",
- "A host providing the HTTPS Service (a tls web server)" );
-
-my $host_tls_cert = getTestParameter( "host_tls_cert", "NP_HOST_TLS_CERT", "localhost",
- "the common name of the certificate." );
-
-
-my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
- "The hostname of system not responsive to network requests",
- "10.0.0.1" );
-
-my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
- "An invalid (not known to DNS) hostname",
- "nosuchhost");
-
-my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
- "Is this system directly connected to the internet?",
- "yes");
-
-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_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost");
+my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost");
+my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost");
+my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
+my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
+my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes");
+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;
@@ -165,23 +148,18 @@ SKIP: {
my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts));
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./$plugin -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date");
- is( $res->return_code, 2, "Output on expire date" );
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./$plugin -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output");
- is( $res->return_code, 2, "cert expires in 1 second exit code" );
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./$plugin -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output");
- is( $res->return_code, 2, "cert expires in 2 minutes exit code" );
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./$plugin -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output");
- is( $res->return_code, 2, "cert expires in 2 hours exit code" );
$res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./$plugin -C 1 $host_tls_http");
like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output");
- is( $res->return_code, 2, "Certificate expired exit code" );
};
$res = NPTest->testCmd( "./$plugin --ssl $host_tls_http -E" );
@@ -200,3 +178,19 @@ SKIP: {
$res = NPTest->testCmd( "./$plugin -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( "./$plugin -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( "./$plugin -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( "./$plugin -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");
+}