diff options
Diffstat (limited to 'plugins/t')
-rw-r--r-- | plugins/t/NPTest.cache.travis | 4 | ||||
-rw-r--r-- | plugins/t/check_http.t | 45 | ||||
-rw-r--r-- | plugins/t/check_ldap.t | 80 | ||||
-rw-r--r-- | plugins/t/check_snmp.t | 4 | ||||
-rw-r--r-- | plugins/t/check_users.t | 4 |
5 files changed, 129 insertions, 8 deletions
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis index 4ebfb90..fe8aabd 100644 --- a/plugins/t/NPTest.cache.travis +++ b/plugins/t/NPTest.cache.travis | |||
@@ -17,13 +17,15 @@ | |||
17 | 'NP_HOST_HPJD_PORT_INVALID' => '161', | 17 | 'NP_HOST_HPJD_PORT_INVALID' => '161', |
18 | 'NP_HOST_HPJD_PORT_VALID' => '', | 18 | 'NP_HOST_HPJD_PORT_VALID' => '', |
19 | 'NP_HOST_TCP_HTTP' => 'localhost', | 19 | 'NP_HOST_TCP_HTTP' => 'localhost', |
20 | 'NP_HOST_TCP_HTTP2' => 'labs.consol.de', | 20 | 'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org', |
21 | 'NP_HOST_TCP_IMAP' => 'imap.web.de', | 21 | 'NP_HOST_TCP_IMAP' => 'imap.web.de', |
22 | 'NP_HOST_TCP_LDAP' => 'localhost', | ||
22 | 'NP_HOST_TCP_POP' => 'pop.web.de', | 23 | 'NP_HOST_TCP_POP' => 'pop.web.de', |
23 | 'NP_HOST_TCP_SMTP' => 'localhost', | 24 | 'NP_HOST_TCP_SMTP' => 'localhost', |
24 | 'NP_HOST_TCP_SMTP_NOTLS' => '', | 25 | 'NP_HOST_TCP_SMTP_NOTLS' => '', |
25 | 'NP_HOST_TCP_SMTP_TLS' => '', | 26 | 'NP_HOST_TCP_SMTP_TLS' => '', |
26 | 'NP_INTERNET_ACCESS' => 'yes', | 27 | 'NP_INTERNET_ACCESS' => 'yes', |
28 | 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain', | ||
27 | 'NP_MOUNTPOINT2_VALID' => '', | 29 | 'NP_MOUNTPOINT2_VALID' => '', |
28 | 'NP_MOUNTPOINT_VALID' => '/', | 30 | 'NP_MOUNTPOINT_VALID' => '/', |
29 | 'NP_MYSQL_SERVER' => 'localhost', | 31 | 'NP_MYSQL_SERVER' => 'localhost', |
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 2539a28..f514ca6 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -6,9 +6,10 @@ | |||
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use Test::More; | 8 | use Test::More; |
9 | use POSIX qw/mktime strftime/; | ||
9 | use NPTest; | 10 | use NPTest; |
10 | 11 | ||
11 | plan tests => 30; | 12 | plan tests => 42; |
12 | 13 | ||
13 | my $successOutput = '/OK.*HTTP.*second/'; | 14 | my $successOutput = '/OK.*HTTP.*second/'; |
14 | 15 | ||
@@ -34,6 +35,8 @@ my $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", | |||
34 | "A host providing an index page containing the string 'monitoring'", | 35 | "A host providing an index page containing the string 'monitoring'", |
35 | "test.monitoring-plugins.org" ); | 36 | "test.monitoring-plugins.org" ); |
36 | 37 | ||
38 | my $faketime = -x '/usr/bin/faketime' ? 1 : 0; | ||
39 | |||
37 | 40 | ||
38 | $res = NPTest->testCmd( | 41 | $res = NPTest->testCmd( |
39 | "./check_http $host_tcp_http -wt 300 -ct 600" | 42 | "./check_http $host_tcp_http -wt 300 -ct 600" |
@@ -47,10 +50,10 @@ $res = NPTest->testCmd( | |||
47 | like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); | 50 | like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); |
48 | 51 | ||
49 | $res = NPTest->testCmd( | 52 | $res = NPTest->testCmd( |
50 | "./check_http $host_nonresponsive -wt 1 -ct 2" | 53 | "./check_http $host_nonresponsive -wt 1 -ct 2 -t 3" |
51 | ); | 54 | ); |
52 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); | 55 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); |
53 | cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 10 seconds", "Output OK"); | 56 | cmp_ok( $res->output, 'eq', "CRITICAL - Socket timeout after 3 seconds", "Output OK"); |
54 | 57 | ||
55 | $res = NPTest->testCmd( | 58 | $res = NPTest->testCmd( |
56 | "./check_http $hostname_invalid -wt 1 -ct 2" | 59 | "./check_http $hostname_invalid -wt 1 -ct 2" |
@@ -112,12 +115,46 @@ SKIP: { | |||
112 | $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); | 115 | $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); |
113 | cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); | 116 | cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); |
114 | 117 | ||
118 | # run some certificate checks with faketime | ||
119 | SKIP: { | ||
120 | skip "No faketime binary found", 12 if !$faketime; | ||
121 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 www.verisign.com"); | ||
122 | like($res->output, qr/OK - Certificate 'www.verisign.com' will expire on/, "Catch cert output"); | ||
123 | is( $res->return_code, 0, "Catch cert output exit code" ); | ||
124 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); | ||
125 | if(!defined $year) { | ||
126 | die("parsing date failed from: ".$res->output); | ||
127 | } | ||
128 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; | ||
129 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); | ||
130 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); | ||
131 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_http -C 1 www.verisign.com"); | ||
132 | like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' just expired/, "Output on expire date"); | ||
133 | is( $res->return_code, 2, "Output on expire date" ); | ||
134 | |||
135 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./check_http -C 1 www.verisign.com"); | ||
136 | like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expires in 0 minutes/, "cert expires in 1 second output"); | ||
137 | is( $res->return_code, 2, "cert expires in 1 second exit code" ); | ||
138 | |||
139 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./check_http -C 1 www.verisign.com"); | ||
140 | like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expires in 2 minutes/, "cert expires in 2 minutes output"); | ||
141 | is( $res->return_code, 2, "cert expires in 2 minutes exit code" ); | ||
142 | |||
143 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./check_http -C 1 www.verisign.com"); | ||
144 | like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expires in 2 hours/, "cert expires in 2 hours output"); | ||
145 | is( $res->return_code, 2, "cert expires in 2 hours exit code" ); | ||
146 | |||
147 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_http -C 1 www.verisign.com"); | ||
148 | like($res->output, qr/CRITICAL - Certificate 'www.verisign.com' expired on/, "Certificate expired output"); | ||
149 | is( $res->return_code, 2, "Certificate expired exit code" ); | ||
150 | }; | ||
151 | |||
115 | $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" ); | 152 | $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" ); |
116 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 153 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
117 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 154 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
118 | 155 | ||
119 | $res = NPTest->testCmd( | 156 | $res = NPTest->testCmd( |
120 | "./check_http --ssl www.e-paycobalt.com" | 157 | "./check_http --ssl -H www.e-paycobalt.com" |
121 | ); | 158 | ); |
122 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); | 159 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); |
123 | 160 | ||
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t new file mode 100644 index 0000000..b8944d4 --- /dev/null +++ b/plugins/t/check_ldap.t | |||
@@ -0,0 +1,80 @@ | |||
1 | #!/usr/bin/env perl -I .. | ||
2 | # | ||
3 | # Lightweight Directory Access Protocol (LDAP) Test via check_ldap | ||
4 | # | ||
5 | # | ||
6 | |||
7 | use strict; | ||
8 | use warnings; | ||
9 | use Test::More; | ||
10 | use NPTest; | ||
11 | |||
12 | my $host_tcp_ldap = getTestParameter("NP_HOST_TCP_LDAP", | ||
13 | "A host providing the LDAP Service", | ||
14 | "localhost" ); | ||
15 | |||
16 | my $ldap_base_dn = getTestParameter("NP_LDAP_BASE_DN", | ||
17 | "A base dn for the LDAP Service", | ||
18 | "cn=admin" ); | ||
19 | |||
20 | my $host_nonresponsive = getTestParameter("host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
21 | "The hostname of system not responsive to network requests" ); | ||
22 | |||
23 | my $hostname_invalid = getTestParameter("hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
24 | "An invalid (not known to DNS) hostname" ); | ||
25 | |||
26 | my($result, $cmd); | ||
27 | my $command = './check_ldap'; | ||
28 | |||
29 | plan tests => 16; | ||
30 | |||
31 | SKIP: { | ||
32 | skip "NP_HOST_NONRESPONSIVE not set", 2 if ! $host_nonresponsive; | ||
33 | |||
34 | $result = NPTest->testCmd("$command -H $host_nonresponsive -b ou=blah -t 2 -w 1 -c 1"); | ||
35 | is( $result->return_code, 2, "$command -H $host_nonresponsive -b ou=blah -t 5 -w 2 -c 3" ); | ||
36 | is( $result->output, 'CRITICAL - Socket timeout after 2 seconds', "output ok" ); | ||
37 | }; | ||
38 | |||
39 | SKIP: { | ||
40 | skip "NP_HOSTNAME_INVALID not set", 2 if ! $hostname_invalid; | ||
41 | |||
42 | $result = NPTest->testCmd("$command -H $hostname_invalid -b ou=blah -t 5"); | ||
43 | is( $result->return_code, 2, "$command -H $hostname_invalid -b ou=blah -t 5" ); | ||
44 | is( $result->output, 'Could not bind to the LDAP server', "output ok" ); | ||
45 | }; | ||
46 | |||
47 | SKIP: { | ||
48 | skip "NP_HOST_TCP_LDAP not set", 12 if ! $host_tcp_ldap; | ||
49 | skip "NP_LDAP_BASE_DN not set", 12 if ! $ldap_base_dn; | ||
50 | |||
51 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3"; | ||
52 | $result = NPTest->testCmd($cmd); | ||
53 | is( $result->return_code, 0, $cmd ); | ||
54 | like( $result->output, '/^LDAP OK - \d+.\d+ seconds response time\|time=\d+\.\d+s;2\.0+;3\.0+;0\.0+$/', "output ok" ); | ||
55 | |||
56 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000 -C 10000001"; | ||
57 | $result = NPTest->testCmd($cmd); | ||
58 | is( $result->return_code, 0, $cmd ); | ||
59 | like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000;10000001;0\.0+$/', "output ok" ); | ||
60 | |||
61 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001:"; | ||
62 | $result = NPTest->testCmd($cmd); | ||
63 | is( $result->return_code, 2, $cmd ); | ||
64 | like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001:;0\.0+$/', "output ok" ); | ||
65 | |||
66 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 0 -C 0"; | ||
67 | $result = NPTest->testCmd($cmd); | ||
68 | is( $result->return_code, 2, $cmd ); | ||
69 | like( $result->output, '/^LDAP CRITICAL - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;0;0;0\.0+$/', "output ok" ); | ||
70 | |||
71 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -W 10000000: -C 10000001"; | ||
72 | $result = NPTest->testCmd($cmd); | ||
73 | is( $result->return_code, 1, $cmd ); | ||
74 | like( $result->output, '/^LDAP WARNING - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;10000000:;10000001;0\.0+$/', "output ok" ); | ||
75 | |||
76 | $cmd = "$command -H $host_tcp_ldap -b $ldap_base_dn -t 5 -w 2 -c 3 -3 -C 10000001"; | ||
77 | $result = NPTest->testCmd($cmd); | ||
78 | is( $result->return_code, 0, $cmd ); | ||
79 | like( $result->output, '/^LDAP OK - found \d+ entries in \d+\.\d+ seconds\|time=\d\.\d+s;2\.0+;3\.0+;0\.0+ entries=\d+\.0+;;10000001;0\.0+$/', "output ok" ); | ||
80 | }; | ||
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index 2d6c44a..aefd872 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
@@ -166,8 +166,8 @@ SKIP: { | |||
166 | SKIP: { | 166 | SKIP: { |
167 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); | 167 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); |
168 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | 168 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); |
169 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | 169 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" ); |
170 | like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem"); | 170 | like($res->output, '/Plugin timed out while executing system call/', "String matches timeout problem"); |
171 | } | 171 | } |
172 | 172 | ||
173 | SKIP: { | 173 | SKIP: { |
diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t index 39044bb..088f3b5 100644 --- a/plugins/t/check_users.t +++ b/plugins/t/check_users.t | |||
@@ -13,7 +13,7 @@ use Test; | |||
13 | use NPTest; | 13 | use NPTest; |
14 | 14 | ||
15 | use vars qw($tests); | 15 | use vars qw($tests); |
16 | BEGIN {$tests = 4; plan tests => $tests} | 16 | BEGIN {$tests = 8; plan tests => $tests} |
17 | 17 | ||
18 | my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; | 18 | my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; |
19 | my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; | 19 | my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; |
@@ -22,6 +22,8 @@ my $t; | |||
22 | 22 | ||
23 | $t += checkCmd( "./check_users 1000 1000", 0, $successOutput ); | 23 | $t += checkCmd( "./check_users 1000 1000", 0, $successOutput ); |
24 | $t += checkCmd( "./check_users 0 0", 2, $failureOutput ); | 24 | $t += checkCmd( "./check_users 0 0", 2, $failureOutput ); |
25 | $t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput ); | ||
26 | $t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput ); | ||
25 | 27 | ||
26 | exit(0) if defined($Test::Harness::VERSION); | 28 | exit(0) if defined($Test::Harness::VERSION); |
27 | exit($tests - $t); | 29 | exit($tests - $t); |