From 579db5a93071547f5484c1690b621a60b46b2e1e Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Mon, 27 Nov 2023 13:00:57 +0100 Subject: check_disk: fix ignore-missing in combination with includes (fixes #1963) Using --ignore-missing together with regex matching and ignore option lead to a wrong error message. ./check_disk -n -w 10% -c 5% -W 10% -r /dummy -i /dummy2 DISK UNKNOWN: Paths need to be selected before using -i/-I. Use -A to select all paths explicitly The use case here is a cluster with fail-over mounts. So it is a valid situation that the regex match does not find anything in addtition with a ignore which also does not exist. After this patch: ./check_disk -n -w 10% -c 5% -W 10% -r /dummy -i /dummy2 DISK OK - No disks were found for provided parameters| --- plugins/t/check_disk.t | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'plugins/t') diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index ca035ce7..bf8dd362 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t @@ -23,11 +23,11 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { plan skip_all => "Need 2 mountpoints to test"; } else { - plan tests => 88; + plan tests => 94; } -$result = NPTest->testCmd( - "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" +$result = NPTest->testCmd( + "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" ); cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); my $c = 0; @@ -103,8 +103,8 @@ is ($crit_percth_data, int((1-10/100)*$total_percth_data), "Wrong critical in pe # Check when order of mount points are reversed, that perf data remains same -$result = NPTest->testCmd( - "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid" +$result = NPTest->testCmd( + "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid" ); @_ = sort(split(/ /, $result->perf_output)); is_deeply( \@perf_data, \@_, "perf data for both filesystems same when reversed"); @@ -134,8 +134,8 @@ cmp_ok( $result->return_code, '==', 0, "Old syntax okay" ); $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); -$result = NPTest->testCmd( - "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" +$result = NPTest->testCmd( + "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" ); cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); like( $result->output, $failureOutput, "Right output" ); @@ -151,14 +151,14 @@ $result = NPTest->testCmd( ); cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); -$result = NPTest->testCmd( - "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" +$result = NPTest->testCmd( + "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" ); cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); my $all_disks = $result->output; $result = NPTest->testCmd( - "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" + "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" ); isnt( $result->output, $all_disks, "-e gives different output"); @@ -240,7 +240,7 @@ TODO: { cmp_ok( $result->return_code, '==', 3, "Invalid command line options" ); } -$result = NPTest->testCmd( +$result = NPTest->testCmd( "./check_disk -p $mountpoint_valid -w 10% -c 15%" ); cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); @@ -322,7 +322,7 @@ cmp_ok( $result->return_code, '==', 1, "grouping: exit warning if the sum of fre $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, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit"); -# grouping: exit unknown if group name is given after -p +# grouping: exit unknown if group name is given after -p $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -p $mountpoint_valid -g group -p $mountpoint2_valid" ); cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); @@ -355,17 +355,17 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo # ignore-missing: exit okay, when fs is not accessible $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); -like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK'); +like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /bob;.*$/', 'Output OK'); # ignore-missing: exit okay, when regex does not match $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); -like( $result->output, '/^DISK OK - No disks were found for provided parameters;.*$/', 'Output OK'); +like( $result->output, '/^DISK OK - No disks were found for provided parameters.*$/', 'Output OK'); # ignore-missing: exit okay, when fs with exact match (-E) is not found $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); -like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK'); +like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /etc;.*$/', 'Output OK'); # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); @@ -375,4 +375,19 @@ like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK'); # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); -like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); \ No newline at end of file +like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); + +# ignore-missing: exit okay, when checking one non-existing fs (path) and one ignored +$result = NPTest->testCmd( "./check_disk -n -w 0% -c 0% -r /dummy -i /dummy2"); +cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); +like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); + +# ignore-missing: exit okay, when regex match does not find anything +$result = NPTest->testCmd( "./check_disk -n -e -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); +cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); +like( $result->output, '/^DISK OK\|$/', 'Output OK'); + +# ignore-missing: exit okay, when regex match does not find anything +$result = NPTest->testCmd( "./check_disk -n -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); +cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); +like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); -- cgit v1.2.3-74-g34f1