summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_http.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t/check_http.t')
-rw-r--r--plugins/t/check_http.t52
1 files changed, 11 insertions, 41 deletions
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 416fbbcb..b3760ebe 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -9,46 +9,21 @@ use Test::More;
9use POSIX qw/mktime strftime/; 9use POSIX qw/mktime strftime/;
10use NPTest; 10use NPTest;
11 11
12plan tests => 55; 12plan tests => 50;
13 13
14my $successOutput = '/OK.*HTTP.*second/'; 14my $successOutput = '/OK.*HTTP.*second/';
15 15
16my $res; 16my $res;
17 17
18my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP", 18my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost");
19 "A host providing the HTTP Service (a web server)", 19my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost");
20 "localhost" ); 20my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost");
21 21my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
22my $host_tls_http = getTestParameter( "host_tls_http", "NP_HOST_TLS_HTTP", "localhost", 22my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
23 "A host providing the HTTPS Service (a tls web server)" ); 23my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes");
24 24my $host_tcp_http2 = getTestParameter("NP_HOST_TCP_HTTP2", "A host providing an index page containing the string 'monitoring'", "test.monitoring-plugins.org");
25my $host_tls_cert = getTestParameter( "host_tls_cert", "NP_HOST_TLS_CERT", "localhost", 25my $host_tcp_proxy = getTestParameter("NP_HOST_TCP_PROXY", "A host providing a HTTP proxy with CONNECT support", "localhost");
26 "the common name of the certificate." ); 26my $port_tcp_proxy = getTestParameter("NP_PORT_TCP_PROXY", "Port of the proxy with HTTP and CONNECT support", "3128");
27
28
29my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
30 "The hostname of system not responsive to network requests",
31 "10.0.0.1" );
32
33my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
34 "An invalid (not known to DNS) hostname",
35 "nosuchhost");
36
37my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
38 "Is this system directly connected to the internet?",
39 "yes");
40
41my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
42 "A host providing an index page containing the string 'monitoring'",
43 "test.monitoring-plugins.org" );
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 27
53my $faketime = -x '/usr/bin/faketime' ? 1 : 0; 28my $faketime = -x '/usr/bin/faketime' ? 1 : 0;
54 29
@@ -158,7 +133,7 @@ SKIP: {
158 133
159 # run some certificate checks with faketime 134 # run some certificate checks with faketime
160 SKIP: { 135 SKIP: {
161 skip "No faketime binary found", 12 if !$faketime; 136 skip "No faketime binary found", 7 if !$faketime;
162 $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 $host_tls_http"); 137 $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 $host_tls_http");
163 like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); 138 like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output");
164 is( $res->return_code, 0, "Catch cert output exit code" ); 139 is( $res->return_code, 0, "Catch cert output exit code" );
@@ -171,23 +146,18 @@ SKIP: {
171 my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); 146 my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts));
172 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_http -C 1 $host_tls_http"); 147 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_http -C 1 $host_tls_http");
173 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date"); 148 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date");
174 is( $res->return_code, 2, "Output on expire date" );
175 149
176 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./check_http -C 1 $host_tls_http"); 150 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./check_http -C 1 $host_tls_http");
177 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); 151 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output");
178 is( $res->return_code, 2, "cert expires in 1 second exit code" );
179 152
180 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./check_http -C 1 $host_tls_http"); 153 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./check_http -C 1 $host_tls_http");
181 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); 154 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output");
182 is( $res->return_code, 2, "cert expires in 2 minutes exit code" );
183 155
184 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./check_http -C 1 $host_tls_http"); 156 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./check_http -C 1 $host_tls_http");
185 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); 157 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output");
186 is( $res->return_code, 2, "cert expires in 2 hours exit code" );
187 158
188 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_http -C 1 $host_tls_http"); 159 $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_http -C 1 $host_tls_http");
189 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output"); 160 like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output");
190 is( $res->return_code, 2, "Certificate expired exit code" );
191 }; 161 };
192 162
193 $res = NPTest->testCmd( "./check_http --ssl $host_tls_http -E" ); 163 $res = NPTest->testCmd( "./check_http --ssl $host_tls_http -E" );