summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_disk.c4
-rw-r--r--plugins/t/check_disk.t47
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
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');