diff options
Diffstat (limited to 'plugins/t')
| -rw-r--r-- | plugins/t/NPTest.cache.travis | 4 | ||||
| -rw-r--r-- | plugins/t/check_dns.t | 12 | ||||
| -rw-r--r-- | plugins/t/check_http.t | 43 | ||||
| -rw-r--r-- | plugins/t/check_ldap.t | 80 | ||||
| -rw-r--r-- | plugins/t/negate.t | 5 |
5 files changed, 137 insertions, 7 deletions
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis index 4ebfb90e..fe8aabdb 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_dns.t b/plugins/t/check_dns.t index b8858807..035e7682 100644 --- a/plugins/t/check_dns.t +++ b/plugins/t/check_dns.t | |||
| @@ -10,7 +10,7 @@ use NPTest; | |||
| 10 | 10 | ||
| 11 | plan skip_all => "check_dns not compiled" unless (-x "check_dns"); | 11 | plan skip_all => "check_dns not compiled" unless (-x "check_dns"); |
| 12 | 12 | ||
| 13 | plan tests => 14; | 13 | plan tests => 16; |
| 14 | 14 | ||
| 15 | my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; | 15 | my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; |
| 16 | 16 | ||
| @@ -43,6 +43,12 @@ my $dns_server = getTestParameter( | |||
| 43 | "A non default (remote) DNS server", | 43 | "A non default (remote) DNS server", |
| 44 | ); | 44 | ); |
| 45 | 45 | ||
| 46 | my $host_nonresponsive = getTestParameter( | ||
| 47 | "NP_HOST_NONRESPONSIVE", | ||
| 48 | "The hostname of system not responsive to network requests", | ||
| 49 | "10.0.0.1", | ||
| 50 | ); | ||
| 51 | |||
| 46 | my $res; | 52 | my $res; |
| 47 | 53 | ||
| 48 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5"); | 54 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5"); |
| @@ -66,6 +72,10 @@ like ( $res->output, $successOutput, "Output OK" ); | |||
| 66 | $res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1"); | 72 | $res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1"); |
| 67 | cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server"); | 73 | cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server"); |
| 68 | 74 | ||
| 75 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -s $host_nonresponsive -t 2"); | ||
| 76 | cmp_ok( $res->return_code, '==', 2, "Got no answer from unresponsive server"); | ||
| 77 | like ( $res->output, "/CRITICAL - /", "Output OK"); | ||
| 78 | |||
| 69 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5"); | 79 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5"); |
| 70 | cmp_ok( $res->return_code, '==', 0, "Got expected address"); | 80 | cmp_ok( $res->return_code, '==', 0, "Got expected address"); |
| 71 | 81 | ||
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 2539a289..c2caec60 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,6 +115,40 @@ 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); | ||
| 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' ); |
diff --git a/plugins/t/check_ldap.t b/plugins/t/check_ldap.t new file mode 100644 index 00000000..b8944d4b --- /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/negate.t b/plugins/t/negate.t index f18acc39..d96a109b 100644 --- a/plugins/t/negate.t +++ b/plugins/t/negate.t | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | use strict; | 7 | use strict; |
| 8 | use Test::More; | 8 | use Test::More; |
| 9 | use Cwd; | ||
| 9 | use NPTest; | 10 | use NPTest; |
| 10 | 11 | ||
| 11 | # 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops | 12 | # 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops |
| @@ -13,7 +14,7 @@ plan tests => 88; | |||
| 13 | 14 | ||
| 14 | my $res; | 15 | my $res; |
| 15 | 16 | ||
| 16 | my $PWD = $ENV{PWD}; | 17 | my $PWD = getcwd(); |
| 17 | 18 | ||
| 18 | $res = NPTest->testCmd( "./negate" ); | 19 | $res = NPTest->testCmd( "./negate" ); |
| 19 | is( $res->return_code, 3, "Not enough parameters"); | 20 | is( $res->return_code, 3, "Not enough parameters"); |
| @@ -50,7 +51,7 @@ is( $res->output, "OK: a dummy okay", "The quoted string is passed through to su | |||
| 50 | $res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" ); | 51 | $res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" ); |
| 51 | is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')"); | 52 | is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')"); |
| 52 | 53 | ||
| 53 | $res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' ); | 54 | $res = NPTest->testCmd( './negate '.$PWD.'/check_dummy 0 \'$$ a dummy okay\'' ); |
| 54 | is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); | 55 | is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); |
| 55 | 56 | ||
| 56 | my %state = ( | 57 | my %state = ( |
