diff options
Diffstat (limited to 'plugins-root/t/check_icmp.t')
-rw-r--r-- | plugins-root/t/check_icmp.t | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/plugins-root/t/check_icmp.t b/plugins-root/t/check_icmp.t index 78bfd638..e043d4ed 100644 --- a/plugins-root/t/check_icmp.t +++ b/plugins-root/t/check_icmp.t | |||
@@ -11,11 +11,12 @@ my $allow_sudo = getTestParameter( "NP_ALLOW_SUDO", | |||
11 | "If sudo is setup for this user to run any command as root ('yes' to allow)", | 11 | "If sudo is setup for this user to run any command as root ('yes' to allow)", |
12 | "no" ); | 12 | "no" ); |
13 | 13 | ||
14 | if ($allow_sudo eq "yes") { | 14 | if ($allow_sudo eq "yes" or $> == 0) { |
15 | plan tests => 16; | 15 | plan tests => 16; |
16 | } else { | 16 | } else { |
17 | plan skip_all => "Need sudo to test check_icmp"; | 17 | plan skip_all => "Need sudo to test check_icmp"; |
18 | } | 18 | } |
19 | my $sudo = $> == 0 ? '' : 'sudo'; | ||
19 | 20 | ||
20 | my $successOutput = '/OK - .*?: rta (?:[\d\.]+ms)|(?:nan), lost \d+%/'; | 21 | my $successOutput = '/OK - .*?: rta (?:[\d\.]+ms)|(?:nan), lost \d+%/'; |
21 | my $failureOutput = '/(WARNING|CRITICAL) - .*?: rta [\d\.]+ms, lost \d%/'; | 22 | my $failureOutput = '/(WARNING|CRITICAL) - .*?: rta [\d\.]+ms, lost \d%/'; |
@@ -35,49 +36,49 @@ my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | |||
35 | my $res; | 36 | my $res; |
36 | 37 | ||
37 | $res = NPTest->testCmd( | 38 | $res = NPTest->testCmd( |
38 | "sudo ./check_icmp -H $host_responsive -w 10000ms,100% -c 10000ms,100%" | 39 | "$sudo ./check_icmp -H $host_responsive -w 10000ms,100% -c 10000ms,100%" |
39 | ); | 40 | ); |
40 | is( $res->return_code, 0, "Syntax ok" ); | 41 | is( $res->return_code, 0, "Syntax ok" ); |
41 | like( $res->output, $successOutput, "Output OK" ); | 42 | like( $res->output, $successOutput, "Output OK" ); |
42 | 43 | ||
43 | $res = NPTest->testCmd( | 44 | $res = NPTest->testCmd( |
44 | "sudo ./check_icmp -H $host_responsive -w 0ms,0% -c 10000ms,100%" | 45 | "$sudo ./check_icmp -H $host_responsive -w 0ms,0% -c 10000ms,100%" |
45 | ); | 46 | ); |
46 | is( $res->return_code, 1, "Syntax ok, with forced warning" ); | 47 | is( $res->return_code, 1, "Syntax ok, with forced warning" ); |
47 | like( $res->output, $failureOutput, "Output OK" ); | 48 | like( $res->output, $failureOutput, "Output OK" ); |
48 | 49 | ||
49 | $res = NPTest->testCmd( | 50 | $res = NPTest->testCmd( |
50 | "sudo ./check_icmp -H $host_responsive -w 0,0% -c 0,0%" | 51 | "$sudo ./check_icmp -H $host_responsive -w 0,0% -c 0,0%" |
51 | ); | 52 | ); |
52 | is( $res->return_code, 2, "Syntax ok, with forced critical" ); | 53 | is( $res->return_code, 2, "Syntax ok, with forced critical" ); |
53 | like( $res->output, $failureOutput, "Output OK" ); | 54 | like( $res->output, $failureOutput, "Output OK" ); |
54 | 55 | ||
55 | $res = NPTest->testCmd( | 56 | $res = NPTest->testCmd( |
56 | "sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100%" | 57 | "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100%" |
57 | ); | 58 | ); |
58 | is( $res->return_code, 2, "Timeout - host nonresponsive" ); | 59 | is( $res->return_code, 2, "Timeout - host nonresponsive" ); |
59 | like( $res->output, '/100%/', "Error contains '100%' string (for 100% packet loss)" ); | 60 | like( $res->output, '/100%/', "Error contains '100%' string (for 100% packet loss)" ); |
60 | 61 | ||
61 | $res = NPTest->testCmd( | 62 | $res = NPTest->testCmd( |
62 | "sudo ./check_icmp -w 10000ms,100% -c 10000ms,100%" | 63 | "$sudo ./check_icmp -w 10000ms,100% -c 10000ms,100%" |
63 | ); | 64 | ); |
64 | is( $res->return_code, 3, "No hostname" ); | 65 | is( $res->return_code, 3, "No hostname" ); |
65 | like( $res->output, '/No hosts to check/', "Output with appropriate error message"); | 66 | like( $res->output, '/No hosts to check/', "Output with appropriate error message"); |
66 | 67 | ||
67 | $res = NPTest->testCmd( | 68 | $res = NPTest->testCmd( |
68 | "sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 0" | 69 | "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 0" |
69 | ); | 70 | ); |
70 | is( $res->return_code, 0, "One host nonresponsive - zero required" ); | 71 | is( $res->return_code, 0, "One host nonresponsive - zero required" ); |
71 | like( $res->output, $successOutput, "Output OK" ); | 72 | like( $res->output, $successOutput, "Output OK" ); |
72 | 73 | ||
73 | $res = NPTest->testCmd( | 74 | $res = NPTest->testCmd( |
74 | "sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 1" | 75 | "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 1" |
75 | ); | 76 | ); |
76 | is( $res->return_code, 0, "One of two host nonresponsive - one required" ); | 77 | is( $res->return_code, 0, "One of two host nonresponsive - one required" ); |
77 | like( $res->output, $successOutput, "Output OK" ); | 78 | like( $res->output, $successOutput, "Output OK" ); |
78 | 79 | ||
79 | $res = NPTest->testCmd( | 80 | $res = NPTest->testCmd( |
80 | "sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 2" | 81 | "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 2" |
81 | ); | 82 | ); |
82 | is( $res->return_code, 2, "One of two host nonresponsive - two required" ); | 83 | is( $res->return_code, 2, "One of two host nonresponsive - two required" ); |
83 | like( $res->output, $failureOutput, "Output OK" ); | 84 | like( $res->output, $failureOutput, "Output OK" ); |