diff options
author | Sven Nierlein <sven@consol.de> | 2023-11-27 12:00:57 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@consol.de> | 2023-11-27 12:04:10 (GMT) |
commit | 579db5a93071547f5484c1690b621a60b46b2e1e (patch) | |
tree | 63ae74bb66e65077ab0c1a0b32828c15cfb11eaf /plugins | |
parent | f59c51601122ceac7ef4571d1993a34728e76813 (diff) | |
download | monitoring-plugins-579db5a93071547f5484c1690b621a60b46b2e1e.tar.gz |
check_disk: fix ignore-missing in combination with includes (fixes #1963)refs/pull/1967/head
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|
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_disk.c | 4 | ||||
-rw-r--r-- | plugins/t/check_disk.t | 47 |
2 files changed, 33 insertions, 18 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index e9a9ddd..c6bba24 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -451,7 +451,7 @@ main (int argc, char **argv) | |||
451 | 451 | ||
452 | if (strcmp(output, "") == 0 && ! erronly) { | 452 | if (strcmp(output, "") == 0 && ! erronly) { |
453 | preamble = ""; | 453 | preamble = ""; |
454 | xasprintf (&output, " - No disks were found for provided parameters;"); | 454 | xasprintf (&output, " - No disks were found for provided parameters"); |
455 | } | 455 | } |
456 | 456 | ||
457 | printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf); | 457 | printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf); |
@@ -831,7 +831,7 @@ process_arguments (int argc, char **argv) | |||
831 | 831 | ||
832 | if (!fnd && ignore_missing == true) { | 832 | if (!fnd && ignore_missing == true) { |
833 | path_ignored = true; | 833 | path_ignored = true; |
834 | /* path_selected = true;*/ | 834 | path_selected = true; |
835 | break; | 835 | break; |
836 | } else if (!fnd) | 836 | } else if (!fnd) |
837 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), | 837 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), |
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index ca035ce..bf8dd36 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 | |||
23 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { | 23 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { |
24 | plan skip_all => "Need 2 mountpoints to test"; | 24 | plan skip_all => "Need 2 mountpoints to test"; |
25 | } else { | 25 | } else { |
26 | plan tests => 88; | 26 | plan tests => 94; |
27 | } | 27 | } |
28 | 28 | ||
29 | $result = NPTest->testCmd( | 29 | $result = NPTest->testCmd( |
30 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" | 30 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" |
31 | ); | 31 | ); |
32 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); | 32 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); |
33 | my $c = 0; | 33 | my $c = 0; |
@@ -103,8 +103,8 @@ is ($crit_percth_data, int((1-10/100)*$total_percth_data), "Wrong critical in pe | |||
103 | 103 | ||
104 | 104 | ||
105 | # Check when order of mount points are reversed, that perf data remains same | 105 | # Check when order of mount points are reversed, that perf data remains same |
106 | $result = NPTest->testCmd( | 106 | $result = NPTest->testCmd( |
107 | "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid" | 107 | "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid" |
108 | ); | 108 | ); |
109 | @_ = sort(split(/ /, $result->perf_output)); | 109 | @_ = sort(split(/ /, $result->perf_output)); |
110 | is_deeply( \@perf_data, \@_, "perf data for both filesystems same when reversed"); | 110 | 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" ); | |||
134 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); | 134 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); |
135 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); | 135 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); |
136 | 136 | ||
137 | $result = NPTest->testCmd( | 137 | $result = NPTest->testCmd( |
138 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" | 138 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" |
139 | ); | 139 | ); |
140 | cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); | 140 | cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); |
141 | like( $result->output, $failureOutput, "Right output" ); | 141 | like( $result->output, $failureOutput, "Right output" ); |
@@ -151,14 +151,14 @@ $result = NPTest->testCmd( | |||
151 | ); | 151 | ); |
152 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); | 152 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); |
153 | 153 | ||
154 | $result = NPTest->testCmd( | 154 | $result = NPTest->testCmd( |
155 | "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 155 | "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" |
156 | ); | 156 | ); |
157 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); | 157 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); |
158 | my $all_disks = $result->output; | 158 | my $all_disks = $result->output; |
159 | 159 | ||
160 | $result = NPTest->testCmd( | 160 | $result = NPTest->testCmd( |
161 | "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 161 | "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" |
162 | ); | 162 | ); |
163 | isnt( $result->output, $all_disks, "-e gives different output"); | 163 | isnt( $result->output, $all_disks, "-e gives different output"); |
164 | 164 | ||
@@ -240,7 +240,7 @@ TODO: { | |||
240 | cmp_ok( $result->return_code, '==', 3, "Invalid command line options" ); | 240 | cmp_ok( $result->return_code, '==', 3, "Invalid command line options" ); |
241 | } | 241 | } |
242 | 242 | ||
243 | $result = NPTest->testCmd( | 243 | $result = NPTest->testCmd( |
244 | "./check_disk -p $mountpoint_valid -w 10% -c 15%" | 244 | "./check_disk -p $mountpoint_valid -w 10% -c 15%" |
245 | ); | 245 | ); |
246 | cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); | 246 | 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 | |||
322 | $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" ); | 322 | $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" ); |
323 | cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit"); | 323 | cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit"); |
324 | 324 | ||
325 | # grouping: exit unknown if group name is given after -p | 325 | # grouping: exit unknown if group name is given after -p |
326 | $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" ); | 326 | $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" ); |
327 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); | 327 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); |
328 | 328 | ||
@@ -355,17 +355,17 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo | |||
355 | # ignore-missing: exit okay, when fs is not accessible | 355 | # ignore-missing: exit okay, when fs is not accessible |
356 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); | 356 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); |
357 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); | 357 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); |
358 | like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK'); | 358 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /bob;.*$/', 'Output OK'); |
359 | 359 | ||
360 | # ignore-missing: exit okay, when regex does not match | 360 | # ignore-missing: exit okay, when regex does not match |
361 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); | 361 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); |
362 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 362 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
363 | like( $result->output, '/^DISK OK - No disks were found for provided parameters;.*$/', 'Output OK'); | 363 | like( $result->output, '/^DISK OK - No disks were found for provided parameters.*$/', 'Output OK'); |
364 | 364 | ||
365 | # ignore-missing: exit okay, when fs with exact match (-E) is not found | 365 | # ignore-missing: exit okay, when fs with exact match (-E) is not found |
366 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); | 366 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); |
367 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); | 367 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); |
368 | like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK'); | 368 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /etc;.*$/', 'Output OK'); |
369 | 369 | ||
370 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) | 370 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) |
371 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); | 371 | $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'); | |||
375 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) | 375 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) |
376 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); | 376 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); |
377 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 377 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
378 | like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); \ No newline at end of file | 378 | like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); |
379 | |||
380 | # ignore-missing: exit okay, when checking one non-existing fs (path) and one ignored | ||
381 | $result = NPTest->testCmd( "./check_disk -n -w 0% -c 0% -r /dummy -i /dummy2"); | ||
382 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
383 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | ||
384 | |||
385 | # ignore-missing: exit okay, when regex match does not find anything | ||
386 | $result = NPTest->testCmd( "./check_disk -n -e -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | ||
387 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
388 | like( $result->output, '/^DISK OK\|$/', 'Output OK'); | ||
389 | |||
390 | # ignore-missing: exit okay, when regex match does not find anything | ||
391 | $result = NPTest->testCmd( "./check_disk -n -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | ||
392 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
393 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | ||