diff options
Diffstat (limited to 'plugins/t')
| -rw-r--r-- | plugins/t/NPTest.cache.travis | 4 | ||||
| -rw-r--r-- | plugins/t/check_http.t | 34 | ||||
| -rw-r--r-- | plugins/t/check_snmp.t | 8 | ||||
| -rw-r--r-- | plugins/t/check_users.t | 4 |
4 files changed, 41 insertions, 9 deletions
diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis index fe8aabdb..5d9c5ff7 100644 --- a/plugins/t/NPTest.cache.travis +++ b/plugins/t/NPTest.cache.travis | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', | 11 | 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', |
| 12 | 'NP_HOST_RESPONSIVE' => 'localhost', | 12 | 'NP_HOST_RESPONSIVE' => 'localhost', |
| 13 | 'NP_HOST_SMB' => '', | 13 | 'NP_HOST_SMB' => '', |
| 14 | 'NP_HOST_SNMP' => '', | 14 | 'NP_HOST_SNMP' => 'localhost', |
| 15 | 'NP_HOST_TCP_FTP' => '', | 15 | 'NP_HOST_TCP_FTP' => '', |
| 16 | 'NP_HOST_TCP_HPJD' => '', | 16 | 'NP_HOST_TCP_HPJD' => '', |
| 17 | 'NP_HOST_HPJD_PORT_INVALID' => '161', | 17 | 'NP_HOST_HPJD_PORT_INVALID' => '161', |
| @@ -39,7 +39,7 @@ | |||
| 39 | 'NP_SMB_SHARE_SPC' => '', | 39 | 'NP_SMB_SHARE_SPC' => '', |
| 40 | 'NP_SMB_VALID_USER' => '', | 40 | 'NP_SMB_VALID_USER' => '', |
| 41 | 'NP_SMB_VALID_USER_PASS' => '', | 41 | 'NP_SMB_VALID_USER_PASS' => '', |
| 42 | 'NP_SNMP_COMMUNITY' => '', | 42 | 'NP_SNMP_COMMUNITY' => 'public', |
| 43 | 'NP_SSH_CONFIGFILE' => '~/.ssh/config', | 43 | 'NP_SSH_CONFIGFILE' => '~/.ssh/config', |
| 44 | 'NP_SSH_HOST' => 'localhost', | 44 | 'NP_SSH_HOST' => 'localhost', |
| 45 | 'NP_SSH_IDENTITY' => '~/.ssh/id_dsa', | 45 | 'NP_SSH_IDENTITY' => '~/.ssh/id_dsa', |
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index c2caec60..5a90f02a 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
| @@ -9,7 +9,7 @@ use Test::More; | |||
| 9 | use POSIX qw/mktime strftime/; | 9 | use POSIX qw/mktime strftime/; |
| 10 | use NPTest; | 10 | use NPTest; |
| 11 | 11 | ||
| 12 | plan tests => 42; | 12 | plan tests => 49; |
| 13 | 13 | ||
| 14 | my $successOutput = '/OK.*HTTP.*second/'; | 14 | my $successOutput = '/OK.*HTTP.*second/'; |
| 15 | 15 | ||
| @@ -64,6 +64,32 @@ cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); | |||
| 64 | # Is also possible to get a socket timeout if DNS is not responding fast enough | 64 | # Is also possible to get a socket timeout if DNS is not responding fast enough |
| 65 | like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK"); | 65 | like( $res->output, "/Unable to open TCP socket|Socket timeout after/", "Output OK"); |
| 66 | 66 | ||
| 67 | # host header checks | ||
| 68 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http"); | ||
| 69 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); | ||
| 70 | |||
| 71 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http -p 80"); | ||
| 72 | like( $res->output, '/^Host: '.$host_tcp_http.'\s*$/ms', "Host Header OK" ); | ||
| 73 | |||
| 74 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http:8080 -p 80"); | ||
| 75 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); | ||
| 76 | |||
| 77 | $res = NPTest->testCmd("./check_http -v -H $host_tcp_http:8080 -p 80"); | ||
| 78 | like( $res->output, '/^Host: '.$host_tcp_http.':8080\s*$/ms', "Host Header OK" ); | ||
| 79 | |||
| 80 | SKIP: { | ||
| 81 | skip "No internet access", 3 if $internet_access eq "no"; | ||
| 82 | |||
| 83 | $res = NPTest->testCmd("./check_http -v -H www.verisign.com -S"); | ||
| 84 | like( $res->output, '/^Host: www.verisign.com\s*$/ms', "Host Header OK" ); | ||
| 85 | |||
| 86 | $res = NPTest->testCmd("./check_http -v -H www.verisign.com:8080 -S -p 443"); | ||
| 87 | like( $res->output, '/^Host: www.verisign.com:8080\s*$/ms', "Host Header OK" ); | ||
| 88 | |||
| 89 | $res = NPTest->testCmd("./check_http -v -H www.verisign.com:443 -S -p 443"); | ||
| 90 | like( $res->output, '/^Host: www.verisign.com\s*$/ms', "Host Header OK" ); | ||
| 91 | }; | ||
| 92 | |||
| 67 | SKIP: { | 93 | SKIP: { |
| 68 | skip "No host serving monitoring in index file", 7 unless $host_tcp_http2; | 94 | skip "No host serving monitoring in index file", 7 unless $host_tcp_http2; |
| 69 | 95 | ||
| @@ -121,9 +147,9 @@ SKIP: { | |||
| 121 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./check_http -C 1 www.verisign.com"); | 147 | $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"); | 148 | 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" ); | 149 | 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+)\./); | 150 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); |
| 125 | if(!defined $year) { | 151 | if(!defined $year) { |
| 126 | die("parsing date failed from: ".$res); | 152 | die("parsing date failed from: ".$res->output); |
| 127 | } | 153 | } |
| 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}; | 154 | 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); | 155 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); |
| @@ -154,7 +180,7 @@ SKIP: { | |||
| 154 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 180 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
| 155 | 181 | ||
| 156 | $res = NPTest->testCmd( | 182 | $res = NPTest->testCmd( |
| 157 | "./check_http --ssl www.e-paycobalt.com" | 183 | "./check_http --ssl -H www.e-paycobalt.com" |
| 158 | ); | 184 | ); |
| 159 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); | 185 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); |
| 160 | 186 | ||
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index aefd872a..eff46ea1 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
| @@ -10,7 +10,7 @@ use NPTest; | |||
| 10 | 10 | ||
| 11 | BEGIN { | 11 | BEGIN { |
| 12 | plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp"; | 12 | plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp"; |
| 13 | plan tests => 61; | 13 | plan tests => 63; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | my $res; | 16 | my $res; |
| @@ -45,7 +45,7 @@ is( $res->return_code, 3, "Invalid protocol" ); | |||
| 45 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); | 45 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); |
| 46 | 46 | ||
| 47 | SKIP: { | 47 | SKIP: { |
| 48 | skip "no snmp host defined", 48 if ( ! $host_snmp ); | 48 | skip "no snmp host defined", 50 if ( ! $host_snmp ); |
| 49 | 49 | ||
| 50 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | 50 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); |
| 51 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); | 51 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); |
| @@ -153,6 +153,10 @@ SKIP: { | |||
| 153 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0"); | 153 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0"); |
| 154 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | 154 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); |
| 155 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); | 155 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); |
| 156 | |||
| 157 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunParameters.1"); | ||
| 158 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | ||
| 159 | is( $res->output, 'SNMP OK - "" | ', "snmp response without datatype" ); | ||
| 156 | } | 160 | } |
| 157 | 161 | ||
| 158 | SKIP: { | 162 | SKIP: { |
diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t index 39044bb5..088f3b52 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); |
