diff options
Diffstat (limited to 'plugins/t')
-rw-r--r-- | plugins/t/check_curl.t | 4 | ||||
-rw-r--r-- | plugins/t/check_http.t | 4 | ||||
-rw-r--r-- | plugins/t/check_swap.t | 65 |
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 | ||
7 | use strict; | 7 | use strict; |
8 | use Test::More tests => 14; | 8 | use warnings; |
9 | use Test::More tests => 21; | ||
9 | use NPTest; | 10 | use NPTest; |
10 | 11 | use JSON; | |
11 | my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; | ||
12 | my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; | ||
13 | my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; | ||
14 | 12 | ||
15 | my $result; | 13 | my $result; |
14 | my $outputFormat = '--output-format mp-test-json'; | ||
15 | my $output; | ||
16 | my $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 |
18 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 19 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
19 | like( $result->output, $successOutput, "Right output" ); | 20 | $output = decode_json($result->output); |
21 | is($output->{'state'}, "OK", "State was correct"); | ||
22 | like($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 |
22 | cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); | 25 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
23 | like( $result->output, $successOutput, "Right output" ); | 26 | $output = decode_json($result->output); |
27 | is($output->{'state'}, "OK", "State was correct"); | ||
28 | like($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 |
26 | cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); | 31 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
27 | like( $result->output, $successOutput, "Right output" ); | 32 | $output = decode_json($result->output); |
33 | is($output->{'state'}, "OK", "State was correct"); | ||
34 | like($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) |
30 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); | 37 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
31 | like( $result->output, $failureOutput, "Right output" ); | 38 | $output = decode_json($result->output); |
39 | is($output->{'state'}, "CRITICAL", "State was correct"); | ||
40 | like($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) |
34 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | 43 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
35 | like( $result->output, $warnOutput, "Right output" ); | 44 | $output = decode_json($result->output); |
45 | is($output->{'state'}, "WARNING", "State was correct"); | ||
46 | like($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) |
38 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | 49 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
39 | like( $result->output, $warnOutput, "Right output" ); | 50 | $output = decode_json($result->output); |
51 | is($output->{'state'}, "WARNING", "State was correct"); | ||
52 | like($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) |
42 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); | 55 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
43 | like( $result->output, $failureOutput, "Right output" ); | 56 | $output = decode_json($result->output); |
57 | is($output->{'state'}, "CRITICAL", "State was correct"); | ||
58 | like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||