summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_http.t
diff options
context:
space:
mode:
authorSven Nierlein <Sven.Nierlein@consol.de>2018-12-04 15:20:18 +0100
committerSven Nierlein <Sven.Nierlein@consol.de>2018-12-04 15:20:19 +0100
commitd7dcca22ae2f7bdf0ee2282e00c1999de0b58e26 (patch)
tree56c6268f2a2481ff7b866ccd09c2005d7ec24a67 /plugins/t/check_http.t
parentb69eb5afed40f14ba648c3358e2b46aeb75b0c5d (diff)
downloadmonitoring-plugins-d7dcca22ae2f7bdf0ee2282e00c1999de0b58e26.tar.gz
tests: rework test parameters
there were 2 variants of calling getTestParameter: - parameter, description, default value - parameter, env value, default value, description, scope While scope was never actually used and having 2 names for the same value led to having 2 different entries in the cache file for the same configuration. This commit removes the variants and simplifies tests parameters by only using the first 3 parameter variant.
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" );