diff options
Diffstat (limited to 'plugins/t/check_disk.t')
| -rw-r--r-- | plugins/t/check_disk.t | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index ca035ce7..9eb77ce4 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; |
| @@ -44,7 +44,7 @@ my @perf_data = sort(split(/ /, $result->perf_output)); | |||
| 44 | # Calculate avg_free free on mountpoint1 and mountpoint2 | 44 | # Calculate avg_free free on mountpoint1 and mountpoint2 |
| 45 | # because if you check in the middle, you should get different errors | 45 | # because if you check in the middle, you should get different errors |
| 46 | $_ = $result->output; | 46 | $_ = $result->output; |
| 47 | my ($free_on_mp1, $free_on_mp2) = (m/\((\d+)%.*\((\d+)%/); | 47 | my ($free_on_mp1, $free_on_mp2) = (m/\((\d+\.\d+)%.*\((\d+\.\d+)%/); |
| 48 | die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2); | 48 | die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2); |
| 49 | my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2); | 49 | my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2); |
| 50 | my ($more_free, $less_free); | 50 | my ($more_free, $less_free); |
| @@ -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"); |
| @@ -119,8 +119,12 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text"); | |||
| 119 | 119 | ||
| 120 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); | 120 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); |
| 121 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); | 121 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); |
| 122 | |||
| 122 | $_ = $result->output; | 123 | $_ = $result->output; |
| 124 | |||
| 123 | my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); | 125 | my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); |
| 126 | die "Cannot parse output: $_" unless ($free_mb_on_mp1 && $free_mb_on_mp2); | ||
| 127 | |||
| 124 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; | 128 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; |
| 125 | 129 | ||
| 126 | 130 | ||
| @@ -134,8 +138,8 @@ cmp_ok( $result->return_code, '==', 0, "Old syntax okay" ); | |||
| 134 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); | 138 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); |
| 135 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); | 139 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); |
| 136 | 140 | ||
| 137 | $result = NPTest->testCmd( | 141 | $result = NPTest->testCmd( |
| 138 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" | 142 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" |
| 139 | ); | 143 | ); |
| 140 | cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); | 144 | cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); |
| 141 | like( $result->output, $failureOutput, "Right output" ); | 145 | like( $result->output, $failureOutput, "Right output" ); |
| @@ -151,14 +155,14 @@ $result = NPTest->testCmd( | |||
| 151 | ); | 155 | ); |
| 152 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); | 156 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); |
| 153 | 157 | ||
| 154 | $result = NPTest->testCmd( | 158 | $result = NPTest->testCmd( |
| 155 | "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 159 | "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" |
| 156 | ); | 160 | ); |
| 157 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); | 161 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); |
| 158 | my $all_disks = $result->output; | 162 | my $all_disks = $result->output; |
| 159 | 163 | ||
| 160 | $result = NPTest->testCmd( | 164 | $result = NPTest->testCmd( |
| 161 | "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 165 | "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" |
| 162 | ); | 166 | ); |
| 163 | isnt( $result->output, $all_disks, "-e gives different output"); | 167 | isnt( $result->output, $all_disks, "-e gives different output"); |
| 164 | 168 | ||
| @@ -240,7 +244,7 @@ TODO: { | |||
| 240 | cmp_ok( $result->return_code, '==', 3, "Invalid command line options" ); | 244 | cmp_ok( $result->return_code, '==', 3, "Invalid command line options" ); |
| 241 | } | 245 | } |
| 242 | 246 | ||
| 243 | $result = NPTest->testCmd( | 247 | $result = NPTest->testCmd( |
| 244 | "./check_disk -p $mountpoint_valid -w 10% -c 15%" | 248 | "./check_disk -p $mountpoint_valid -w 10% -c 15%" |
| 245 | ); | 249 | ); |
| 246 | cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); | 250 | cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); |
| @@ -311,8 +315,8 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoi | |||
| 311 | like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given"); | 315 | like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given"); |
| 312 | 316 | ||
| 313 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit | 317 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit |
| 314 | $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" ); | 318 | $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" ); |
| 315 | cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit"); | 319 | 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); |
| 316 | 320 | ||
| 317 | # grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c | 321 | # grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c |
| 318 | $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" ); |
| @@ -322,7 +326,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" ); | 326 | $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"); | 327 | cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit"); |
| 324 | 328 | ||
| 325 | # grouping: exit unknown if group name is given after -p | 329 | # 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" ); | 330 | $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"); | 331 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); |
| 328 | 332 | ||
| @@ -355,17 +359,17 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo | |||
| 355 | # ignore-missing: exit okay, when fs is not accessible | 359 | # ignore-missing: exit okay, when fs is not accessible |
| 356 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); | 360 | $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"); | 361 | 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'); | 362 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /bob;.*$/', 'Output OK'); |
| 359 | 363 | ||
| 360 | # ignore-missing: exit okay, when regex does not match | 364 | # ignore-missing: exit okay, when regex does not match |
| 361 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); | 365 | $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"); | 366 | 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'); | 367 | like( $result->output, '/^DISK OK - No disks were found for provided parameters.*$/', 'Output OK'); |
| 364 | 368 | ||
| 365 | # ignore-missing: exit okay, when fs with exact match (-E) is not found | 369 | # 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"); | 370 | $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"); | 371 | 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'); | 372 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /etc;.*$/', 'Output OK'); |
| 369 | 373 | ||
| 370 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) | 374 | # 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 '^/\$'"); | 375 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); |
| @@ -375,4 +379,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) | 379 | # 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 '/'"); | 380 | $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"); | 381 | 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 | 382 | like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); |
| 383 | |||
| 384 | # ignore-missing: exit okay, when checking one non-existing fs (path) and one ignored | ||
| 385 | $result = NPTest->testCmd( "./check_disk -n -w 0% -c 0% -r /dummy -i /dummy2"); | ||
| 386 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
| 387 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | ||
| 388 | |||
| 389 | # ignore-missing: exit okay, when regex match does not find anything | ||
| 390 | $result = NPTest->testCmd( "./check_disk -n -e -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | ||
| 391 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
| 392 | like( $result->output, '/^DISK OK\|$/', 'Output OK'); | ||
| 393 | |||
| 394 | # ignore-missing: exit okay, when regex match does not find anything | ||
| 395 | $result = NPTest->testCmd( "./check_disk -n -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | ||
| 396 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
| 397 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | ||
