summaryrefslogtreecommitdiffstats
path: root/plugins-root/t/check_icmp.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-root/t/check_icmp.t')
-rw-r--r--plugins-root/t/check_icmp.t19
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
14if ($allow_sudo eq "yes") { 14if ($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}
19my $sudo = $> == 0 ? '' : 'sudo';
19 20
20my $successOutput = '/OK - .*?: rta (?:[\d\.]+ms)|(?:nan), lost \d+%/'; 21my $successOutput = '/OK - .*?: rta (?:[\d\.]+ms)|(?:nan), lost \d+%/';
21my $failureOutput = '/(WARNING|CRITICAL) - .*?: rta [\d\.]+ms, lost \d%/'; 22my $failureOutput = '/(WARNING|CRITICAL) - .*?: rta [\d\.]+ms, lost \d%/';
@@ -35,49 +36,49 @@ my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
35my $res; 36my $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 );
40is( $res->return_code, 0, "Syntax ok" ); 41is( $res->return_code, 0, "Syntax ok" );
41like( $res->output, $successOutput, "Output OK" ); 42like( $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 );
46is( $res->return_code, 1, "Syntax ok, with forced warning" ); 47is( $res->return_code, 1, "Syntax ok, with forced warning" );
47like( $res->output, $failureOutput, "Output OK" ); 48like( $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 );
52is( $res->return_code, 2, "Syntax ok, with forced critical" ); 53is( $res->return_code, 2, "Syntax ok, with forced critical" );
53like( $res->output, $failureOutput, "Output OK" ); 54like( $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 );
58is( $res->return_code, 2, "Timeout - host nonresponsive" ); 59is( $res->return_code, 2, "Timeout - host nonresponsive" );
59like( $res->output, '/100%/', "Error contains '100%' string (for 100% packet loss)" ); 60like( $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 );
64is( $res->return_code, 3, "No hostname" ); 65is( $res->return_code, 3, "No hostname" );
65like( $res->output, '/No hosts to check/', "Output with appropriate error message"); 66like( $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 );
70is( $res->return_code, 0, "One host nonresponsive - zero required" ); 71is( $res->return_code, 0, "One host nonresponsive - zero required" );
71like( $res->output, $successOutput, "Output OK" ); 72like( $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 );
76is( $res->return_code, 0, "One of two host nonresponsive - one required" ); 77is( $res->return_code, 0, "One of two host nonresponsive - one required" );
77like( $res->output, $successOutput, "Output OK" ); 78like( $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 );
82is( $res->return_code, 2, "One of two host nonresponsive - two required" ); 83is( $res->return_code, 2, "One of two host nonresponsive - two required" );
83like( $res->output, $failureOutput, "Output OK" ); 84like( $res->output, $failureOutput, "Output OK" );