diff options
-rw-r--r-- | plugins/check_disk.c | 81 |
1 files changed, 65 insertions, 16 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index fd3b977..2b285d3 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -57,6 +57,8 @@ const char *options = "\ | |||
57 | Display the mountpoint instead of the partition\n\ | 57 | Display the mountpoint instead of the partition\n\ |
58 | -e, --errors-only\n\ | 58 | -e, --errors-only\n\ |
59 | Display only devices/mountpoints with errors\n\ | 59 | Display only devices/mountpoints with errors\n\ |
60 | -C, --clear\n\ | ||
61 | Clear thresholds\n\ | ||
60 | -v, --verbose\n\ | 62 | -v, --verbose\n\ |
61 | Show details for command-line debugging (do not use with nagios server)\n\ | 63 | Show details for command-line debugging (do not use with nagios server)\n\ |
62 | -h, --help\n\ | 64 | -h, --help\n\ |
@@ -67,6 +69,11 @@ const char *options = "\ | |||
67 | const char *notes = "\ | 69 | const char *notes = "\ |
68 | \n"; | 70 | \n"; |
69 | 71 | ||
72 | const char *examples = "\ | ||
73 | check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\ | ||
74 | Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n\ | ||
75 | \n"; | ||
76 | |||
70 | #include "common.h" | 77 | #include "common.h" |
71 | #if HAVE_INTTYPES_H | 78 | #if HAVE_INTTYPES_H |
72 | # include <inttypes.h> | 79 | # include <inttypes.h> |
@@ -107,6 +114,10 @@ struct name_list | |||
107 | { | 114 | { |
108 | char *name; | 115 | char *name; |
109 | int found; | 116 | int found; |
117 | int w_df; | ||
118 | int c_df; | ||
119 | float w_dfp; | ||
120 | float c_dfp; | ||
110 | struct name_list *name_next; | 121 | struct name_list *name_next; |
111 | }; | 122 | }; |
112 | 123 | ||
@@ -151,7 +162,7 @@ enum | |||
151 | #endif | 162 | #endif |
152 | 163 | ||
153 | int process_arguments (int, char **); | 164 | int process_arguments (int, char **); |
154 | int validate_arguments (void); | 165 | int validate_arguments (int, int, float, float, char *); |
155 | int check_disk (int usp, int free_disk); | 166 | int check_disk (int usp, int free_disk); |
156 | int walk_name_list (struct name_list *list, const char *name); | 167 | int walk_name_list (struct name_list *list, const char *name); |
157 | void print_help (void); | 168 | void print_help (void); |
@@ -237,7 +248,7 @@ main (int argc, char **argv) | |||
237 | units, | 248 | units, |
238 | free_space_pct, | 249 | free_space_pct, |
239 | (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir); | 250 | (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir); |
240 | asprintf (&details, "%s\n%.0f of %.0f %s (%2.0f%%) free on %s (type %s mounted on %s)", | 251 | asprintf (&details, "%s\n%.0f of %.0f %s (%2.0f%%) free on %s (type %s mounted on %s) warn:%d crit:%d warn%%:%.0f%% crit%%:%.0f%%", |
241 | details, | 252 | details, |
242 | free_space, | 253 | free_space, |
243 | total_space, | 254 | total_space, |
@@ -245,7 +256,8 @@ main (int argc, char **argv) | |||
245 | free_space_pct, | 256 | free_space_pct, |
246 | me->me_devname, | 257 | me->me_devname, |
247 | me->me_type, | 258 | me->me_type, |
248 | me->me_mountdir); | 259 | me->me_mountdir, |
260 | w_df, c_df, w_dfp, c_dfp); | ||
249 | } | 261 | } |
250 | 262 | ||
251 | } | 263 | } |
@@ -279,6 +291,8 @@ process_arguments (int argc, char **argv) | |||
279 | struct name_list **devtail = &dev_select_list; | 291 | struct name_list **devtail = &dev_select_list; |
280 | struct name_list **fstail = &fs_exclude_list; | 292 | struct name_list **fstail = &fs_exclude_list; |
281 | struct name_list **dptail = &dp_exclude_list; | 293 | struct name_list **dptail = &dp_exclude_list; |
294 | struct name_list *temp_list; | ||
295 | int result = OK; | ||
282 | 296 | ||
283 | int option_index = 0; | 297 | int option_index = 0; |
284 | static struct option long_options[] = { | 298 | static struct option long_options[] = { |
@@ -297,6 +311,7 @@ process_arguments (int argc, char **argv) | |||
297 | {"errors-only", no_argument, 0, 'e'}, | 311 | {"errors-only", no_argument, 0, 'e'}, |
298 | {"verbose", no_argument, 0, 'v'}, | 312 | {"verbose", no_argument, 0, 'v'}, |
299 | {"quiet", no_argument, 0, 'q'}, | 313 | {"quiet", no_argument, 0, 'q'}, |
314 | {"clear", no_argument, 0, 'C'}, | ||
300 | {"version", no_argument, 0, 'V'}, | 315 | {"version", no_argument, 0, 'V'}, |
301 | {"help", no_argument, 0, 'h'}, | 316 | {"help", no_argument, 0, 'h'}, |
302 | {0, 0, 0, 0} | 317 | {0, 0, 0, 0} |
@@ -316,7 +331,7 @@ process_arguments (int argc, char **argv) | |||
316 | strcpy (argv[c], "-t"); | 331 | strcpy (argv[c], "-t"); |
317 | 332 | ||
318 | while (1) { | 333 | while (1) { |
319 | c = getopt_long (argc, argv, "+?Vqhvet:c:w:u:p:x:X:mklM", long_options, &option_index); | 334 | c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", long_options, &option_index); |
320 | 335 | ||
321 | if (c == -1 || c == EOF) | 336 | if (c == -1 || c == EOF) |
322 | break; | 337 | break; |
@@ -397,6 +412,10 @@ process_arguments (int argc, char **argv) | |||
397 | se = (struct name_list *) malloc (sizeof (struct name_list)); | 412 | se = (struct name_list *) malloc (sizeof (struct name_list)); |
398 | se->name = strdup (optarg); | 413 | se->name = strdup (optarg); |
399 | se->name_next = NULL; | 414 | se->name_next = NULL; |
415 | se->w_df = w_df; | ||
416 | se->c_df = c_df; | ||
417 | se->w_dfp = w_dfp; | ||
418 | se->c_dfp = c_dfp; | ||
400 | *pathtail = se; | 419 | *pathtail = se; |
401 | pathtail = &se->name_next; | 420 | pathtail = &se->name_next; |
402 | break; | 421 | break; |
@@ -427,6 +446,12 @@ process_arguments (int argc, char **argv) | |||
427 | case 'M': /* display mountpoint */ | 446 | case 'M': /* display mountpoint */ |
428 | display_mntp = TRUE; | 447 | display_mntp = TRUE; |
429 | break; | 448 | break; |
449 | case 'C': | ||
450 | w_df = -1; | ||
451 | c_df = -1; | ||
452 | w_dfp = -1.0; | ||
453 | c_dfp = -1.0; | ||
454 | break; | ||
430 | case 'V': /* version */ | 455 | case 'V': /* version */ |
431 | print_revision (progname, revision); | 456 | print_revision (progname, revision); |
432 | exit (STATE_OK); | 457 | exit (STATE_OK); |
@@ -449,30 +474,49 @@ process_arguments (int argc, char **argv) | |||
449 | if (argc > c && strlen (path) == 0) | 474 | if (argc > c && strlen (path) == 0) |
450 | path = argv[c++]; | 475 | path = argv[c++]; |
451 | 476 | ||
452 | return validate_arguments (); | 477 | if (path_select_list) { |
478 | temp_list = path_select_list; | ||
479 | while (temp_list) { | ||
480 | if (validate_arguments (temp_list->w_df, temp_list->c_df, temp_list->w_dfp, temp_list->c_dfp, temp_list->name) == ERROR) | ||
481 | result = ERROR; | ||
482 | temp_list = temp_list->name_next; | ||
483 | } | ||
484 | return result; | ||
485 | } else { | ||
486 | return validate_arguments (w_df, c_df, w_dfp, c_dfp, NULL); | ||
487 | } | ||
453 | } | 488 | } |
454 | 489 | ||
455 | 490 | ||
491 | void print_path (char *path) | ||
492 | { | ||
493 | if (path) | ||
494 | printf (" for %s", path); | ||
495 | printf ("\n"); | ||
496 | } | ||
456 | 497 | ||
457 | int | 498 | int |
458 | validate_arguments () | 499 | validate_arguments (int w, int c, float wp, float cp, char *path) |
459 | { | 500 | { |
460 | if (w_df < 0 && c_df < 0 && w_dfp < 0 && c_dfp < 0) { | 501 | if (w < 0 && c < 0 && wp < 0 && cp < 0) { |
461 | printf ("INPUT ERROR: Unable to parse command line\n"); | 502 | printf ("INPUT ERROR: No thresholds specified"); |
503 | print_path (path); | ||
462 | return ERROR; | 504 | return ERROR; |
463 | } | 505 | } |
464 | else if ((w_dfp >= 0 || c_dfp >= 0) | 506 | else if ((wp >= 0 || cp >= 0) |
465 | && (w_dfp < 0 || c_dfp < 0 || w_dfp > 100 || c_dfp > 100 | 507 | && (wp < 0 || cp < 0 || wp > 100 || cp > 100 |
466 | || c_dfp > w_dfp)) { | 508 | || cp > wp)) { |
467 | printf | 509 | printf |
468 | ("INPUT ERROR: C_DFP (%f) should be less than W_DFP (%f) and both should be between zero and 100 percent, inclusive\n", | 510 | ("INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive", |
469 | c_dfp, w_dfp); | 511 | cp, wp); |
512 | print_path (path); | ||
470 | return ERROR; | 513 | return ERROR; |
471 | } | 514 | } |
472 | else if ((w_df > 0 || c_df > 0) && (w_df < 0 || c_df < 0 || c_df > w_df)) { | 515 | else if ((w > 0 || c > 0) && (w < 0 || c < 0 || c > w)) { |
473 | printf | 516 | printf |
474 | ("INPUT ERROR: C_DF (%d) should be less than W_DF (%d) and both should be greater than zero\n", | 517 | ("INPUT ERROR: C_DF (%d) should be less than W_DF (%d) and both should be greater than zero", |
475 | c_df, w_df); | 518 | c, w); |
519 | print_path (path); | ||
476 | return ERROR; | 520 | return ERROR; |
477 | } | 521 | } |
478 | else { | 522 | else { |
@@ -509,6 +553,10 @@ walk_name_list (struct name_list *list, const char *name) | |||
509 | while (list) { | 553 | while (list) { |
510 | if (! strcmp(list->name, name)) { | 554 | if (! strcmp(list->name, name)) { |
511 | list->found = 1; | 555 | list->found = 1; |
556 | w_df = list->w_df; | ||
557 | c_df = list->c_df; | ||
558 | w_dfp = list->w_dfp; | ||
559 | c_dfp = list->c_dfp; | ||
512 | return TRUE; | 560 | return TRUE; |
513 | } | 561 | } |
514 | list = list->name_next; | 562 | list = list->name_next; |
@@ -529,6 +577,7 @@ print_help (void) | |||
529 | printf ("\nOptions:\n"); | 577 | printf ("\nOptions:\n"); |
530 | printf (options); | 578 | printf (options); |
531 | printf (notes); | 579 | printf (notes); |
580 | printf ("Examples:\n%s", examples); | ||
532 | support (); | 581 | support (); |
533 | } | 582 | } |
534 | 583 | ||