diff options
Diffstat (limited to 'plugins/t/check_fping.t')
-rw-r--r-- | plugins/t/check_fping.t | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/plugins/t/check_fping.t b/plugins/t/check_fping.t index 08692e46..67b357b2 100644 --- a/plugins/t/check_fping.t +++ b/plugins/t/check_fping.t | |||
@@ -5,40 +5,30 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use Test; | 8 | use Test::More; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | use vars qw($tests); | 11 | my $host_responsive = getTestParameter("NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", "localhost"); |
12 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | ||
13 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | ||
12 | 14 | ||
13 | BEGIN {$tests = 4; plan tests => $tests} | 15 | my $res; |
14 | |||
15 | my $successOutput = '/^FPING OK - /'; | ||
16 | my $failureOutput = '/^FPING CRITICAL - /'; | ||
17 | |||
18 | my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost", | ||
19 | "The hostname of system responsive to network requests" ); | ||
20 | |||
21 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | ||
22 | "The hostname of system not responsive to network requests" ); | ||
23 | |||
24 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | ||
25 | "An invalid (not known to DNS) hostname" ); | ||
26 | |||
27 | |||
28 | my $t; | ||
29 | 16 | ||
30 | my $fping = qx(which fping 2> /dev/null); | 17 | my $fping = qx(which fping 2> /dev/null); |
31 | chomp($fping); | 18 | chomp($fping); |
32 | if( ! -x "./check_fping") { | 19 | if( ! -x "./check_fping") { |
33 | $t += skipMissingCmd( "./check_fping", $tests ); | 20 | plan skip_all => "check_fping not found, skipping tests"; |
34 | } | 21 | } |
35 | elsif ( $> != 0 && (!$fping || ! -u $fping)) { | 22 | elsif ( !$fping || !-x $fping ) { |
36 | $t += skipMsg( "./check_fping", $tests ); | 23 | plan skip_all => "fping not found or cannot be executed, skipping tests"; |
37 | } else { | 24 | } else { |
38 | $t += checkCmd( "./check_fping $host_responsive", 0, $successOutput ); | 25 | plan tests => 3; |
39 | $t += checkCmd( "./check_fping $host_nonresponsive", [ 1, 2 ] ); | 26 | $res = NPTest->testCmd( "./check_fping $host_responsive" ); |
40 | $t += checkCmd( "./check_fping $hostname_invalid", [ 1, 2 ] ); | 27 | cmp_ok( $res->return_code, '==', 0, "Responsive host returns OK"); |
41 | } | ||
42 | 28 | ||
43 | exit(0) if defined($Test::Harness::VERSION); | 29 | $res = NPTest->testCmd( "./check_fping $host_nonresponsive" ); |
44 | exit($tests - $t); | 30 | cmp_ok( $res->return_code, '==', 2, "Non-Responsive host returns Critical"); |
31 | |||
32 | $res = NPTest->testCmd( "./check_fping $hostname_invalid" ); | ||
33 | cmp_ok( $res->return_code, '==', 3, "Invalid host returns Unknown"); | ||
34 | } | ||