summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
-rw-r--r--plugins/t/check_curl.t4
-rw-r--r--plugins/t/check_http.t4
-rw-r--r--plugins/t/check_swap.t65
3 files changed, 44 insertions, 29 deletions
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t
index eae98cc1..7a930a4e 100644
--- a/plugins/t/check_curl.t
+++ b/plugins/t/check_curl.t
@@ -205,9 +205,9 @@ SKIP: {
205 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); 205 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
206 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); 206 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' );
207 207
208 $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f curl" ); 208 $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" );
209 is( $res->return_code, 0, "Redirection based on location is okay"); 209 is( $res->return_code, 0, "Redirection based on location is okay");
210 210
211 $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); 211 $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" );
212 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); 212 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
213} 213}
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 1f2fbdfd..6ab4a5b6 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -166,10 +166,10 @@ SKIP: {
166 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); 166 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
167 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); 167 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' );
168 168
169 $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f follow" ); 169 $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" );
170 is( $res->return_code, 0, "Redirection based on location is okay"); 170 is( $res->return_code, 0, "Redirection based on location is okay");
171 171
172 $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); 172 $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" );
173 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); 173 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
174} 174}
175 175
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t
index 18780386..7e61b766 100644
--- a/plugins/t/check_swap.t
+++ b/plugins/t/check_swap.t
@@ -5,39 +5,54 @@
5# 5#
6 6
7use strict; 7use strict;
8use Test::More tests => 14; 8use warnings;
9use Test::More tests => 21;
9use NPTest; 10use NPTest;
10 11use JSON;
11my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
12my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
13my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
14 12
15my $result; 13my $result;
14my $outputFormat = '--output-format mp-test-json';
15my $output;
16my $message = '/^[0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
16 17
17$result = NPTest->testCmd( "./check_swap" ); # Always OK 18$result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK
18cmp_ok( $result->return_code, "==", 0, "Always OK" ); 19cmp_ok( $result->return_code, "==", 0, "Always OK" );
19like( $result->output, $successOutput, "Right output" ); 20$output = decode_json($result->output);
21is($output->{'state'}, "OK", "State was correct");
22like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
20 23
21$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free 24$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free
22cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); 25cmp_ok( $result->return_code, "==", 0, "Always OK" );
23like( $result->output, $successOutput, "Right output" ); 26$output = decode_json($result->output);
27is($output->{'state'}, "OK", "State was correct");
28like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
24 29
25$result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free 30$result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free
26cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); 31cmp_ok( $result->return_code, "==", 0, "Always OK" );
27like( $result->output, $successOutput, "Right output" ); 32$output = decode_json($result->output);
33is($output->{'state'}, "OK", "State was correct");
34like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
28 35
29$result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical) 36$result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical)
30cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); 37cmp_ok( $result->return_code, "==", 0, "Always OK" );
31like( $result->output, $failureOutput, "Right output" ); 38$output = decode_json($result->output);
39is($output->{'state'}, "CRITICAL", "State was correct");
40like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
32 41
33$result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) 42$result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn)
34cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); 43cmp_ok( $result->return_code, "==", 0, "Always OK" );
35like( $result->output, $warnOutput, "Right output" ); 44$output = decode_json($result->output);
45is($output->{'state'}, "WARNING", "State was correct");
46like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
36 47
37$result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn) 48$result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn)
38cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); 49cmp_ok( $result->return_code, "==", 0, "Always OK" );
39like( $result->output, $warnOutput, "Right output" ); 50$output = decode_json($result->output);
51is($output->{'state'}, "WARNING", "State was correct");
52like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
40 53
41$result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical) 54$result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical)
42cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); 55cmp_ok( $result->return_code, "==", 0, "Always OK" );
43like( $result->output, $failureOutput, "Right output" ); 56$output = decode_json($result->output);
57is($output->{'state'}, "CRITICAL", "State was correct");
58like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");