diff options
-rw-r--r-- | lib/utils_disk.c | 1 | ||||
-rw-r--r-- | lib/utils_disk.h | 1 | ||||
-rw-r--r-- | plugins/check_disk.c | 33 | ||||
-rw-r--r-- | plugins/t/check_disk.t | 73 |
4 files changed, 94 insertions, 14 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index fdbeaf1e..74708c0e 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
@@ -60,6 +60,7 @@ np_add_parameter(struct parameter_list **list, const char *name) | |||
60 | new_path->usedspace_units = NULL; | 60 | new_path->usedspace_units = NULL; |
61 | new_path->usedspace_percent = NULL; | 61 | new_path->usedspace_percent = NULL; |
62 | new_path->usedinodes_percent = NULL; | 62 | new_path->usedinodes_percent = NULL; |
63 | new_path->freeinodes_percent = NULL; | ||
63 | 64 | ||
64 | if (current == NULL) { | 65 | if (current == NULL) { |
65 | *list = new_path; | 66 | *list = new_path; |
diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 700f5d26..8bf4f113 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h | |||
@@ -19,6 +19,7 @@ struct parameter_list | |||
19 | thresholds *usedspace_units; | 19 | thresholds *usedspace_units; |
20 | thresholds *usedspace_percent; | 20 | thresholds *usedspace_percent; |
21 | thresholds *usedinodes_percent; | 21 | thresholds *usedinodes_percent; |
22 | thresholds *freeinodes_percent; | ||
22 | struct mount_entry *best_match; | 23 | struct mount_entry *best_match; |
23 | struct parameter_list *name_next; | 24 | struct parameter_list *name_next; |
24 | }; | 25 | }; |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 51e8e850..ac86f4d2 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -146,6 +146,8 @@ char *warn_usedspace_percent = NULL; | |||
146 | char *crit_usedspace_percent = NULL; | 146 | char *crit_usedspace_percent = NULL; |
147 | char *warn_usedinodes_percent = NULL; | 147 | char *warn_usedinodes_percent = NULL; |
148 | char *crit_usedinodes_percent = NULL; | 148 | char *crit_usedinodes_percent = NULL; |
149 | char *warn_freeinodes_percent = NULL; | ||
150 | char *crit_freeinodes_percent = NULL; | ||
149 | 151 | ||
150 | 152 | ||
151 | int | 153 | int |
@@ -197,6 +199,7 @@ main (int argc, char **argv) | |||
197 | set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units); | 199 | set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units); |
198 | set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent); | 200 | set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent); |
199 | set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent); | 201 | set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent); |
202 | set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent); | ||
200 | } | 203 | } |
201 | } else { | 204 | } else { |
202 | np_set_best_match(path_select_list, mount_list, exact_match); | 205 | np_set_best_match(path_select_list, mount_list, exact_match); |
@@ -261,8 +264,8 @@ main (int argc, char **argv) | |||
261 | dfree_inodes_percent = 100 - dused_inodes_percent; | 264 | dfree_inodes_percent = 100 - dused_inodes_percent; |
262 | 265 | ||
263 | if (verbose >= 3) { | 266 | if (verbose >= 3) { |
264 | printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g\n", | 267 | 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", |
265 | me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent); | 268 | me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent); |
266 | } | 269 | } |
267 | 270 | ||
268 | /* Threshold comparisons */ | 271 | /* Threshold comparisons */ |
@@ -287,6 +290,10 @@ main (int argc, char **argv) | |||
287 | if (verbose >=3) printf("Usedinodes_percent result=%d\n", temp_result); | 290 | if (verbose >=3) printf("Usedinodes_percent result=%d\n", temp_result); |
288 | disk_result = max_state( disk_result, temp_result ); | 291 | disk_result = max_state( disk_result, temp_result ); |
289 | 292 | ||
293 | temp_result = get_status(dfree_inodes_percent, path->freeinodes_percent); | ||
294 | if (verbose >=3) printf("Freeinodes_percent result=%d\n", temp_result); | ||
295 | disk_result = max_state( disk_result, temp_result ); | ||
296 | |||
290 | result = max_state(result, disk_result); | 297 | result = max_state(result, disk_result); |
291 | 298 | ||
292 | /* What a mess of units. The output shows free space, the perf data shows used space. Yikes! | 299 | /* What a mess of units. The output shows free space, the perf data shows used space. Yikes! |
@@ -309,8 +316,8 @@ main (int argc, char **argv) | |||
309 | asprintf (&perf, "%s %s", perf, | 316 | asprintf (&perf, "%s %s", perf, |
310 | perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 317 | perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
311 | dused_units, units, | 318 | dused_units, units, |
312 | TRUE, warning_high_tide, | 319 | (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, |
313 | TRUE, critical_high_tide, | 320 | (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, |
314 | TRUE, 0, | 321 | TRUE, 0, |
315 | TRUE, dtotal_units)); | 322 | TRUE, dtotal_units)); |
316 | 323 | ||
@@ -477,10 +484,18 @@ process_arguments (int argc, char **argv) | |||
477 | break; | 484 | break; |
478 | 485 | ||
479 | case 'W': /* warning inode threshold */ | 486 | case 'W': /* warning inode threshold */ |
480 | warn_usedinodes_percent = optarg; | 487 | if (*optarg == '@') { |
488 | warn_freeinodes_percent = optarg; | ||
489 | } else { | ||
490 | asprintf(&warn_freeinodes_percent, "@%s", optarg); | ||
491 | } | ||
481 | break; | 492 | break; |
482 | case 'K': /* critical inode threshold */ | 493 | case 'K': /* critical inode threshold */ |
483 | crit_usedinodes_percent = optarg; | 494 | if (*optarg == '@') { |
495 | crit_freeinodes_percent = optarg; | ||
496 | } else { | ||
497 | asprintf(&crit_freeinodes_percent, "@%s", optarg); | ||
498 | } | ||
484 | break; | 499 | break; |
485 | case 'u': | 500 | case 'u': |
486 | if (units) | 501 | if (units) |
@@ -525,7 +540,7 @@ process_arguments (int argc, char **argv) | |||
525 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || | 540 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || |
526 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || | 541 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || |
527 | warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent || | 542 | warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent || |
528 | crit_usedinodes_percent)) { | 543 | crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) { |
529 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n")); | 544 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n")); |
530 | } | 545 | } |
531 | se = np_add_parameter(&path_select_list, optarg); | 546 | se = np_add_parameter(&path_select_list, optarg); |
@@ -534,6 +549,7 @@ process_arguments (int argc, char **argv) | |||
534 | set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units); | 549 | set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units); |
535 | set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent); | 550 | set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent); |
536 | set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent); | 551 | set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent); |
552 | set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent); | ||
537 | break; | 553 | break; |
538 | case 'x': /* exclude path or partition */ | 554 | case 'x': /* exclude path or partition */ |
539 | np_add_name(&dp_exclude_list, optarg); | 555 | np_add_name(&dp_exclude_list, optarg); |
@@ -567,6 +583,8 @@ process_arguments (int argc, char **argv) | |||
567 | crit_usedspace_percent = NULL; | 583 | crit_usedspace_percent = NULL; |
568 | warn_usedinodes_percent = NULL; | 584 | warn_usedinodes_percent = NULL; |
569 | crit_usedinodes_percent = NULL; | 585 | crit_usedinodes_percent = NULL; |
586 | warn_freeinodes_percent = NULL; | ||
587 | crit_freeinodes_percent = NULL; | ||
570 | break; | 588 | break; |
571 | case 'V': /* version */ | 589 | case 'V': /* version */ |
572 | print_revision (progname, revision); | 590 | print_revision (progname, revision); |
@@ -594,6 +612,7 @@ process_arguments (int argc, char **argv) | |||
594 | set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units); | 612 | set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units); |
595 | set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent); | 613 | set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent); |
596 | set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent); | 614 | set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent); |
615 | set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent); | ||
597 | } | 616 | } |
598 | 617 | ||
599 | if (units == NULL) { | 618 | if (units == NULL) { |
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index e8e35b9f..dd4fcee4 100644 --- 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 | |||
24 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { | 24 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { |
25 | plan skip_all => "Need 2 mountpoints to test"; | 25 | plan skip_all => "Need 2 mountpoints to test"; |
26 | } else { | 26 | } else { |
27 | plan tests => 42; | 27 | plan tests => 56; |
28 | } | 28 | } |
29 | 29 | ||
30 | $result = NPTest->testCmd( | 30 | $result = NPTest->testCmd( |
31 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" | 31 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" |
32 | ); | 32 | ); |
33 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free)"); | 33 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); |
34 | my $c = 0; | 34 | my $c = 0; |
35 | $_ = $result->output; | 35 | $_ = $result->output; |
36 | $c++ while /\(/g; # counts number of "(" - should be two | 36 | $c++ while /\(/g; # counts number of "(" - should be two |
@@ -54,6 +54,26 @@ if ($free_on_mp1 > $free_on_mp2) { | |||
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | # Do same for inodes | ||
58 | $_ = $result->output; | ||
59 | my ($free_inode_on_mp1, $free_inode_on_mp2) = (m/inode=(\d+)%.*inode=(\d+)%/); | ||
60 | die "Cannot parse free inodes: $_" unless ($free_inode_on_mp1 && $free_inode_on_mp2); | ||
61 | my $avg_inode_free = ceil(($free_inode_on_mp1 + $free_inode_on_mp2)/2); | ||
62 | my ($more_inode_free, $less_inode_free); | ||
63 | if ($free_inode_on_mp1 > $free_inode_on_mp2) { | ||
64 | $more_inode_free = $mountpoint_valid; | ||
65 | $less_inode_free = $mountpoint2_valid; | ||
66 | } elsif ($free_on_mp1 < $free_on_mp2) { | ||
67 | $more_inode_free = $mountpoint2_valid; | ||
68 | $less_inode_free = $mountpoint_valid; | ||
69 | } else { | ||
70 | die "Two mountpoints with same inodes free - cannot do rest of test"; | ||
71 | } | ||
72 | |||
73 | |||
74 | |||
75 | # Basic filesystem checks for sizes | ||
76 | |||
57 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free" ); | 77 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free" ); |
58 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free"); | 78 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free"); |
59 | like ( $result->output, $successOutput, "OK output" ); | 79 | like ( $result->output, $successOutput, "OK output" ); |
@@ -76,8 +96,6 @@ cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $le | |||
76 | like( $result->output, $failureOutput, "Right output" ); | 96 | like( $result->output, $failureOutput, "Right output" ); |
77 | 97 | ||
78 | 98 | ||
79 | |||
80 | |||
81 | $result = NPTest->testCmd( | 99 | $result = NPTest->testCmd( |
82 | "./check_disk -w $avg_free% -c 0% -p $less_free" | 100 | "./check_disk -w $avg_free% -c 0% -p $less_free" |
83 | ); | 101 | ); |
@@ -102,9 +120,6 @@ like( $result->output, qr/$less_free/, "Found problem $less_free"); | |||
102 | unlike( $result->only_output, qr/$more_free/, "Has ignored $more_free as not a problem"); | 120 | unlike( $result->only_output, qr/$more_free/, "Has ignored $more_free as not a problem"); |
103 | like( $result->perf_output, qr/$more_free/, "But $more_free is still in perf data"); | 121 | like( $result->perf_output, qr/$more_free/, "But $more_free is still in perf data"); |
104 | 122 | ||
105 | |||
106 | |||
107 | |||
108 | $result = NPTest->testCmd( | 123 | $result = NPTest->testCmd( |
109 | "./check_disk -w $avg_free% -c 0% -p $more_free" | 124 | "./check_disk -w $avg_free% -c 0% -p $more_free" |
110 | ); | 125 | ); |
@@ -126,6 +141,50 @@ cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make | |||
126 | 141 | ||
127 | 142 | ||
128 | 143 | ||
144 | # Basic inode checks for sizes | ||
145 | |||
146 | $result = NPTest->testCmd( "./check_disk --icritical 1% --iwarning 1% -p $more_inode_free" ); | ||
147 | is( $result->return_code, 0, "At least 1% free on inodes for both mountpoints"); | ||
148 | |||
149 | $result = NPTest->testCmd( "./check_disk -K 100% -W 100% -p $less_inode_free" ); | ||
150 | is( $result->return_code, 2, "Critical requesting 100% free inodes for both mountpoints"); | ||
151 | |||
152 | $result = NPTest->testCmd( "./check_disk --iwarning 1% --icritical 1% -p $more_inode_free -K 100% -W 100% -p $less_inode_free" ); | ||
153 | is( $result->return_code, 2, "Get critical on less_inode_free mountpoint $less_inode_free"); | ||
154 | |||
155 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $less_inode_free" ); | ||
156 | is( $result->return_code, 1, "Get warning on less_inode_free, when checking average"); | ||
157 | |||
158 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free "); | ||
159 | is( $result->return_code, 0, "Get ok on more_inode_free when checking average"); | ||
160 | |||
161 | $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" ); | ||
162 | is ($result->return_code, 1, "Combine above two tests, get warning"); | ||
163 | $all_disks = $result->output; | ||
164 | |||
165 | $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" ); | ||
166 | isnt( $result->output, $all_disks, "-e gives different output"); | ||
167 | like( $result->output, qr/$less_inode_free/, "Found problem $less_inode_free"); | ||
168 | unlike( $result->only_output, qr/$more_inode_free/, "Has ignored $more_inode_free as not a problem"); | ||
169 | like( $result->perf_output, qr/$more_inode_free/, "But $more_inode_free is still in perf data"); | ||
170 | |||
171 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $more_inode_free" ); | ||
172 | is( $result->return_code, 0, "Get ok on more_inode_free mountpoint, checking average"); | ||
173 | |||
174 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free" ); | ||
175 | is( $result->return_code, 2, "Get critical on less_inode_free, checking average"); | ||
176 | |||
177 | $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" ); | ||
178 | is( $result->return_code, 2, "Combining above two tests, get critical"); | ||
179 | |||
180 | $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" ); | ||
181 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); | ||
182 | |||
183 | |||
184 | |||
185 | |||
186 | |||
187 | |||
129 | TODO: { | 188 | TODO: { |
130 | local $TODO = "Invalid percent figures"; | 189 | local $TODO = "Invalid percent figures"; |
131 | $result = NPTest->testCmd( | 190 | $result = NPTest->testCmd( |