From d3faf13961c61b3ad69b47960124d3269c5f335e Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:36:41 +0100 Subject: check_disk: Fail on missing arguments for --warning and --critical and fix a test case (#1935) * check_disk: Fail on missing arguments for --warning and --critical * Add new test function for percentage expressions and use it in check_disk * Add error abort in tests if they fail to parse output * Fix typo in test which probably broke the test since forever :-( --- plugins/t/check_disk.t | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'plugins/t') diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index e0dd70eb..9eb77ce4 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t @@ -119,8 +119,12 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text"); $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); + $_ = $result->output; + my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); +die "Cannot parse output: $_" unless ($free_mb_on_mp1 && $free_mb_on_mp2); + my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; @@ -311,8 +315,8 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoi like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given"); # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit -$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ."-g group -p $mountpoint_valid -p $mountpoint2_valid" ); -cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit"); +$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); +cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit\nInstead received: " . $result->output); # grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all - 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); -- cgit v1.2.3-74-g34f1