Imported Upstream version 1.4.8
This commit is contained in:
parent
6a280f6f24
commit
6dd54dd8e2
352 changed files with 42813 additions and 27251 deletions
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
# Disk Space Tests via check_disk
|
||||
#
|
||||
# $Id: check_disk.t,v 1.14 2006/10/18 12:12:11 tonvoon Exp $
|
||||
# $Id: check_disk.t,v 1.20 2007/03/30 09:00:06 psychotrahe Exp $
|
||||
#
|
||||
|
||||
# TODO: Add in tests for perf data. Need to beef up Nagios::Plugin::Performance to cater for max, min, etc
|
||||
|
@ -24,18 +24,24 @@ 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 => 42;
|
||||
plan tests => 68;
|
||||
}
|
||||
|
||||
$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)");
|
||||
cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)");
|
||||
my $c = 0;
|
||||
$_ = $result->output;
|
||||
$c++ while /\(/g; # counts number of "(" - should be two
|
||||
cmp_ok( $c, '==', 2, "Got two mountpoints in output");
|
||||
|
||||
|
||||
# Get perf data
|
||||
# Should use Nagios::Plugin
|
||||
my @perf_data = sort(split(/ /, $result->perf_output));
|
||||
|
||||
|
||||
# Calculate avg_free free on mountpoint1 and mountpoint2
|
||||
# because if you check in the middle, you should get different errors
|
||||
$_ = $result->output;
|
||||
|
@ -54,12 +60,67 @@ if ($free_on_mp1 > $free_on_mp2) {
|
|||
}
|
||||
|
||||
|
||||
# Do same for inodes
|
||||
$_ = $result->output;
|
||||
my ($free_inode_on_mp1, $free_inode_on_mp2) = (m/inode=(\d+)%.*inode=(\d+)%/);
|
||||
die "Cannot parse free inodes: $_" unless ($free_inode_on_mp1 && $free_inode_on_mp2);
|
||||
my $avg_inode_free = ceil(($free_inode_on_mp1 + $free_inode_on_mp2)/2);
|
||||
my ($more_inode_free, $less_inode_free);
|
||||
if ($free_inode_on_mp1 > $free_inode_on_mp2) {
|
||||
$more_inode_free = $mountpoint_valid;
|
||||
$less_inode_free = $mountpoint2_valid;
|
||||
} elsif ($free_inode_on_mp1 < $free_inode_on_mp2) {
|
||||
$more_inode_free = $mountpoint2_valid;
|
||||
$less_inode_free = $mountpoint_valid;
|
||||
} else {
|
||||
die "Two mountpoints with same inodes free - cannot do rest of test";
|
||||
}
|
||||
|
||||
# Verify performance data
|
||||
# First check absolute thresholds...
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w 20 -c 10 -p $mountpoint_valid"
|
||||
);
|
||||
$_ = $result->perf_output;
|
||||
my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/);
|
||||
is ($warn_absth_data, $total_absth_data - 20, "Wrong warning in perf data using absolute thresholds");
|
||||
is ($crit_absth_data, $total_absth_data - 10, "Wrong critical in perf data using absolute thresholds");
|
||||
|
||||
# Then check percent thresholds.
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w 20% -c 10% -p $mountpoint_valid"
|
||||
);
|
||||
$_ = $result->perf_output;
|
||||
my ($warn_percth_data, $crit_percth_data, $total_percth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/);
|
||||
is ($warn_percth_data, int((1-20/100)*$total_percth_data), "Wrong warning in perf data using percent thresholds");
|
||||
is ($crit_percth_data, int((1-10/100)*$total_percth_data), "Wrong critical in perf data using percent thresholds");
|
||||
|
||||
|
||||
# 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"
|
||||
);
|
||||
@_ = sort(split(/ /, $result->perf_output));
|
||||
is_deeply( \@perf_data, \@_, "perf data for both filesystems same when reversed");
|
||||
|
||||
|
||||
# Basic filesystem checks for sizes
|
||||
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free" );
|
||||
cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free");
|
||||
like ( $result->output, $successOutput, "OK output" );
|
||||
like ( $result->only_output, qr/free space/, "Have free space text");
|
||||
like ( $result->only_output, qr/$more_free/, "Have disk name in text");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" );
|
||||
cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free");
|
||||
$_ = $result->output;
|
||||
print $result->output."\n";
|
||||
my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g);
|
||||
my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
|
||||
print "$free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2\n";
|
||||
|
||||
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" );
|
||||
is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs");
|
||||
|
||||
|
@ -76,8 +137,6 @@ cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $le
|
|||
like( $result->output, $failureOutput, "Right output" );
|
||||
|
||||
|
||||
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w $avg_free% -c 0% -p $less_free"
|
||||
);
|
||||
|
@ -98,12 +157,11 @@ $result = NPTest->testCmd(
|
|||
"./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");
|
||||
like( $result->output, qr/$less_free/, "Found problem $less_free");
|
||||
unlike( $result->only_output, qr/$more_free/, "Has ignored $more_free as not a problem");
|
||||
like( $result->perf_output, qr/$more_free/, "But $more_free is still in perf data");
|
||||
|
||||
|
||||
|
||||
# Need spaces around filesystem name in case less_free and more_free are nested
|
||||
like( $result->output, qr/ $less_free /, "Found problem $less_free");
|
||||
unlike( $result->only_output, qr/ $more_free /, "Has ignored $more_free as not a problem");
|
||||
like( $result->perf_output, qr/ $more_free=/, "But $more_free is still in perf data");
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w $avg_free% -c 0% -p $more_free"
|
||||
|
@ -126,6 +184,50 @@ cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make
|
|||
|
||||
|
||||
|
||||
# Basic inode checks for sizes
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk --icritical 1% --iwarning 1% -p $more_inode_free" );
|
||||
is( $result->return_code, 0, "At least 1% free on inodes for both mountpoints");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -K 100% -W 100% -p $less_inode_free" );
|
||||
is( $result->return_code, 2, "Critical requesting 100% free inodes for both mountpoints");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk --iwarning 1% --icritical 1% -p $more_inode_free -K 100% -W 100% -p $less_inode_free" );
|
||||
is( $result->return_code, 2, "Get critical on less_inode_free mountpoint $less_inode_free");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $less_inode_free" );
|
||||
is( $result->return_code, 1, "Get warning on less_inode_free, when checking average");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free ");
|
||||
is( $result->return_code, 0, "Get ok on more_inode_free when checking average");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $less_inode_free -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free" );
|
||||
is ($result->return_code, 1, "Combine above two tests, get warning");
|
||||
$all_disks = $result->output;
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -e -W $avg_inode_free% -K 0% -p $less_inode_free -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free" );
|
||||
isnt( $result->output, $all_disks, "-e gives different output");
|
||||
like( $result->output, qr/$less_inode_free/, "Found problem $less_inode_free");
|
||||
unlike( $result->only_output, qr/$more_inode_free\s/, "Has ignored $more_inode_free as not a problem");
|
||||
like( $result->perf_output, qr/$more_inode_free/, "But $more_inode_free is still in perf data");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $more_inode_free" );
|
||||
is( $result->return_code, 0, "Get ok on more_inode_free mountpoint, checking average");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free" );
|
||||
is( $result->return_code, 2, "Get critical on less_inode_free, checking average");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $more_inode_free -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free" );
|
||||
is( $result->return_code, 2, "Combining above two tests, get critical");
|
||||
|
||||
$result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free -W $avg_inode_free% -K 0% -p $more_inode_free" );
|
||||
cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TODO: {
|
||||
local $TODO = "Invalid percent figures";
|
||||
$result = NPTest->testCmd(
|
||||
|
@ -192,3 +294,28 @@ unlike( $result->perf_output, '/\/bob/', "perf data does not have /bob in it");
|
|||
|
||||
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /" );
|
||||
unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice");
|
||||
|
||||
# are partitions added if -C is given without path selection -p ?
|
||||
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoint_valid" );
|
||||
like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given");
|
||||
|
||||
# grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit
|
||||
$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, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit");
|
||||
|
||||
# grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c
|
||||
$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, '==', 1, "grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c ");
|
||||
|
||||
# grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit
|
||||
$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
|
||||
$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");
|
||||
|
||||
# regex: exit unknown if given regex is not compileable
|
||||
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" );
|
||||
cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue