summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-11-27 15:57:49 +0100
committerGitHub <noreply@github.com>2023-11-27 15:57:49 +0100
commitc2ddda30e043bb62b30ca5d25dba8379697b6340 (patch)
tree63ae74bb66e65077ab0c1a0b32828c15cfb11eaf /plugins
parentdf690d695763ebbfebb60e22656ddea6cecb6690 (diff)
parent579db5a93071547f5484c1690b621a60b46b2e1e (diff)
downloadmonitoring-plugins-c2ddda3.tar.gz
Merge pull request #1967 from sni/fix_check_disk
check_disk: fix ignore-missing in combination with includes (fixes #1963)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_disk.c15
-rw-r--r--plugins/t/check_disk.t47
2 files changed, 38 insertions, 24 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index a4180ca7..c6bba243 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -112,8 +112,7 @@ enum
112{ 112{
113 SYNC_OPTION = CHAR_MAX + 1, 113 SYNC_OPTION = CHAR_MAX + 1,
114 NO_SYNC_OPTION, 114 NO_SYNC_OPTION,
115 BLOCK_SIZE_OPTION, 115 BLOCK_SIZE_OPTION
116 IGNORE_MISSING
117}; 116};
118 117
119#ifdef _AIX 118#ifdef _AIX
@@ -452,7 +451,7 @@ main (int argc, char **argv)
452 451
453 if (strcmp(output, "") == 0 && ! erronly) { 452 if (strcmp(output, "") == 0 && ! erronly) {
454 preamble = ""; 453 preamble = "";
455 xasprintf (&output, " - No disks were found for provided parameters;"); 454 xasprintf (&output, " - No disks were found for provided parameters");
456 } 455 }
457 456
458 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);
@@ -524,7 +523,7 @@ process_arguments (int argc, char **argv)
524 {"ignore-ereg-partition", required_argument, 0, 'i'}, 523 {"ignore-ereg-partition", required_argument, 0, 'i'},
525 {"ignore-eregi-path", required_argument, 0, 'I'}, 524 {"ignore-eregi-path", required_argument, 0, 'I'},
526 {"ignore-eregi-partition", required_argument, 0, 'I'}, 525 {"ignore-eregi-partition", required_argument, 0, 'I'},
527 {"ignore-missing", no_argument, 0, IGNORE_MISSING}, 526 {"ignore-missing", no_argument, 0, 'n'},
528 {"local", no_argument, 0, 'l'}, 527 {"local", no_argument, 0, 'l'},
529 {"stat-remote-fs", no_argument, 0, 'L'}, 528 {"stat-remote-fs", no_argument, 0, 'L'},
530 {"iperfdata", no_argument, 0, 'P'}, 529 {"iperfdata", no_argument, 0, 'P'},
@@ -550,7 +549,7 @@ process_arguments (int argc, char **argv)
550 strcpy (argv[c], "-t"); 549 strcpy (argv[c], "-t");
551 550
552 while (1) { 551 while (1) {
553 c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEA", longopts, &option); 552 c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEAn", longopts, &option);
554 553
555 if (c == -1 || c == EOF) 554 if (c == -1 || c == EOF)
556 break; 555 break;
@@ -792,7 +791,7 @@ process_arguments (int argc, char **argv)
792 cflags = default_cflags; 791 cflags = default_cflags;
793 break; 792 break;
794 793
795 case IGNORE_MISSING: 794 case 'n':
796 ignore_missing = true; 795 ignore_missing = true;
797 break; 796 break;
798 case 'A': 797 case 'A':
@@ -832,7 +831,7 @@ process_arguments (int argc, char **argv)
832 831
833 if (!fnd && ignore_missing == true) { 832 if (!fnd && ignore_missing == true) {
834 path_ignored = true; 833 path_ignored = true;
835 /* path_selected = true;*/ 834 path_selected = true;
836 break; 835 break;
837 } else if (!fnd) 836 } else if (!fnd)
838 die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), 837 die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"),
@@ -1004,7 +1003,7 @@ print_help (void)
1004 printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)")); 1003 printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
1005 printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION"); 1004 printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION");
1006 printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)")); 1005 printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
1007 printf (" %s\n", "--ignore-missing"); 1006 printf (" %s\n", "-n, --ignore-missing");
1008 printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible.")); 1007 printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible."));
1009 printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)")); 1008 printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)"));
1010 printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 1009 printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
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
23if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { 23if ($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 );
32cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); 32cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)");
33my $c = 0; 33my $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));
110is_deeply( \@perf_data, \@_, "perf data for both filesystems same when reversed"); 110is_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" );
135cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); 135cmp_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 );
140cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); 140cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" );
141like( $result->output, $failureOutput, "Right output" ); 141like( $result->output, $failureOutput, "Right output" );
@@ -151,14 +151,14 @@ $result = NPTest->testCmd(
151 ); 151 );
152cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); 152cmp_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 );
157cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); 157cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning");
158my $all_disks = $result->output; 158my $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 );
163isnt( $result->output, $all_disks, "-e gives different output"); 163isnt( $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 );
246cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); 246cmp_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" );
323cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit"); 323cmp_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" );
327cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); 327cmp_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");
357cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); 357cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob");
358like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK'); 358like( $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");
362cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); 362cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
363like( $result->output, '/^DISK OK - No disks were found for provided parameters;.*$/', 'Output OK'); 363like( $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");
367cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); 367cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs");
368like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK'); 368like( $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 '/'");
377cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); 377cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
378like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); \ No newline at end of file 378like( $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");
382cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
383like( $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");
387cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
388like( $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");
392cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
393like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK');