summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0ff58b9)
raw | patch | inline | side by side (parent: 0ff58b9)
author | Matthias Eble <psychotrahe@users.sourceforge.net> | |
Fri, 30 Mar 2007 08:53:58 +0000 (08:53 +0000) | ||
committer | Matthias Eble <psychotrahe@users.sourceforge.net> | |
Fri, 30 Mar 2007 08:53:58 +0000 (08:53 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1658 f882894a-f735-0410-b71e-b25c423dba1c
lib/utils_disk.c | patch | blob | history | |
lib/utils_disk.h | patch | blob | history | |
plugins/check_disk.c | patch | blob | history |
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index 877b80d91ed52db61bf2181aa84864da128cb52b..cfd6a97968edb716f26f1e69ecc29e91ea826e08 100644 (file)
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
return FALSE;
}
+int
+np_regex_match_mount_entry (struct mount_entry* me, regex_t* re)
+{
+ if (regexec(re, me->me_devname, (size_t) 0, NULL, 0) == 0 ||
+ regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) {
+ return true;
+ } else {
+ return false;
+ }
+}
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 331c16d7d675e3169ad8a6684f745256a40549ad..6263339f4da98faee8480a7db838c2b142b9b3c7 100644 (file)
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
#include "mountlist.h"
#include "utils_base.h"
+#include "regex.h"
struct name_list
{
struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name);
int search_parameter_list (struct parameter_list *list, const char *name);
void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact);
+int np_regex_match_mount_entry (struct mount_entry* me, regex_t* re);
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 10095648f3bd9d14652056cedbd2e435dfbcca0e..2b12e56c6541bb9bcf4c644260129fafe6dda8aa 100644 (file)
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
#if HAVE_LIMITS_H
# include <limits.h>
#endif
+#include "regex.h"
/* If nonzero, show inode information. */
int
process_arguments (int argc, char **argv)
{
- int c;
+ int c, err;
struct parameter_list *se;
struct parameter_list *temp_list;
+ struct mount_entry *me;
int result = OK;
struct stat *stat_buf;
+ regex_t re;
+ int cflags = REG_NOSUB | REG_EXTENDED;
+ char errbuf[MAX_INPUT_BUFFER];
+ bool fnd = false;
int option = 0;
static struct option longopts[] = {
{"exclude_device", required_argument, 0, 'x'},
{"exclude-type", required_argument, 0, 'X'},
{"group", required_argument, 0, 'g'},
+ {"eregi-path", required_argument, 0, 'R'},
+ {"eregi-partition", required_argument, 0, 'R'},
+ {"ereg-path", required_argument, 0, 'r'},
+ {"ereg-partition", required_argument, 0, 'r'},
{"mountpoint", no_argument, 0, 'M'},
{"errors-only", no_argument, 0, 'e'},
{"exact-match", no_argument, 0, 'E'},
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:ME", longopts, &option);
+ c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:R:r:ME", longopts, &option);
if (c == -1 || c == EOF)
break;
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before using -p\n"));
group = optarg;
break;
+ case 'R':
+ cflags |= REG_ICASE;
+ case 'r':
+ if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
+ crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
+ warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent ||
+ crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
+ die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -r/-R\n"));
+ }
+
+ err = regcomp(&re, optarg, cflags);
+ if (err != 0) {
+ regerror (err, &re, errbuf, MAX_INPUT_BUFFER);
+ die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
+ }
+
+ for (me = mount_list; me; me = me->me_next) {
+ if (np_regex_match_mount_entry(me, &re)) {
+ fnd = true;
+ if (verbose > 3)
+ printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
+
+ /* add parameter if not found. overwrite thresholds if path has already been added */
+ if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) {
+ se = np_add_parameter(&path_select_list, me->me_mountdir);
+ }
+ se->group = group;
+ set_all_thresholds(se);
+ }
+ }
+
+ if (!fnd)
+ die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"),
+ _("Regular expression did not match any path or disk"), optarg);
+
+ fnd = false;
+ path_selected = true;
+ break;
case 'M': /* display mountpoint */
display_mntp = TRUE;
break;
printf (" %s\n", _("Only check local filesystems"));
printf (" %s\n", "-p, --path=PATH, --partition=PARTITION");
printf (" %s\n", _("Path or partition (may be repeated)"));
+ printf (" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION");
+ printf (" %s\n", _("Regular expression for path or partition (may be repeated)"));
+ printf (" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION");
+ printf (" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)"));
printf (" %s\n", "-g, --group=NAME");
printf (" %s\n", _("Group pathes. Thresholds apply to (free-)space of all partitions together"));
printf (" %s\n", "-x, --exclude_device=PATH <STRING>");