summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NPTest.pm4
-rw-r--r--plugins/t/check_swap.t35
2 files changed, 18 insertions, 21 deletions
diff --git a/NPTest.pm b/NPTest.pm
index 9b25ac3e..47773acc 100644
--- a/NPTest.pm
+++ b/NPTest.pm
@@ -15,6 +15,8 @@ use warnings;
15use Cwd; 15use Cwd;
16use File::Basename; 16use File::Basename;
17 17
18use JSON;
19
18use IO::File; 20use IO::File;
19use Data::Dumper; 21use Data::Dumper;
20 22
@@ -617,6 +619,8 @@ sub testCmd {
617 chomp $output; 619 chomp $output;
618 $object->output($output); 620 $object->output($output);
619 621
622 $object->{'mp_test_result'} = decode_json($output);
623
620 alarm(0); 624 alarm(0);
621 625
622 my ($pkg, $file, $line) = caller(0); 626 my ($pkg, $file, $line) = caller(0);
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t
index 7e61b766..68946f6d 100644
--- a/plugins/t/check_swap.t
+++ b/plugins/t/check_swap.t
@@ -17,42 +17,35 @@ my $message = '/^[0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
17 17
18$result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK 18$result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK
19cmp_ok( $result->return_code, "==", 0, "Always OK" ); 19cmp_ok( $result->return_code, "==", 0, "Always OK" );
20$output = decode_json($result->output); 20is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct");
21is($output->{'state'}, "OK", "State was correct"); 21like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");
22like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
23 22
24$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free 23$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free
25cmp_ok( $result->return_code, "==", 0, "Always OK" ); 24cmp_ok( $result->return_code, "==", 0, "Always OK" );
26$output = decode_json($result->output); 25is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct");
27is($output->{'state'}, "OK", "State was correct"); 26like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");
28like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
29 27
30$result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free 28$result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free
31cmp_ok( $result->return_code, "==", 0, "Always OK" ); 29cmp_ok( $result->return_code, "==", 0, "Always OK" );
32$output = decode_json($result->output); 30is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct");
33is($output->{'state'}, "OK", "State was correct"); 31like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");
34like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
35 32
36$result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical) 33$result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical)
37cmp_ok( $result->return_code, "==", 0, "Always OK" ); 34cmp_ok( $result->return_code, "==", 0, "Always OK" );
38$output = decode_json($result->output); 35is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct");
39is($output->{'state'}, "CRITICAL", "State was correct"); 36like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");
40like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
41 37
42$result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn) 38$result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn)
43cmp_ok( $result->return_code, "==", 0, "Always OK" ); 39cmp_ok( $result->return_code, "==", 0, "Always OK" );
44$output = decode_json($result->output); 40is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct");
45is($output->{'state'}, "WARNING", "State was correct"); 41like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");
46like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
47 42
48$result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn) 43$result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn)
49cmp_ok( $result->return_code, "==", 0, "Always OK" ); 44cmp_ok( $result->return_code, "==", 0, "Always OK" );
50$output = decode_json($result->output); 45is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct");
51is($output->{'state'}, "WARNING", "State was correct"); 46like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");
52like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
53 47
54$result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical) 48$result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical)
55cmp_ok( $result->return_code, "==", 0, "Always OK" ); 49cmp_ok( $result->return_code, "==", 0, "Always OK" );
56$output = decode_json($result->output); 50is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct");
57is($output->{'state'}, "CRITICAL", "State was correct"); 51like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");
58like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");