summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-07-13 23:58:00 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2006-07-13 23:58:00 (GMT)
commit5912398b9723545ecd061650667cbb238be85743 (patch)
treee5d8353cc8d8c278bfc22bd926f613da63f5e83f /plugins
parent548083b2ea865474915fc8a9ddd361e997585a02 (diff)
downloadmonitoring-plugins-5912398b9723545ecd061650667cbb238be85743.tar.gz
Major fixes to check_disk. Now should return same data as df
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1452 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_disk.c329
-rw-r--r--plugins/t/check_disk.t51
2 files changed, 199 insertions, 181 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 6beaf86..b966fab 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -49,13 +49,14 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
49#include <stdarg.h> 49#include <stdarg.h>
50#include "fsusage.h" 50#include "fsusage.h"
51#include "mountlist.h" 51#include "mountlist.h"
52#include "intprops.h" /* necessary for TYPE_MAXIMUM */
52#if HAVE_LIMITS_H 53#if HAVE_LIMITS_H
53# include <limits.h> 54# include <limits.h>
54#endif 55#endif
55 56
56 57
57/* If nonzero, show inode information. */ 58/* If nonzero, show inode information. */
58static int inode_format; 59static int inode_format = 1;
59 60
60/* If nonzero, show even filesystems with zero size or 61/* If nonzero, show even filesystems with zero size or
61 uninteresting types. */ 62 uninteresting types. */
@@ -118,16 +119,11 @@ static struct mount_entry *mount_list;
118int process_arguments (int, char **); 119int process_arguments (int, char **);
119void print_path (const char *mypath); 120void print_path (const char *mypath);
120int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *); 121int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
121int check_disk (double usp, uintmax_t free_disk, double uisp);
122void print_help (void); 122void print_help (void);
123void print_usage (void); 123void print_usage (void);
124 124
125uintmax_t w_df = 0;
126uintmax_t c_df = 0;
127double w_dfp = -1.0; 125double w_dfp = -1.0;
128double c_dfp = -1.0; 126double c_dfp = -1.0;
129double w_idfp = -1.0;
130double c_idfp = -1.0;
131char *path; 127char *path;
132char *exclude_device; 128char *exclude_device;
133char *units; 129char *units;
@@ -136,20 +132,32 @@ int verbose = 0;
136int erronly = FALSE; 132int erronly = FALSE;
137int display_mntp = FALSE; 133int display_mntp = FALSE;
138int exact_match = FALSE; 134int exact_match = FALSE;
135char *warn_freespace_units = NULL;
136char *crit_freespace_units = NULL;
137char *warn_freespace_percent = NULL;
138char *crit_freespace_percent = NULL;
139char *warn_usedspace_units = NULL;
140char *crit_usedspace_units = NULL;
141char *warn_usedspace_percent = NULL;
142char *crit_usedspace_percent = NULL;
143char *warn_usedinodes_percent = NULL;
144char *crit_usedinodes_percent = NULL;
139 145
140 146
141int 147int
142main (int argc, char **argv) 148main (int argc, char **argv)
143{ 149{
144 double usp = -1.0, uisp = -1.0;
145 int result = STATE_UNKNOWN; 150 int result = STATE_UNKNOWN;
146 int disk_result = STATE_UNKNOWN; 151 int disk_result = STATE_UNKNOWN;
147 char file_system[MAX_INPUT_BUFFER];
148 char *output; 152 char *output;
149 char *details; 153 char *details;
150 char *perf; 154 char *perf;
151 uintmax_t psize; 155 float inode_space_pct;
152 float free_space, free_space_pct, total_space, inode_space_pct; 156 uintmax_t total, available, available_to_root, used;
157 double dfree_pct = -1, dused_pct = -1;
158 double dused_units, dfree_units, dtotal_units;
159 double dused_inodes_percent;
160 int temp_result;
153 161
154 struct mount_entry *me; 162 struct mount_entry *me;
155 struct fs_usage fsp; 163 struct fs_usage fsp;
@@ -175,13 +183,12 @@ main (int argc, char **argv)
175 if (! path_select_list) { 183 if (! path_select_list) {
176 for (me = mount_list; me; me = me->me_next) { 184 for (me = mount_list; me; me = me->me_next) {
177 path = np_add_parameter(&path_select_list, me->me_mountdir); 185 path = np_add_parameter(&path_select_list, me->me_mountdir);
178 path->w_df = w_df;
179 path->c_df = c_df;
180 path->w_dfp = w_dfp;
181 path->c_dfp = c_dfp;
182 path->w_idfp = w_idfp;
183 path->c_idfp = c_idfp;
184 path->best_match = me; 186 path->best_match = me;
187 set_thresholds(&path->freespace_units, warn_freespace_units, crit_freespace_units);
188 set_thresholds(&path->freespace_percent, warn_freespace_percent, crit_freespace_percent);
189 set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units);
190 set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
191 set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
185 } 192 }
186 } else { 193 } else {
187 np_set_best_match(path_select_list, mount_list, exact_match); 194 np_set_best_match(path_select_list, mount_list, exact_match);
@@ -199,12 +206,6 @@ main (int argc, char **argv)
199 /* Process for every path in list */ 206 /* Process for every path in list */
200 for (path = path_select_list; path; path=path->name_next) { 207 for (path = path_select_list; path; path=path->name_next) {
201 me = path->best_match; 208 me = path->best_match;
202 w_df = path->w_df;
203 c_df = path->c_df;
204 w_dfp = path->w_dfp;
205 c_dfp = path->c_dfp;
206 w_idfp = path->w_idfp;
207 c_idfp = path->c_idfp;
208 209
209 /* Filters */ 210 /* Filters */
210 211
@@ -233,13 +234,67 @@ main (int argc, char **argv)
233 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 234 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
234 235
235 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { 236 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
236 usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; 237 total = fsp.fsu_blocks;
237 uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files; 238 available = fsp.fsu_bavail;
238 disk_result = check_disk (usp, fsp.fsu_bavail, uisp); 239 available_to_root = fsp.fsu_bfree;
240 used = total - available_to_root;
241
242 /* I don't understand the below, but it is taken from coreutils' df */
243 /* Is setting dused_pct, in the best possible way */
244 if (used <= TYPE_MAXIMUM(uintmax_t) / 100) {
245 uintmax_t u100 = used * 100;
246 uintmax_t nonroot_total = used + available;
247 dused_pct = u100 / nonroot_total + (u100 % nonroot_total != 0);
248 } else {
249 /* Possible rounding errors - see coreutils' df for more explanation */
250 double u = used;
251 double a = available;
252 double nonroot_total = u + a;
253 if (nonroot_total) {
254 long int lipct = dused_pct = u * 100 / nonroot_total;
255 double ipct = lipct;
256
257 /* Like 'pct = ceil (dpct);', but without ceil - from coreutils again */
258 if (ipct - 1 < dused_pct && dused_pct <= ipct + 1)
259 dused_pct = ipct + (ipct < dused_pct);
260 }
261 }
262
263 dfree_pct = 100 - dused_pct;
264 dused_units = used*fsp.fsu_blocksize/mult;
265 dfree_units = available*fsp.fsu_blocksize/mult;
266 dtotal_units = total*fsp.fsu_blocksize/mult;
267 dused_inodes_percent = (fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files;
268
269 if (verbose >= 3) {
270 printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g\n",
271 me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent);
272 }
273
274 /* Threshold comparisons */
275
276 temp_result = get_status(dfree_units, path->freespace_units);
277 if (verbose >=3) printf("Freespace_units result=%d\n", temp_result);
278 result = max_state( result, temp_result );
239 279
280 temp_result = get_status(dfree_pct, path->freespace_percent);
281 if (verbose >=3) printf("Freespace%% result=%d\n", temp_result);
282 result = max_state( result, temp_result );
283
284 temp_result = get_status(dused_units, path->usedspace_units);
285 if (verbose >=3) printf("Usedspace_units result=%d\n", temp_result);
286 result = max_state( result, temp_result );
287
288 temp_result = get_status(dused_pct, path->usedspace_percent);
289 if (verbose >=3) printf("Usedspace_percent result=%d\n", temp_result);
290 result = max_state( result, temp_result );
291
292 temp_result = get_status(dused_inodes_percent, path->usedinodes_percent);
293 if (verbose >=3) printf("Usedinodes_percent result=%d\n", temp_result);
294 result = max_state( result, temp_result );
295
296
240 297
241 result = max_state (disk_result, result);
242 psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult;
243 298
244 299
245 /* Moved this computation up here so we can add it 300 /* Moved this computation up here so we can add it
@@ -248,33 +303,33 @@ main (int argc, char **argv)
248 303
249 304
250 asprintf (&perf, "%s %s", perf, 305 asprintf (&perf, "%s %s", perf,
251 perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 306 perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
252 psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units, 307 dused_units, units,
253 TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)), 308 FALSE, 0, /* min ((uintmax_t)dtotal_units-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*dtotal_units)), */
254 TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)), 309 FALSE, 0, /* min ((uintmax_t)dtotal_units-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*dtotal_units)), */
255 TRUE, inode_space_pct, 310 FALSE, 0, /* inode_space_pct, */
311 FALSE, 0));; /* dtotal_units)); */
256 312
257 TRUE, psize));
258 if (disk_result==STATE_OK && erronly && !verbose) 313 if (disk_result==STATE_OK && erronly && !verbose)
259 continue; 314 continue;
260 315
261 free_space = (float)fsp.fsu_bavail*fsp.fsu_blocksize/mult; 316 if (disk_result!=STATE_OK || verbose>=0) {
262 free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks;
263 total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult;
264 if (disk_result!=STATE_OK || verbose>=0)
265 asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"), 317 asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"),
266 output, 318 output,
267 (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 319 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
268 free_space, 320 dfree_units,
269 units, 321 units,
270 free_space_pct, 322 dfree_pct,
271 inode_space_pct); 323 inode_space_pct);
324 }
272 325
326 /* Need to do a similar one
273 asprintf (&details, _("%s\n\ 327 asprintf (&details, _("%s\n\
274%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), 328%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
275 details, free_space, total_space, units, free_space_pct, inode_space_pct, 329 details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct,
276 me->me_devname, me->me_type, me->me_mountdir, 330 me->me_devname, me->me_type, me->me_mountdir,
277 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); 331 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
332 */
278 333
279 } 334 }
280 335
@@ -299,14 +354,6 @@ process_arguments (int argc, char **argv)
299 struct parameter_list *temp_list; 354 struct parameter_list *temp_list;
300 int result = OK; 355 int result = OK;
301 struct stat *stat_buf; 356 struct stat *stat_buf;
302 char *warn_freespace = NULL;
303 char *crit_freespace = NULL;
304 char *warn_freespace_percent = NULL;
305 char *crit_freespace_percent = NULL;
306 char temp_string[MAX_INPUT_BUFFER];
307
308 unsigned long l;
309 double f;
310 357
311 int option = 0; 358 int option = 0;
312 static struct option longopts[] = { 359 static struct option longopts[] = {
@@ -359,65 +406,51 @@ process_arguments (int argc, char **argv)
359 else { 406 else {
360 usage2 (_("Timeout interval must be a positive integer"), optarg); 407 usage2 (_("Timeout interval must be a positive integer"), optarg);
361 } 408 }
409
410 /* See comments for 'c' */
362 case 'w': /* warning threshold */ 411 case 'w': /* warning threshold */
363 /*
364 if (strstr(optarg, "%")) { 412 if (strstr(optarg, "%")) {
365 printf("Got percent with optarg=%s\n", optarg); 413 if (*optarg == '@') {
366 warn_freespace_percent = optarg; 414 warn_freespace_percent = optarg;
415 } else {
416 asprintf(&warn_freespace_percent, "@%s", optarg);
417 }
367 } else { 418 } else {
368 warn_freespace = optarg; 419 if (*optarg == '@') {
420 warn_freespace_units = optarg;
421 } else {
422 asprintf(&warn_freespace_units, "@%s", optarg);
423 }
369 } 424 }
370 break; 425 break;
371 */ 426
372 if (is_intnonneg (optarg)) { 427 /* Awful mistake where the range values do not make sense. Normally,
373 w_df = atoi (optarg); 428 you alert if the value is within the range, but since we are using
374 break; 429 freespace, we have to alert if outside the range. Thus we artifically
375 } 430 force @ at the beginning of the range, so that it is backwards compatible
376 else if (strpbrk (optarg, ",:") && 431 */
377 strstr (optarg, "%") &&
378 sscanf (optarg, "%lu%*[:,]%lf%%", &l, &w_dfp) == 2) {
379 w_df = (uintmax_t)l;
380 break;
381 }
382 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) {
383 break;
384 }
385 else {
386 usage4 (_("Warning threshold must be integer or percentage!"));
387 }
388 case 'c': /* critical threshold */ 432 case 'c': /* critical threshold */
389 if (is_intnonneg (optarg)) { 433 if (strstr(optarg, "%")) {
390 c_df = atoi (optarg); 434 if (*optarg == '@') {
391 break; 435 crit_freespace_percent = optarg;
392 } 436 } else {
393 else if (strpbrk (optarg, ",:") && 437 asprintf(&crit_freespace_percent, "@%s", optarg);
394 strstr (optarg, "%") && 438 }
395 sscanf (optarg, "%lu%*[,:]%lf%%", &l, &c_dfp) == 2) { 439 } else {
396 c_df = (uintmax_t)l; 440 if (*optarg == '@') {
397 break; 441 crit_freespace_units = optarg;
398 } 442 } else {
399 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) { 443 asprintf(&crit_freespace_units, "@%s", optarg);
400 break; 444 }
401 }
402 else {
403 usage4 (_("Critical threshold must be integer or percentage!"));
404 } 445 }
446 break;
405 447
406 448 case 'W': /* warning inode threshold */
407 case 'W': /* warning inode threshold */ 449 warn_usedinodes_percent = optarg;
408 if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_idfp) == 1) { 450 break;
409 break; 451 case 'K': /* critical inode threshold */
410 } 452 crit_usedinodes_percent = optarg;
411 else { 453 break;
412 usage (_("Warning inode threshold must be percentage!\n"));
413 }
414 case 'K': /* kritical inode threshold */
415 if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) {
416 break;
417 }
418 else {
419 usage (_("Critical inode threshold must be percentage!\n"));
420 }
421 case 'u': 454 case 'u':
422 if (units) 455 if (units)
423 free(units); 456 free(units);
@@ -458,13 +491,18 @@ process_arguments (int argc, char **argv)
458 show_local_fs = 1; 491 show_local_fs = 1;
459 break; 492 break;
460 case 'p': /* select path */ 493 case 'p': /* select path */
494 if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
495 crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
496 warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent ||
497 crit_usedinodes_percent)) {
498 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
499 }
461 se = np_add_parameter(&path_select_list, optarg); 500 se = np_add_parameter(&path_select_list, optarg);
462 se->w_df = w_df; 501 set_thresholds(&se->freespace_units, warn_freespace_units, crit_freespace_units);
463 se->c_df = c_df; 502 set_thresholds(&se->freespace_percent, warn_freespace_percent, crit_freespace_percent);
464 se->w_dfp = w_dfp; 503 set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units);
465 se->c_dfp = c_dfp; 504 set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
466 se->w_idfp = w_idfp; 505 set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
467 se->c_idfp = c_idfp;
468 break; 506 break;
469 case 'x': /* exclude path or partition */ 507 case 'x': /* exclude path or partition */
470 np_add_name(&dp_exclude_list, optarg); 508 np_add_name(&dp_exclude_list, optarg);
@@ -488,12 +526,16 @@ process_arguments (int argc, char **argv)
488 display_mntp = TRUE; 526 display_mntp = TRUE;
489 break; 527 break;
490 case 'C': 528 case 'C':
491 w_df = 0; 529 warn_freespace_units = NULL;
492 c_df = 0; 530 crit_freespace_units = NULL;
493 w_dfp = -1.0; 531 warn_usedspace_units = NULL;
494 c_dfp = -1.0; 532 crit_usedspace_units = NULL;
495 w_idfp = -1.0; 533 warn_freespace_percent = NULL;
496 c_idfp = -1.0; 534 crit_freespace_percent = NULL;
535 warn_usedspace_percent = NULL;
536 crit_usedspace_percent = NULL;
537 warn_usedinodes_percent = NULL;
538 crit_usedinodes_percent = NULL;
497 break; 539 break;
498 case 'V': /* version */ 540 case 'V': /* version */
499 print_revision (progname, revision); 541 print_revision (progname, revision);
@@ -506,22 +548,26 @@ process_arguments (int argc, char **argv)
506 } 548 }
507 } 549 }
508 550
509 /* Support for "check_disk warn crit [fs]" with thresholds at used level */ 551 /* Support for "check_disk warn crit [fs]" with thresholds at used% level */
510 c = optind; 552 c = optind;
511 if (w_dfp < 0 && argc > c && is_intnonneg (argv[c])) 553 if (warn_usedspace_percent == NULL && argc > c && is_intnonneg (argv[c]))
512 w_dfp = (100.0 - atof (argv[c++])); 554 warn_usedspace_percent = argv[c++];
513 555
514 if (c_dfp < 0 && argc > c && is_intnonneg (argv[c])) 556 if (crit_usedspace_percent == NULL && argc > c && is_intnonneg (argv[c]))
515 c_dfp = (100.0 - atof (argv[c++])); 557 crit_usedspace_percent = argv[c++];
516 558
517 if (argc > c && path == NULL) { 559 if (argc > c && path == NULL) {
518 se = np_add_parameter(&path_select_list, strdup(argv[c++])); 560 se = np_add_parameter(&path_select_list, strdup(argv[c++]));
519 se->w_df = w_df; 561 set_thresholds(&se->freespace_units, warn_freespace_units, crit_freespace_units);
520 se->c_df = c_df; 562 set_thresholds(&se->freespace_percent, warn_freespace_percent, crit_freespace_percent);
521 se->w_dfp = w_dfp; 563 set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units);
522 se->c_dfp = c_dfp; 564 set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
523 se->w_idfp = w_idfp; 565 set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
524 se->c_idfp = c_idfp; 566 }
567
568 if (units == NULL) {
569 units = strdup ("MB");
570 mult = (uintmax_t)1024 * 1024;
525 } 571 }
526 572
527 if (path_select_list) { 573 if (path_select_list) {
@@ -533,7 +579,7 @@ process_arguments (int argc, char **argv)
533 printf("DISK %s - ", _("CRITICAL")); 579 printf("DISK %s - ", _("CRITICAL"));
534 die (STATE_CRITICAL, _("%s does not exist\n"), temp_list->name); 580 die (STATE_CRITICAL, _("%s does not exist\n"), temp_list->name);
535 } 581 }
536 if (validate_arguments (temp_list->w_df, 582 /* if (validate_arguments (temp_list->w_df,
537 temp_list->c_df, 583 temp_list->c_df,
538 temp_list->w_dfp, 584 temp_list->w_dfp,
539 temp_list->c_dfp, 585 temp_list->c_dfp,
@@ -541,12 +587,14 @@ process_arguments (int argc, char **argv)
541 temp_list->c_idfp, 587 temp_list->c_idfp,
542 temp_list->name) == ERROR) 588 temp_list->name) == ERROR)
543 result = ERROR; 589 result = ERROR;
590 */
544 temp_list = temp_list->name_next; 591 temp_list = temp_list->name_next;
545 } 592 }
546 free(stat_buf); 593 free(stat_buf);
547 return result; 594 return result;
548 } else { 595 } else {
549 return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL); 596 return TRUE;
597 /* return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL); */
550 } 598 }
551} 599}
552 600
@@ -560,11 +608,13 @@ print_path (const char *mypath)
560 else 608 else
561 printf (_(" for %s\n"), mypath); 609 printf (_(" for %s\n"), mypath);
562 610
563 return; 611 //return;
564} 612}
565 613
566 614
567 615
616/* TODO: Remove?
617
568int 618int
569validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath) 619validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath)
570{ 620{
@@ -597,37 +647,12 @@ INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greate
597 return ERROR; 647 return ERROR;
598 } 648 }
599 649
600 if (units == NULL) {
601 units = strdup ("MB");
602 mult = (uintmax_t)1024 * 1024;
603 }
604 return OK; 650 return OK;
605} 651}
606 652
653*/
607 654
608 655
609int
610check_disk (double usp, uintmax_t free_disk, double uisp)
611{
612 int result = STATE_UNKNOWN;
613 /* check the percent used space against thresholds */
614 if (usp >= 0.0 && c_dfp >=0.0 && usp >= (100.0 - c_dfp))
615 result = STATE_CRITICAL;
616 else if (uisp >= 0.0 && c_idfp >=0.0 && uisp >= (100.0 - c_idfp))
617 result = STATE_CRITICAL;
618 else if (c_df > 0 && free_disk <= c_df)
619 result = STATE_CRITICAL;
620 else if (usp >= 0.0 && w_dfp >=0.0 && usp >= (100.0 - w_dfp))
621 result = STATE_WARNING;
622 else if (uisp >= 0.0 && w_idfp >=0.0 && uisp >= (100.0 - w_idfp))
623 result = STATE_WARNING;
624 else if (w_df > 0 && free_disk <= w_df)
625 result = STATE_WARNING;
626 else if (usp >= 0.0)
627 result = STATE_OK;
628 return result;
629}
630
631 656
632 657
633 658
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index 70d8415..6634492 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -52,8 +52,8 @@ if ($free_on_mp1 > $free_on_mp2) {
52} 52}
53 53
54 54
55$result = NPTest->testCmd( "./check_disk -w 100 -c 100 -p $more_free" ); 55$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free" );
56cmp_ok( $result->return_code, '==', 0, "At least 100 bytes available on $more_free"); 56cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free");
57like ( $result->output, $successOutput, "OK output" ); 57like ( $result->output, $successOutput, "OK output" );
58 58
59$result = NPTest->testCmd( "./check_disk 100 100 $more_free" ); 59$result = NPTest->testCmd( "./check_disk 100 100 $more_free" );
@@ -110,35 +110,28 @@ cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make
110 110
111 111
112 112
113
114$result = NPTest->testCmd(
115 "./check_disk -w 10% -c 15% -p $mountpoint_valid"
116 );
117cmp_ok( $result->return_code, '==', 3, "Invalid command line options" );
118
119TODO: { 113TODO: {
120 local $TODO = "-p must come after -w and -c"; 114 local $TODO = "Invalid percent figures";
121 $result = NPTest->testCmd( 115 $result = NPTest->testCmd(
116 "./check_disk -w 10% -c 15% -p $mountpoint_valid"
117 );
118 cmp_ok( $result->return_code, '==', 3, "Invalid command line options" );
119}
120
121$result = NPTest->testCmd(
122 "./check_disk -p $mountpoint_valid -w 10% -c 15%" 122 "./check_disk -p $mountpoint_valid -w 10% -c 15%"
123 ); 123 );
124 cmp_ok( $result->return_code, "==", 3, "Invalid options - order unimportant" ); 124cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" );
125}
126 125
127$result = NPTest->testCmd( "./check_disk -w 100% -c 100% ".${mountpoint_valid} ); # 100% empty 126$result = NPTest->testCmd( "./check_disk -w 100% -c 100% ".${mountpoint_valid} ); # 100% empty
128cmp_ok( $result->return_code, "==", 2, "100% empty" ); 127cmp_ok( $result->return_code, "==", 2, "100% empty" );
129like( $result->output, $failureOutput, "Right output" ); 128like( $result->output, $failureOutput, "Right output" );
130 129
131TODO: { 130$result = NPTest->testCmd( "./check_disk -w 100000 -c 100000 $mountpoint_valid" );
132 local $TODO = "Requesting 100GB free is should be critical"; 131cmp_ok( $result->return_code, '==', 2, "Check for 100GB free" );
133 $result = NPTest->testCmd( "./check_disk -w 100000 -c 100000 $mountpoint_valid" );
134 cmp_ok( $result->return_code, '==', 2, "Check for 100GB free" );
135}
136 132
137TODO: { 133$result = NPTest->testCmd( "./check_disk -w 100 -c 100 -u GB ".${mountpoint_valid} ); # 100 GB empty
138 local $TODO = "-u GB does not work"; 134cmp_ok( $result->return_code, "==", 2, "100 GB empty" );
139 $result = NPTest->testCmd( "./check_disk -w 100 -c 100 -u GB ".${mountpoint_valid} ); # 100 GB empty
140 cmp_ok( $result->return_code, "==", 2, "100 GB empty" );
141}
142 135
143 136
144# Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds 137# Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds
@@ -151,17 +144,17 @@ cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" );
151$result = NPTest->testCmd( "./check_disk 0 100 $mountpoint_valid" ); 144$result = NPTest->testCmd( "./check_disk 0 100 $mountpoint_valid" );
152cmp_ok( $result->return_code, '==', 1, "Old syntax: warn 0% used" ); 145cmp_ok( $result->return_code, '==', 1, "Old syntax: warn 0% used" );
153 146
154$result = NPTest->testCmd( "./check_disk 0 200 $mountpoint_valid" );
155cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
156
157TODO: { 147TODO: {
158 local $TODO = "Need to properly check input"; 148 local $TODO = "Invalid values";
149 $result = NPTest->testCmd( "./check_disk 0 200 $mountpoint_valid" );
150 cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
151
159 $result = NPTest->testCmd( "./check_disk 200 200 $mountpoint_valid" ); 152 $result = NPTest->testCmd( "./check_disk 200 200 $mountpoint_valid" );
160 cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" ); 153 cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
161}
162 154
163$result = NPTest->testCmd( "./check_disk 200 0 $mountpoint_valid" ); 155 $result = NPTest->testCmd( "./check_disk 200 0 $mountpoint_valid" );
164cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" ); 156 cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
157}
165 158
166$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /bob" ); 159$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /bob" );
167cmp_ok( $result->return_code, '==', 2, "Checking /bob - return error because /bob does not exist" ); 160cmp_ok( $result->return_code, '==', 2, "Checking /bob - return error because /bob does not exist" );