summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
authorMatthias Eble <psychotrahe@users.sourceforge.net>2007-09-22 17:40:35 (GMT)
committerMatthias Eble <psychotrahe@users.sourceforge.net>2007-09-22 17:40:35 (GMT)
commitd23b17e6567d8eb983956b36b31a383f3cc639d2 (patch)
tree19ba67a6555bb609875f819af5c4b9c479101820 /plugins/check_disk.c
parent520f297fa931d391f81af672b5b0e34db71b8c73 (diff)
downloadmonitoring-plugins-d23b17e6567d8eb983956b36b31a383f3cc639d2.tar.gz
Added -i/-I to ignore pathes/partitions based on regular expressions
Added check_disk -A selecting all filesystems -E option must now be passed before -p or -r/-R Passing -E after -p or -r results in UNKNOWN state Fixed bug when mixing case sensitive and insensitive regexes git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1786 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c81
1 files changed, 67 insertions, 14 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 90b2248..d267409 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -447,15 +447,16 @@ int
447process_arguments (int argc, char **argv) 447process_arguments (int argc, char **argv)
448{ 448{
449 int c, err; 449 int c, err;
450 struct parameter_list *se, *se2; 450 struct parameter_list *se;
451 struct parameter_list *temp_list; 451 struct parameter_list *temp_list = NULL, *previous = NULL;
452 struct parameter_list *temp_path_select_list = NULL; 452 struct parameter_list *temp_path_select_list = NULL;
453 struct mount_entry *me; 453 struct mount_entry *me, *temp_me;
454 int result = OK; 454 int result = OK;
455 regex_t re; 455 regex_t re;
456 int cflags = REG_NOSUB | REG_EXTENDED; 456 int cflags = REG_NOSUB | REG_EXTENDED;
457 int default_cflags = cflags;
457 char errbuf[MAX_INPUT_BUFFER]; 458 char errbuf[MAX_INPUT_BUFFER];
458 bool fnd = false; 459 int fnd = 0;
459 460
460 int option = 0; 461 int option = 0;
461 static struct option longopts[] = { 462 static struct option longopts[] = {
@@ -478,9 +479,14 @@ process_arguments (int argc, char **argv)
478 {"eregi-partition", required_argument, 0, 'R'}, 479 {"eregi-partition", required_argument, 0, 'R'},
479 {"ereg-path", required_argument, 0, 'r'}, 480 {"ereg-path", required_argument, 0, 'r'},
480 {"ereg-partition", required_argument, 0, 'r'}, 481 {"ereg-partition", required_argument, 0, 'r'},
482 {"ignore-ereg-path", required_argument, 0, 'i'},
483 {"ignore-ereg-partition", required_argument, 0, 'i'},
484 {"ignore-eregi-path", required_argument, 0, 'I'},
485 {"ignore-eregi-partition", required_argument, 0, 'I'},
481 {"mountpoint", no_argument, 0, 'M'}, 486 {"mountpoint", no_argument, 0, 'M'},
482 {"errors-only", no_argument, 0, 'e'}, 487 {"errors-only", no_argument, 0, 'e'},
483 {"exact-match", no_argument, 0, 'E'}, 488 {"exact-match", no_argument, 0, 'E'},
489 {"all", no_argument, 0, 'A'},
484 {"verbose", no_argument, 0, 'v'}, 490 {"verbose", no_argument, 0, 'v'},
485 {"quiet", no_argument, 0, 'q'}, 491 {"quiet", no_argument, 0, 'q'},
486 {"clear", no_argument, 0, 'C'}, 492 {"clear", no_argument, 0, 'C'},
@@ -499,7 +505,7 @@ process_arguments (int argc, char **argv)
499 strcpy (argv[c], "-t"); 505 strcpy (argv[c], "-t");
500 506
501 while (1) { 507 while (1) {
502 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:R:r:ME", longopts, &option); 508 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:R:r:i:I:MEA", longopts, &option);
503 509
504 if (c == -1 || c == EOF) 510 if (c == -1 || c == EOF)
505 break; 511 break;
@@ -613,18 +619,13 @@ process_arguments (int argc, char **argv)
613 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n")); 619 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
614 } 620 }
615 621
616 /* get the real mountdir of the specified path. np_find_parameter won't find an entry if -p is not
617 * exactly the same string as the mountdir */
618 se2 = np_add_parameter(&temp_path_select_list, optarg);
619 np_set_best_match(se2, mount_list, FALSE);
620
621
622 /* add parameter if not found. overwrite thresholds if path has already been added */ 622 /* add parameter if not found. overwrite thresholds if path has already been added */
623 if (! (se = np_find_parameter(path_select_list, optarg))) { 623 if (! (se = np_find_parameter(path_select_list, optarg))) {
624 se = np_add_parameter(&path_select_list, optarg); 624 se = np_add_parameter(&path_select_list, optarg);
625 } 625 }
626 se->group = group; 626 se->group = group;
627 set_all_thresholds(se); 627 set_all_thresholds(se);
628 np_set_best_match(se, mount_list, exact_match);
628 path_selected = true; 629 path_selected = true;
629 break; 630 break;
630 case 'x': /* exclude path or partition */ 631 case 'x': /* exclude path or partition */
@@ -644,13 +645,56 @@ process_arguments (int argc, char **argv)
644 erronly = TRUE; 645 erronly = TRUE;
645 break; 646 break;
646 case 'E': 647 case 'E':
648 if (path_selected)
649 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting pathes\n"));
647 exact_match = TRUE; 650 exact_match = TRUE;
648 break; 651 break;
649 case 'g': 652 case 'g':
650 if (path_selected) 653 if (path_selected)
651 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before using -p\n")); 654 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting pathes \n"));
652 group = optarg; 655 group = optarg;
653 break; 656 break;
657 case 'I':
658 cflags |= REG_ICASE;
659 case 'i':
660 if (!path_selected)
661 die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Pathes need to be selected before using -i/-I. Use -A to select all pathes explicitly"));
662 err = regcomp(&re, optarg, cflags);
663 if (err != 0) {
664 regerror (err, &re, errbuf, MAX_INPUT_BUFFER);
665 die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
666 }
667
668 temp_list = path_select_list;
669
670 previous = NULL;
671 while (temp_list) {
672 if (temp_list->best_match) {
673 if (np_regex_match_mount_entry(temp_list->best_match, &re)) {
674
675 if (verbose >=3)
676 printf("ignoring %s matching regex\n", temp_list->name);
677
678 temp_list = np_del_parameter(temp_list, previous);
679 /* pointer to first element needs to be uĆ¼dated if first item gets deleted */
680 if (previous == NULL)
681 path_select_list = temp_list;
682 } else {
683 previous = temp_list;
684 temp_list = temp_list->name_next;
685 }
686 } else {
687 previous = temp_list;
688 temp_list = temp_list->name_next;
689 }
690 }
691
692
693 cflags = default_cflags;
694 break;
695
696 case 'A':
697 optarg = strdup(".*");
654 case 'R': 698 case 'R':
655 cflags |= REG_ICASE; 699 cflags |= REG_ICASE;
656 case 'r': 700 case 'r':
@@ -669,9 +713,9 @@ process_arguments (int argc, char **argv)
669 713
670 for (me = mount_list; me; me = me->me_next) { 714 for (me = mount_list; me; me = me->me_next) {
671 if (np_regex_match_mount_entry(me, &re)) { 715 if (np_regex_match_mount_entry(me, &re)) {
672 fnd = true; 716 fnd = true;
673 if (verbose > 3) 717 if (verbose > 3)
674 printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg); 718 printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
675 719
676 /* add parameter if not found. overwrite thresholds if path has already been added */ 720 /* add parameter if not found. overwrite thresholds if path has already been added */
677 if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) { 721 if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) {
@@ -688,6 +732,9 @@ process_arguments (int argc, char **argv)
688 732
689 fnd = false; 733 fnd = false;
690 path_selected = true; 734 path_selected = true;
735 np_set_best_match(path_select_list, mount_list, exact_match);
736 cflags = default_cflags;
737
691 break; 738 break;
692 case 'M': /* display mountpoint */ 739 case 'M': /* display mountpoint */
693 display_mntp = TRUE; 740 display_mntp = TRUE;
@@ -871,10 +918,16 @@ print_help (void)
871 printf (" %s\n", _("Display the mountpoint instead of the partition")); 918 printf (" %s\n", _("Display the mountpoint instead of the partition"));
872 printf (" %s\n", "-m, --megabytes"); 919 printf (" %s\n", "-m, --megabytes");
873 printf (" %s\n", _("Same as '--units MB'")); 920 printf (" %s\n", _("Same as '--units MB'"));
921 printf (" %s\n", "-A, --all");
922 printf (" %s\n", _("Explicitly select all pathes. This is equivalent to -R '.*'"));
874 printf (" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION"); 923 printf (" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION");
875 printf (" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)")); 924 printf (" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)"));
876 printf (" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION"); 925 printf (" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION");
877 printf (" %s\n", _("Regular expression for path or partition (may be repeated)")); 926 printf (" %s\n", _("Regular expression for path or partition (may be repeated)"));
927 printf (" %s\n", "-I, --ignore-eregi-path=PATH, --ignore-eregi-partition=PARTITION");
928 printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
929 printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION");
930 printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
878 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 931 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
879 printf (" %s\n", "-u, --units=STRING"); 932 printf (" %s\n", "-u, --units=STRING");
880 printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)")); 933 printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));