summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ff2e811)
raw | patch | inline | side by side (parent: ff2e811)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 20 Dec 2006 19:25:59 +0000 (19:25 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 20 Dec 2006 19:25:59 +0000 (19:25 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1554 f882894a-f735-0410-b71e-b25c423dba1c
lib/utils_disk.c | patch | blob | history | |
lib/utils_disk.h | patch | blob | history | |
plugins/check_disk.c | patch | blob | history | |
plugins/t/check_disk.t | patch | blob | history |
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index fdbeaf1e7c1220a5eb915737bd2d7fce39549ceb..74708c0e3a2807200c2c4c0829dc981b166396fe 100644 (file)
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
new_path->usedspace_units = NULL;
new_path->usedspace_percent = NULL;
new_path->usedinodes_percent = NULL;
+ new_path->freeinodes_percent = NULL;
if (current == NULL) {
*list = new_path;
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 700f5d26b4b5181553e4e01a74fecc84dccb3cfb..8bf4f113b989b02b9ec27cf63253fac8d66dd26d 100644 (file)
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
thresholds *usedspace_units;
thresholds *usedspace_percent;
thresholds *usedinodes_percent;
+ thresholds *freeinodes_percent;
struct mount_entry *best_match;
struct parameter_list *name_next;
};
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 51e8e850e53070cf165d2ac7252cb6c9af985358..ac86f4d2a195e77637a09c2a512ae013c8d7dfc9 100644 (file)
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
char *crit_usedspace_percent = NULL;
char *warn_usedinodes_percent = NULL;
char *crit_usedinodes_percent = NULL;
+char *warn_freeinodes_percent = NULL;
+char *crit_freeinodes_percent = NULL;
int
set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units);
set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
+ set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
}
} else {
np_set_best_match(path_select_list, mount_list, exact_match);
dfree_inodes_percent = 100 - dused_inodes_percent;
if (verbose >= 3) {
- printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g\n",
- me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent);
+ printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g\n",
+ me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent);
}
/* Threshold comparisons */
if (verbose >=3) printf("Usedinodes_percent result=%d\n", temp_result);
disk_result = max_state( disk_result, temp_result );
+ temp_result = get_status(dfree_inodes_percent, path->freeinodes_percent);
+ if (verbose >=3) printf("Freeinodes_percent result=%d\n", temp_result);
+ disk_result = max_state( disk_result, temp_result );
+
result = max_state(result, disk_result);
/* What a mess of units. The output shows free space, the perf data shows used space. Yikes!
asprintf (&perf, "%s %s", perf,
perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
dused_units, units,
- TRUE, warning_high_tide,
- TRUE, critical_high_tide,
+ (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide,
+ (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide,
TRUE, 0,
TRUE, dtotal_units));
break;
case 'W': /* warning inode threshold */
- warn_usedinodes_percent = optarg;
+ if (*optarg == '@') {
+ warn_freeinodes_percent = optarg;
+ } else {
+ asprintf(&warn_freeinodes_percent, "@%s", optarg);
+ }
break;
case 'K': /* critical inode threshold */
- crit_usedinodes_percent = optarg;
+ if (*optarg == '@') {
+ crit_freeinodes_percent = optarg;
+ } else {
+ asprintf(&crit_freeinodes_percent, "@%s", optarg);
+ }
break;
case 'u':
if (units)
if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent ||
- crit_usedinodes_percent)) {
+ crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
}
se = np_add_parameter(&path_select_list, optarg);
set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units);
set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
+ set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
break;
case 'x': /* exclude path or partition */
np_add_name(&dp_exclude_list, optarg);
crit_usedspace_percent = NULL;
warn_usedinodes_percent = NULL;
crit_usedinodes_percent = NULL;
+ warn_freeinodes_percent = NULL;
+ crit_freeinodes_percent = NULL;
break;
case 'V': /* version */
print_revision (progname, revision);
set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units);
set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
+ set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
}
if (units == NULL) {
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index e8e35b9fe62b1b0f7bfaade96de866d04f4ad7df..dd4fcee4789bcf8fd4e07298dcead560072b7751 100644 (file)
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -24,13 +24,13 @@ 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 => 56;
}
$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
}
+# 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_on_mp1 < $free_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";
+}
+
+
+
+# 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->output, $failureOutput, "Right output" );
-
-
$result = NPTest->testCmd(
"./check_disk -w $avg_free% -c 0% -p $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 +141,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/, "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(