summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-02-19 11:57:25 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-02-19 11:57:25 +0100
commitd27e0862a9e514149d81622a82622d31ab3bee9b (patch)
tree74f0bf9b9c6ed65dbd8b5d3130af36bf13d4b785 /plugins/t
parent6320a4e9534595d9c5f0d6d73e6858f548092a3e (diff)
downloadmonitoring-plugins-d27e0862a9e514149d81622a82622d31ab3bee9b.tar.gz
Fix previous check_swap tests
Diffstat (limited to 'plugins/t')
-rw-r--r--plugins/t/check_swap.t22
1 files changed, 12 insertions, 10 deletions
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t
index eaa81083..6ef2323d 100644
--- a/plugins/t/check_swap.t
+++ b/plugins/t/check_swap.t
@@ -5,39 +5,41 @@
5# 5#
6 6
7use strict; 7use strict;
8use warnings;
8use Test::More tests => 14; 9use Test::More tests => 14;
9use NPTest; 10use NPTest;
10 11
11my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; 12my $successOutput = '/^OK.* - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
12my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; 13my $failureOutput = '/^CRITICAL: .*- [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
13my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; 14my $warnOutput = '/^WARNING: .*- [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
14 15
16my $outputFormat = '--output-format one-line';
15my $result; 17my $result;
16 18
17$result = NPTest->testCmd( "./check_swap" ); # Always OK 19$result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK
18cmp_ok( $result->return_code, "==", 0, "Always OK" ); 20cmp_ok( $result->return_code, "==", 0, "Always OK" );
19like( $result->output, $successOutput, "Right output" ); 21like( $result->output, $successOutput, "Right output" );
20 22
21$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free 23$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free
22cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); 24cmp_ok( $result->return_code, "==", 0, "At least 1MB free" );
23like( $result->output, $successOutput, "Right output" ); 25like( $result->output, $successOutput, "Right output" );
24 26
25$result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free 27$result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free
26cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); 28cmp_ok( $result->return_code, "==", 0, 'At least 1% free' );
27like( $result->output, $successOutput, "Right output" ); 29like( $result->output, $successOutput, "Right output" );
28 30
29$result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical) 31$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' ); 32cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
31like( $result->output, $failureOutput, "Right output" ); 33like( $result->output, $failureOutput, "Right output" );
32 34
33$result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) 35$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' ); 36cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
35like( $result->output, $warnOutput, "Right output" ); 37like( $result->output, $warnOutput, "Right output" );
36 38
37$result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn) 39$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' ); 40cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
39like( $result->output, $warnOutput, "Right output" ); 41like( $result->output, $warnOutput, "Right output" );
40 42
41$result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical) 43$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' ); 44cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
43like( $result->output, $failureOutput, "Right output" ); 45like( $result->output, $failureOutput, "Right output" );