diff options
author | Matthias Eble <psychotrahe@users.sourceforge.net> | 2007-03-30 08:53:58 +0000 |
---|---|---|
committer | Matthias Eble <psychotrahe@users.sourceforge.net> | 2007-03-30 08:53:58 +0000 |
commit | 0f71b7d07a8badd9aa38ef8d847bd982ab2db72c (patch) | |
tree | fba1316686bdb6f891ac92ba67f4c3e4e4dc7940 /plugins/check_disk.c | |
parent | 0ff58b90631e9b62da23c4c9487d3d8d310f2d7f (diff) | |
download | monitoring-plugins-0f71b7d07a8badd9aa38ef8d847bd982ab2db72c.tar.gz |
check_disk: added regex functionality -r and -R. see np-devel mail (2007-02-10)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1658 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r-- | plugins/check_disk.c | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 10095648..2b12e56c 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -56,6 +56,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
56 | #if HAVE_LIMITS_H | 56 | #if HAVE_LIMITS_H |
57 | # include <limits.h> | 57 | # include <limits.h> |
58 | #endif | 58 | #endif |
59 | #include "regex.h" | ||
59 | 60 | ||
60 | 61 | ||
61 | /* If nonzero, show inode information. */ | 62 | /* If nonzero, show inode information. */ |
@@ -437,11 +438,16 @@ double calculate_percent(uintmax_t value, uintmax_t total) { | |||
437 | int | 438 | int |
438 | process_arguments (int argc, char **argv) | 439 | process_arguments (int argc, char **argv) |
439 | { | 440 | { |
440 | int c; | 441 | int c, err; |
441 | struct parameter_list *se; | 442 | struct parameter_list *se; |
442 | struct parameter_list *temp_list; | 443 | struct parameter_list *temp_list; |
444 | struct mount_entry *me; | ||
443 | int result = OK; | 445 | int result = OK; |
444 | struct stat *stat_buf; | 446 | struct stat *stat_buf; |
447 | regex_t re; | ||
448 | int cflags = REG_NOSUB | REG_EXTENDED; | ||
449 | char errbuf[MAX_INPUT_BUFFER]; | ||
450 | bool fnd = false; | ||
445 | 451 | ||
446 | int option = 0; | 452 | int option = 0; |
447 | static struct option longopts[] = { | 453 | static struct option longopts[] = { |
@@ -460,6 +466,10 @@ process_arguments (int argc, char **argv) | |||
460 | {"exclude_device", required_argument, 0, 'x'}, | 466 | {"exclude_device", required_argument, 0, 'x'}, |
461 | {"exclude-type", required_argument, 0, 'X'}, | 467 | {"exclude-type", required_argument, 0, 'X'}, |
462 | {"group", required_argument, 0, 'g'}, | 468 | {"group", required_argument, 0, 'g'}, |
469 | {"eregi-path", required_argument, 0, 'R'}, | ||
470 | {"eregi-partition", required_argument, 0, 'R'}, | ||
471 | {"ereg-path", required_argument, 0, 'r'}, | ||
472 | {"ereg-partition", required_argument, 0, 'r'}, | ||
463 | {"mountpoint", no_argument, 0, 'M'}, | 473 | {"mountpoint", no_argument, 0, 'M'}, |
464 | {"errors-only", no_argument, 0, 'e'}, | 474 | {"errors-only", no_argument, 0, 'e'}, |
465 | {"exact-match", no_argument, 0, 'E'}, | 475 | {"exact-match", no_argument, 0, 'E'}, |
@@ -481,7 +491,7 @@ process_arguments (int argc, char **argv) | |||
481 | strcpy (argv[c], "-t"); | 491 | strcpy (argv[c], "-t"); |
482 | 492 | ||
483 | while (1) { | 493 | while (1) { |
484 | c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:ME", longopts, &option); | 494 | c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:R:r:ME", longopts, &option); |
485 | 495 | ||
486 | if (c == -1 || c == EOF) | 496 | if (c == -1 || c == EOF) |
487 | break; | 497 | break; |
@@ -626,6 +636,44 @@ process_arguments (int argc, char **argv) | |||
626 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before using -p\n")); | 636 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before using -p\n")); |
627 | group = optarg; | 637 | group = optarg; |
628 | break; | 638 | break; |
639 | case 'R': | ||
640 | cflags |= REG_ICASE; | ||
641 | case 'r': | ||
642 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || | ||
643 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || | ||
644 | warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent || | ||
645 | crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) { | ||
646 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -r/-R\n")); | ||
647 | } | ||
648 | |||
649 | err = regcomp(&re, optarg, cflags); | ||
650 | if (err != 0) { | ||
651 | regerror (err, &re, errbuf, MAX_INPUT_BUFFER); | ||
652 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf); | ||
653 | } | ||
654 | |||
655 | for (me = mount_list; me; me = me->me_next) { | ||
656 | if (np_regex_match_mount_entry(me, &re)) { | ||
657 | fnd = true; | ||
658 | if (verbose > 3) | ||
659 | printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg); | ||
660 | |||
661 | /* add parameter if not found. overwrite thresholds if path has already been added */ | ||
662 | if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) { | ||
663 | se = np_add_parameter(&path_select_list, me->me_mountdir); | ||
664 | } | ||
665 | se->group = group; | ||
666 | set_all_thresholds(se); | ||
667 | } | ||
668 | } | ||
669 | |||
670 | if (!fnd) | ||
671 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), | ||
672 | _("Regular expression did not match any path or disk"), optarg); | ||
673 | |||
674 | fnd = false; | ||
675 | path_selected = true; | ||
676 | break; | ||
629 | case 'M': /* display mountpoint */ | 677 | case 'M': /* display mountpoint */ |
630 | display_mntp = TRUE; | 678 | display_mntp = TRUE; |
631 | break; | 679 | break; |
@@ -824,6 +872,10 @@ print_help (void) | |||
824 | printf (" %s\n", _("Only check local filesystems")); | 872 | printf (" %s\n", _("Only check local filesystems")); |
825 | printf (" %s\n", "-p, --path=PATH, --partition=PARTITION"); | 873 | printf (" %s\n", "-p, --path=PATH, --partition=PARTITION"); |
826 | printf (" %s\n", _("Path or partition (may be repeated)")); | 874 | printf (" %s\n", _("Path or partition (may be repeated)")); |
875 | printf (" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION"); | ||
876 | printf (" %s\n", _("Regular expression for path or partition (may be repeated)")); | ||
877 | printf (" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION"); | ||
878 | printf (" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)")); | ||
827 | printf (" %s\n", "-g, --group=NAME"); | 879 | printf (" %s\n", "-g, --group=NAME"); |
828 | printf (" %s\n", _("Group pathes. Thresholds apply to (free-)space of all partitions together")); | 880 | printf (" %s\n", _("Group pathes. Thresholds apply to (free-)space of all partitions together")); |
829 | printf (" %s\n", "-x, --exclude_device=PATH <STRING>"); | 881 | printf (" %s\n", "-x, --exclude_device=PATH <STRING>"); |