summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c226
1 files changed, 109 insertions, 117 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 05e5502..b3dd301 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
46#include <stdarg.h> 46#include <stdarg.h>
47#include "fsusage.h" 47#include "fsusage.h"
48#include "mountlist.h" 48#include "mountlist.h"
49#include "intprops.h" /* necessary for TYPE_MAXIMUM */ 49#include <float.h>
50#if HAVE_LIMITS_H 50#if HAVE_LIMITS_H
51# include <limits.h> 51# include <limits.h>
52#endif 52#endif
@@ -93,11 +93,11 @@ static int stat_remote_fs = 0;
93 93
94/* Linked list of filesystem types to omit. 94/* Linked list of filesystem types to omit.
95 If the list is empty, don't exclude any types. */ 95 If the list is empty, don't exclude any types. */
96static struct name_list *fs_exclude_list; 96static struct regex_list *fs_exclude_list = NULL;
97 97
98/* Linked list of filesystem types to check. 98/* Linked list of filesystem types to check.
99 If the list is empty, include all types. */ 99 If the list is empty, include all types. */
100static struct name_list *fs_include_list; 100static struct regex_list *fs_include_list;
101 101
102static struct name_list *dp_exclude_list; 102static struct name_list *dp_exclude_list;
103 103
@@ -112,52 +112,48 @@ enum
112{ 112{
113 SYNC_OPTION = CHAR_MAX + 1, 113 SYNC_OPTION = CHAR_MAX + 1,
114 NO_SYNC_OPTION, 114 NO_SYNC_OPTION,
115 BLOCK_SIZE_OPTION, 115 BLOCK_SIZE_OPTION
116 IGNORE_MISSING
117}; 116};
118 117
119#ifdef _AIX 118#ifdef _AIX
120#pragma alloca 119#pragma alloca
121#endif 120#endif
122 121
123int process_arguments (int, char **); 122static int process_arguments (int, char **);
124void print_path (const char *mypath); 123static void set_all_thresholds (struct parameter_list *path);
125void set_all_thresholds (struct parameter_list *path); 124static void print_help (void);
126int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
127void print_help (void);
128void print_usage (void); 125void print_usage (void);
129double calculate_percent(uintmax_t, uintmax_t); 126static double calculate_percent(uintmax_t, uintmax_t);
130bool stat_path (struct parameter_list *p); 127static bool stat_path (struct parameter_list *p);
131void get_stats (struct parameter_list *p, struct fs_usage *fsp); 128static void get_stats (struct parameter_list *p, struct fs_usage *fsp);
132void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); 129static void get_path_stats (struct parameter_list *p, struct fs_usage *fsp);
133 130
134char *exclude_device; 131static char *units;
135char *units; 132static uintmax_t mult = 1024 * 1024;
136uintmax_t mult = 1024 * 1024; 133static int verbose = 0;
137int verbose = 0; 134static bool erronly = false;
138int erronly = FALSE; 135static bool display_mntp = false;
139int display_mntp = FALSE; 136static bool exact_match = false;
140int exact_match = FALSE; 137static bool ignore_missing = false;
141bool ignore_missing = false; 138static bool freespace_ignore_reserved = false;
142int freespace_ignore_reserved = FALSE; 139static bool display_inodes_perfdata = false;
143int display_inodes_perfdata = FALSE; 140static char *warn_freespace_units = NULL;
144char *warn_freespace_units = NULL; 141static char *crit_freespace_units = NULL;
145char *crit_freespace_units = NULL; 142static char *warn_freespace_percent = NULL;
146char *warn_freespace_percent = NULL; 143static char *crit_freespace_percent = NULL;
147char *crit_freespace_percent = NULL; 144static char *warn_usedspace_units = NULL;
148char *warn_usedspace_units = NULL; 145static char *crit_usedspace_units = NULL;
149char *crit_usedspace_units = NULL; 146static char *warn_usedspace_percent = NULL;
150char *warn_usedspace_percent = NULL; 147static char *crit_usedspace_percent = NULL;
151char *crit_usedspace_percent = NULL; 148static char *warn_usedinodes_percent = NULL;
152char *warn_usedinodes_percent = NULL; 149static char *crit_usedinodes_percent = NULL;
153char *crit_usedinodes_percent = NULL; 150static char *warn_freeinodes_percent = NULL;
154char *warn_freeinodes_percent = NULL; 151static char *crit_freeinodes_percent = NULL;
155char *crit_freeinodes_percent = NULL; 152static bool path_selected = false;
156int path_selected = FALSE; 153static bool path_ignored = false;
157bool path_ignored = false; 154static char *group = NULL;
158char *group = NULL; 155static struct stat *stat_buf;
159struct stat *stat_buf; 156static struct name_list *seen = NULL;
160struct name_list *seen = NULL;
161 157
162 158
163int 159int
@@ -205,7 +201,7 @@ main (int argc, char **argv)
205 /* If a list of paths has not been selected, find entire 201 /* If a list of paths has not been selected, find entire
206 mount list and create list of paths 202 mount list and create list of paths
207 */ 203 */
208 if (path_selected == FALSE && path_ignored == false) { 204 if (path_selected == false && path_ignored == false) {
209 for (me = mount_list; me; me = me->me_next) { 205 for (me = mount_list; me; me = me->me_next) {
210 if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) { 206 if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
211 path = np_add_parameter(&path_select_list, me->me_mountdir); 207 path = np_add_parameter(&path_select_list, me->me_mountdir);
@@ -300,7 +296,7 @@ main (int argc, char **argv)
300 } else if (me->me_dummy && !show_all_fs) { 296 } else if (me->me_dummy && !show_all_fs) {
301 continue; 297 continue;
302 /* Skip excluded fstypes */ 298 /* Skip excluded fstypes */
303 } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) { 299 } else if (fs_exclude_list && np_find_regmatch (fs_exclude_list, me->me_type)) {
304 continue; 300 continue;
305 /* Skip excluded fs's */ 301 /* Skip excluded fs's */
306 } else if (dp_exclude_list && 302 } else if (dp_exclude_list &&
@@ -308,7 +304,7 @@ main (int argc, char **argv)
308 np_find_name (dp_exclude_list, me->me_mountdir))) { 304 np_find_name (dp_exclude_list, me->me_mountdir))) {
309 continue; 305 continue;
310 /* Skip not included fstypes */ 306 /* Skip not included fstypes */
311 } else if (fs_include_list && !np_find_name (fs_include_list, me->me_type)) { 307 } else if (fs_include_list && !np_find_regmatch(fs_include_list, me->me_type)) {
312 continue; 308 continue;
313 } 309 }
314 } 310 }
@@ -326,7 +322,7 @@ main (int argc, char **argv)
326 get_stats (path, &fsp); 322 get_stats (path, &fsp);
327 323
328 if (verbose >= 3) { 324 if (verbose >= 3) {
329 printf ("For %s, used_pct=%g free_pct=%g used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%lu mult=%lu\n", 325 printf ("For %s, used_pct=%f free_pct=%f used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%f free_inodes_pct=%f fsp.fsu_blocksize=%lu mult=%lu\n",
330 me->me_mountdir, 326 me->me_mountdir,
331 path->dused_pct, 327 path->dused_pct,
332 path->dfree_pct, 328 path->dfree_pct,
@@ -396,10 +392,10 @@ main (int argc, char **argv)
396 perfdata_uint64 ( 392 perfdata_uint64 (
397 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 393 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
398 path->dused_units * mult, "B", 394 path->dused_units * mult, "B",
399 (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide, 395 (warning_high_tide == UINT64_MAX ? false : true), warning_high_tide,
400 (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide, 396 (critical_high_tide == UINT64_MAX ? false : true), critical_high_tide,
401 TRUE, 0, 397 true, 0,
402 TRUE, path->dtotal_units * mult)); 398 true, path->dtotal_units * mult));
403 399
404 if (display_inodes_perfdata) { 400 if (display_inodes_perfdata) {
405 /* *_high_tide must be reinitialized at each run */ 401 /* *_high_tide must be reinitialized at each run */
@@ -418,10 +414,10 @@ main (int argc, char **argv)
418 xasprintf (&perf, "%s %s", perf, 414 xasprintf (&perf, "%s %s", perf,
419 perfdata_uint64 (perf_ilabel, 415 perfdata_uint64 (perf_ilabel,
420 path->inodes_used, "", 416 path->inodes_used, "",
421 (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide, 417 (warning_high_tide != UINT64_MAX ? true : false), warning_high_tide,
422 (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide, 418 (critical_high_tide != UINT64_MAX ? true : false), critical_high_tide,
423 TRUE, 0, 419 true, 0,
424 TRUE, path->inodes_total)); 420 true, path->inodes_total));
425 } 421 }
426 422
427 if (disk_result==STATE_OK && erronly && !verbose) 423 if (disk_result==STATE_OK && erronly && !verbose)
@@ -432,7 +428,7 @@ main (int argc, char **argv)
432 } else { 428 } else {
433 xasprintf(&flag_header, ""); 429 xasprintf(&flag_header, "");
434 } 430 }
435 xasprintf (&output, "%s%s %s %llu%s (%.0f%%", 431 xasprintf (&output, "%s%s %s %llu%s (%.1f%%",
436 output, flag_header, 432 output, flag_header,
437 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 433 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
438 path->dfree_units, 434 path->dfree_units,
@@ -452,7 +448,7 @@ main (int argc, char **argv)
452 448
453 if (strcmp(output, "") == 0 && ! erronly) { 449 if (strcmp(output, "") == 0 && ! erronly) {
454 preamble = ""; 450 preamble = "";
455 xasprintf (&output, " - No disks were found for provided parameters;"); 451 xasprintf (&output, " - No disks were found for provided parameters");
456 } 452 }
457 453
458 printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf); 454 printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf);
@@ -462,24 +458,8 @@ main (int argc, char **argv)
462 458
463double calculate_percent(uintmax_t value, uintmax_t total) { 459double calculate_percent(uintmax_t value, uintmax_t total) {
464 double pct = -1; 460 double pct = -1;
465 /* I don't understand the below, but it is taken from coreutils' df */ 461 if(value <= DBL_MAX && total != 0) {
466 /* Seems to be calculating pct, in the best possible way */ 462 pct = (double)value / total * 100.0;
467 if (value <= TYPE_MAXIMUM(uintmax_t) / 100
468 && total != 0) {
469 uintmax_t u100 = value * 100;
470 pct = u100 / total + (u100 % total != 0);
471 } else {
472 /* Possible rounding errors - see coreutils' df for more explanation */
473 double u = value;
474 double t = total;
475 if (t) {
476 long int lipct = pct = u * 100 / t;
477 double ipct = lipct;
478
479 /* Like 'pct = ceil (dpct);', but without ceil - from coreutils again */
480 if (ipct - 1 < pct && pct <= ipct + 1)
481 pct = ipct + (ipct < pct);
482 }
483 } 463 }
484 return pct; 464 return pct;
485} 465}
@@ -524,7 +504,7 @@ process_arguments (int argc, char **argv)
524 {"ignore-ereg-partition", required_argument, 0, 'i'}, 504 {"ignore-ereg-partition", required_argument, 0, 'i'},
525 {"ignore-eregi-path", required_argument, 0, 'I'}, 505 {"ignore-eregi-path", required_argument, 0, 'I'},
526 {"ignore-eregi-partition", required_argument, 0, 'I'}, 506 {"ignore-eregi-partition", required_argument, 0, 'I'},
527 {"ignore-missing", no_argument, 0, IGNORE_MISSING}, 507 {"ignore-missing", no_argument, 0, 'n'},
528 {"local", no_argument, 0, 'l'}, 508 {"local", no_argument, 0, 'l'},
529 {"stat-remote-fs", no_argument, 0, 'L'}, 509 {"stat-remote-fs", no_argument, 0, 'L'},
530 {"iperfdata", no_argument, 0, 'P'}, 510 {"iperfdata", no_argument, 0, 'P'},
@@ -543,14 +523,14 @@ process_arguments (int argc, char **argv)
543 if (argc < 2) 523 if (argc < 2)
544 return ERROR; 524 return ERROR;
545 525
546 np_add_name(&fs_exclude_list, "iso9660"); 526 np_add_regex(&fs_exclude_list, "iso9660", REG_EXTENDED);
547 527
548 for (c = 1; c < argc; c++) 528 for (c = 1; c < argc; c++)
549 if (strcmp ("-to", argv[c]) == 0) 529 if (strcmp ("-to", argv[c]) == 0)
550 strcpy (argv[c], "-t"); 530 strcpy (argv[c], "-t");
551 531
552 while (1) { 532 while (1) {
553 c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEA", longopts, &option); 533 c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEAn", longopts, &option);
554 534
555 if (c == -1 || c == EOF) 535 if (c == -1 || c == EOF)
556 break; 536 break;
@@ -567,6 +547,10 @@ process_arguments (int argc, char **argv)
567 547
568 /* See comments for 'c' */ 548 /* See comments for 'c' */
569 case 'w': /* warning threshold */ 549 case 'w': /* warning threshold */
550 if (!is_percentage_expression(optarg) && !is_numeric(optarg)) {
551 die(STATE_UNKNOWN, "Argument for --warning invalid or missing: %s\n", optarg);
552 }
553
570 if (strstr(optarg, "%")) { 554 if (strstr(optarg, "%")) {
571 if (*optarg == '@') { 555 if (*optarg == '@') {
572 warn_freespace_percent = optarg; 556 warn_freespace_percent = optarg;
@@ -588,6 +572,10 @@ process_arguments (int argc, char **argv)
588 force @ at the beginning of the range, so that it is backwards compatible 572 force @ at the beginning of the range, so that it is backwards compatible
589 */ 573 */
590 case 'c': /* critical threshold */ 574 case 'c': /* critical threshold */
575 if (!is_percentage_expression(optarg) && !is_numeric(optarg)) {
576 die(STATE_UNKNOWN, "Argument for --critical invalid or missing: %s\n", optarg);
577 }
578
591 if (strstr(optarg, "%")) { 579 if (strstr(optarg, "%")) {
592 if (*optarg == '@') { 580 if (*optarg == '@') {
593 crit_freespace_percent = optarg; 581 crit_freespace_percent = optarg;
@@ -710,34 +698,42 @@ process_arguments (int argc, char **argv)
710 mount_list = read_file_system_list (0); 698 mount_list = read_file_system_list (0);
711 np_set_best_match(se, mount_list, exact_match); 699 np_set_best_match(se, mount_list, exact_match);
712 700
713 path_selected = TRUE; 701 path_selected = true;
714 break; 702 break;
715 case 'x': /* exclude path or partition */ 703 case 'x': /* exclude path or partition */
716 np_add_name(&dp_exclude_list, optarg); 704 np_add_name(&dp_exclude_list, optarg);
717 break; 705 break;
718 case 'X': /* exclude file system type */ 706 case 'X': /* exclude file system type */
719 np_add_name(&fs_exclude_list, optarg); 707 err = np_add_regex(&fs_exclude_list, optarg, REG_EXTENDED);
708 if (err != 0) {
709 regerror (err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER);
710 die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
711 }
720 break; 712 break;
721 case 'N': /* include file system type */ 713 case 'N': /* include file system type */
722 np_add_name(&fs_include_list, optarg); 714 err = np_add_regex(&fs_include_list, optarg, REG_EXTENDED);
715 if (err != 0) {
716 regerror (err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER);
717 die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
718 }
723 break; 719 break;
724 case 'v': /* verbose */ 720 case 'v': /* verbose */
725 verbose++; 721 verbose++;
726 break; 722 break;
727 case 'q': /* TODO: this function should eventually go away (removed 2007-09-20) */ 723 case 'q': /* TODO: this function should eventually go away (removed 2007-09-20) */
728 /* verbose--; **replaced by line below**. -q was only a broken way of implementing -e */ 724 /* verbose--; **replaced by line below**. -q was only a broken way of implementing -e */
729 erronly = TRUE; 725 erronly = true;
730 break; 726 break;
731 case 'e': 727 case 'e':
732 erronly = TRUE; 728 erronly = true;
733 break; 729 break;
734 case 'E': 730 case 'E':
735 if (path_selected) 731 if (path_selected)
736 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n")); 732 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n"));
737 exact_match = TRUE; 733 exact_match = true;
738 break; 734 break;
739 case 'f': 735 case 'f':
740 freespace_ignore_reserved = TRUE; 736 freespace_ignore_reserved = true;
741 break; 737 break;
742 case 'g': 738 case 'g':
743 if (path_selected) 739 if (path_selected)
@@ -784,7 +780,7 @@ process_arguments (int argc, char **argv)
784 cflags = default_cflags; 780 cflags = default_cflags;
785 break; 781 break;
786 782
787 case IGNORE_MISSING: 783 case 'n':
788 ignore_missing = true; 784 ignore_missing = true;
789 break; 785 break;
790 case 'A': 786 case 'A':
@@ -798,7 +794,7 @@ process_arguments (int argc, char **argv)
798 crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || 794 crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
799 warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent || 795 warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent ||
800 crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) { 796 crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
801 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -r/-R\n")); 797 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -r/-R/-A (--ereg-path/--eregi-path/--all)\n"));
802 } 798 }
803 799
804 err = regcomp(&re, optarg, cflags); 800 err = regcomp(&re, optarg, cflags);
@@ -809,7 +805,7 @@ process_arguments (int argc, char **argv)
809 805
810 for (me = mount_list; me; me = me->me_next) { 806 for (me = mount_list; me; me = me->me_next) {
811 if (np_regex_match_mount_entry(me, &re)) { 807 if (np_regex_match_mount_entry(me, &re)) {
812 fnd = TRUE; 808 fnd = true;
813 if (verbose >= 3) 809 if (verbose >= 3)
814 printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg); 810 printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
815 811
@@ -824,24 +820,24 @@ process_arguments (int argc, char **argv)
824 820
825 if (!fnd && ignore_missing == true) { 821 if (!fnd && ignore_missing == true) {
826 path_ignored = true; 822 path_ignored = true;
827 /* path_selected = TRUE;*/ 823 path_selected = true;
828 break; 824 break;
829 } else if (!fnd) 825 } else if (!fnd)
830 die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), 826 die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"),
831 _("Regular expression did not match any path or disk"), optarg); 827 _("Regular expression did not match any path or disk"), optarg);
832 828
833 fnd = FALSE; 829 fnd = false;
834 path_selected = TRUE; 830 path_selected = true;
835 np_set_best_match(path_select_list, mount_list, exact_match); 831 np_set_best_match(path_select_list, mount_list, exact_match);
836 cflags = default_cflags; 832 cflags = default_cflags;
837 833
838 break; 834 break;
839 case 'M': /* display mountpoint */ 835 case 'M': /* display mountpoint */
840 display_mntp = TRUE; 836 display_mntp = true;
841 break; 837 break;
842 case 'C': 838 case 'C':
843 /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */ 839 /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */
844 if (path_selected == FALSE) { 840 if (path_selected == false) {
845 struct parameter_list *path; 841 struct parameter_list *path;
846 for (me = mount_list; me; me = me->me_next) { 842 for (me = mount_list; me; me = me->me_next) {
847 if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) 843 if (! (path = np_find_parameter(path_select_list, me->me_mountdir)))
@@ -864,7 +860,7 @@ process_arguments (int argc, char **argv)
864 warn_freeinodes_percent = NULL; 860 warn_freeinodes_percent = NULL;
865 crit_freeinodes_percent = NULL; 861 crit_freeinodes_percent = NULL;
866 862
867 path_selected = FALSE; 863 path_selected = false;
868 group = NULL; 864 group = NULL;
869 break; 865 break;
870 case 'V': /* version */ 866 case 'V': /* version */
@@ -888,7 +884,7 @@ process_arguments (int argc, char **argv)
888 884
889 if (argc > c) { 885 if (argc > c) {
890 se = np_add_parameter(&path_select_list, strdup(argv[c++])); 886 se = np_add_parameter(&path_select_list, strdup(argv[c++]));
891 path_selected = TRUE; 887 path_selected = true;
892 set_all_thresholds(se); 888 set_all_thresholds(se);
893 } 889 }
894 890
@@ -897,21 +893,9 @@ process_arguments (int argc, char **argv)
897 mult = (uintmax_t)1024 * 1024; 893 mult = (uintmax_t)1024 * 1024;
898 } 894 }
899 895
900 return TRUE; 896 return true;
901}
902
903
904
905void
906print_path (const char *mypath)
907{
908 if (mypath == NULL)
909 printf ("\n");
910 else
911 printf (_(" for %s\n"), mypath);
912} 897}
913 898
914
915void 899void
916set_all_thresholds (struct parameter_list *path) 900set_all_thresholds (struct parameter_list *path)
917{ 901{
@@ -996,25 +980,33 @@ print_help (void)
996 printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)")); 980 printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
997 printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION"); 981 printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION");
998 printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)")); 982 printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
999 printf (" %s\n", "--ignore-missing"); 983 printf (" %s\n", "-n, --ignore-missing");
1000 printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible.")); 984 printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible."));
1001 printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)")); 985 printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)"));
1002 printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 986 printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
1003 printf (" %s\n", "-u, --units=STRING"); 987 printf (" %s\n", "-u, --units=STRING");
1004 printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)")); 988 printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
1005 printf (UT_VERBOSE); 989 printf (UT_VERBOSE);
1006 printf (" %s\n", "-X, --exclude-type=TYPE"); 990 printf (" %s\n", "-X, --exclude-type=TYPE_REGEX");
1007 printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)")); 991 printf (" %s\n", _("Ignore all filesystems of types matching given regex(7) (may be repeated)"));
1008 printf (" %s\n", "-N, --include-type=TYPE"); 992 printf (" %s\n", "-N, --include-type=TYPE_REGEX");
1009 printf (" %s\n", _("Check only filesystems of indicated type (may be repeated)")); 993 printf (" %s\n", _("Check only filesystems where the type matches this given regex(7) (may be repeated)"));
994
995 printf ("\n");
996 printf ("%s\n", _("General usage hints:"));
997 printf (" %s\n", _("- Arguments are positional! \"-w 5 -c 1 -p /foo -w6 -c2 -p /bar\" is not the same as"));
998 printf (" %s\n", _("\"-w 5 -c 1 -p /bar w6 -c2 -p /foo\"."));
999 printf (" %s\n", _("- The syntax is broadly: \"{thresholds a} {paths a} -C {thresholds b} {thresholds b} ...\""));
1000
1001
1010 1002
1011 printf ("\n"); 1003 printf ("\n");
1012 printf ("%s\n", _("Examples:")); 1004 printf ("%s\n", _("Examples:"));
1013 printf (" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /"); 1005 printf (" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /");
1014 printf (" %s\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB")); 1006 printf (" %s\n\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB"));
1015 printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -g sidDATA -r '^/oracle/SID/data.*$'"); 1007 printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -g sidDATA -r '^/oracle/SID/data.*$'");
1016 printf (" %s\n", _("Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex")); 1008 printf (" %s\n", _("Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex"));
1017 printf (" %s\n", _("are grouped which means the freespace thresholds are applied to all disks together")); 1009 printf (" %s\n\n", _("are grouped which means the freespace thresholds are applied to all disks together"));
1018 printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -p /foo -C -w 5% -c 3% -p /bar"); 1010 printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -p /foo -C -w 5% -c 3% -p /bar");
1019 printf (" %s\n", _("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M")); 1011 printf (" %s\n", _("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M"));
1020 1012
@@ -1027,9 +1019,9 @@ void
1027print_usage (void) 1019print_usage (void)
1028{ 1020{
1029 printf ("%s\n", _("Usage:")); 1021 printf ("%s\n", _("Usage:"));
1030 printf (" %s {-w absolute_limit |-w percentage_limit% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit% | -K inode_percentage_limit } {-p path | -x device}\n", progname); 1022 printf (" %s {-w absolute_limit |-w percentage_limit%% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit%% | -K inode_percentage_limit } {-p path | -x device}\n", progname);
1031 printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); 1023 printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
1032 printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); 1024 printf ("[-t timeout] [-u unit] [-v] [-X type_regex] [-N type]\n");
1033} 1025}
1034 1026
1035bool 1027bool
@@ -1115,7 +1107,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
1115 } 1107 }
1116 /* finally calculate percentages for either plain FS or summed up group */ 1108 /* finally calculate percentages for either plain FS or summed up group */
1117 p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ 1109 p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */
1118 p->dfree_pct = 100 - p->dused_pct; 1110 p->dfree_pct = 100.0 - p->dused_pct;
1119 p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); 1111 p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total);
1120 p->dfree_inodes_percent = 100 - p->dused_inodes_percent; 1112 p->dfree_inodes_percent = 100 - p->dused_inodes_percent;
1121 1113