diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-02-21 14:33:24 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-21 14:33:24 +0100 | 
| commit | 75658bd04d84d037dbcc9fafd9f7860555ac4836 (patch) | |
| tree | 6b50ee39401c68a27757abac785c931bd82ae02d /plugins/t | |
| parent | b38dec3e9b45efa6a6631acc38ada853e69fc547 (diff) | |
| parent | 7c8c9d9b3e7bb6c29d82788d05d74e3f18f01aa5 (diff) | |
| download | monitoring-plugins-75658bd0.tar.gz | |
Merge pull request #2064 from RincewindsHat/feature/new_output_infra
Feature/new output infra
Diffstat (limited to 'plugins/t')
| -rw-r--r-- | plugins/t/check_swap.t | 65 | 
1 files changed, 40 insertions, 25 deletions
| diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index eaa81083..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]+MiB out of [0-9]+MiB\)/'; | ||
| 12 | my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | ||
| 13 | my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | ||
| 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"); | ||
