summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b809d23)
raw | patch | inline | side by side (parent: b809d23)
author | Matthias Eble <psychotrahe@users.sourceforge.net> | |
Fri, 30 Mar 2007 08:48:50 +0000 (08:48 +0000) | ||
committer | Matthias Eble <psychotrahe@users.sourceforge.net> | |
Fri, 30 Mar 2007 08:48:50 +0000 (08:48 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1656 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 74708c0e3a2807200c2c4c0829dc981b166396fe..fd768b20d09c7b356075f7e5f62e5b86a69941af 100644 (file)
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
return new_path;
}
+/* returns a pointer to the struct found in the list */
+struct parameter_list *
+np_find_parameter(struct parameter_list *list, const char *name)
+{
+ struct parameter_list *temp_list;
+ for (temp_list = list; temp_list; temp_list = temp_list->name_next) {
+ if (! strcmp(temp_list->name, name))
+ return temp_list;
+ }
+
+ return NULL;
+}
+
void
np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
{
struct parameter_list *d;
for (d = desired; d; d= d->name_next) {
- struct mount_entry *me;
- size_t name_len = strlen(d->name);
- size_t best_match_len = 0;
- struct mount_entry *best_match = NULL;
+ if (! d->best_match) {
+ struct mount_entry *me;
+ size_t name_len = strlen(d->name);
+ size_t best_match_len = 0;
+ struct mount_entry *best_match = NULL;
- for (me = mount_list; me; me = me->me_next) {
- size_t len = strlen (me->me_mountdir);
- if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
- (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
- || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
- {
- best_match = me;
- best_match_len = len;
- } else {
- len = strlen (me->me_devname);
- if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
- (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
- || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
+ for (me = mount_list; me; me = me->me_next) {
+ size_t len = strlen (me->me_mountdir);
+ if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
+ (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
+ || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
{
best_match = me;
best_match_len = len;
+ } else {
+ len = strlen (me->me_devname);
+ if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
+ (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
+ || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
+ {
+ best_match = me;
+ best_match_len = len;
+ }
}
}
- }
- if (best_match) {
- d->best_match = best_match;
- } else {
- d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
+ if (best_match) {
+ d->best_match = best_match;
+ } else {
+ d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
+ }
}
}
}
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 8bf4f113b989b02b9ec27cf63253fac8d66dd26d..55de9385d7bacb2e6a1fc2da56779ef213437133 100644 (file)
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
int np_find_name (struct name_list *list, const char *name);
int np_seen_name (struct name_list *list, const char *name);
struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
+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);
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 88a176926f1454b82697d667e93c4599f9f766bc..7bd044adf6dc046fe2dd460164bbd3ed3cb9abba 100644 (file)
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
int process_arguments (int, char **);
void print_path (const char *mypath);
+void set_all_thresholds (struct parameter_list *path);
int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
void print_help (void);
void print_usage (void);
char *crit_usedinodes_percent = NULL;
char *warn_freeinodes_percent = NULL;
char *crit_freeinodes_percent = NULL;
+bool path_selected = false;
int
/* If a list of paths has not been selected, find entire
mount list and create list of paths
*/
- if (! path_select_list) {
+ if (path_selected == false) {
for (me = mount_list; me; me = me->me_next) {
- path = np_add_parameter(&path_select_list, me->me_mountdir);
+ if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
+ path = np_add_parameter(&path_select_list, me->me_mountdir);
+ }
path->best_match = me;
- set_thresholds(&path->freespace_units, warn_freespace_units, crit_freespace_units);
- set_thresholds(&path->freespace_percent, warn_freespace_percent, crit_freespace_percent);
- set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units);
- set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
- set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
- set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
+ set_all_thresholds(path);
}
- } else {
- np_set_best_match(path_select_list, mount_list, exact_match);
+ }
+ np_set_best_match(path_select_list, mount_list, exact_match);
- /* Error if no match found for specified paths */
- temp_list = path_select_list;
- while (temp_list) {
- if (! temp_list->best_match) {
- die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
- }
- temp_list = temp_list->name_next;
+ /* Error if no match found for specified paths */
+ temp_list = path_select_list;
+ while (temp_list) {
+ if (! temp_list->best_match) {
+ die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
}
+ temp_list = temp_list->name_next;
}
+
/* Process for every path in list */
for (path = path_select_list; path; path=path->name_next) {
+ if (verbose > 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL)
+ printf("Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end,
+ path->freespace_percent->critical->end);
+
/* reset disk result */
disk_result = STATE_UNKNOWN;
crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
}
- se = np_add_parameter(&path_select_list, optarg);
- set_thresholds(&se->freespace_units, warn_freespace_units, crit_freespace_units);
- set_thresholds(&se->freespace_percent, warn_freespace_percent, crit_freespace_percent);
- set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units);
- set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
- set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
- set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
+
+ /* add parameter if not found. overwrite thresholds if path has already been added */
+ if (! (se = np_find_parameter(path_select_list, optarg))) {
+ se = np_add_parameter(&path_select_list, optarg);
+ }
+
+ set_all_thresholds(se);
+ path_selected = true;
break;
case 'x': /* exclude path or partition */
np_add_name(&dp_exclude_list, optarg);
display_mntp = TRUE;
break;
case 'C':
+ /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */
+ if (path_selected == false) {
+ struct mount_entry *me;
+ struct parameter_list *path;
+ for (me = mount_list; me; me = me->me_next) {
+ if (! (path = np_find_parameter(path_select_list, me->me_mountdir)))
+ path = np_add_parameter(&path_select_list, me->me_mountdir);
+ path->best_match = me;
+ set_all_thresholds(path);
+ }
+ }
warn_freespace_units = NULL;
crit_freespace_units = NULL;
warn_usedspace_units = NULL;
crit_usedinodes_percent = NULL;
warn_freeinodes_percent = NULL;
crit_freeinodes_percent = NULL;
+
+ path_selected = false;
break;
case 'V': /* version */
print_revision (progname, revision);
if (argc > c && path == NULL) {
se = np_add_parameter(&path_select_list, strdup(argv[c++]));
- set_thresholds(&se->freespace_units, warn_freespace_units, crit_freespace_units);
- set_thresholds(&se->freespace_percent, warn_freespace_percent, crit_freespace_percent);
- set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units);
- set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
- set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
- set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
+ set_all_thresholds(se);
}
if (units == NULL) {
}
+void
+set_all_thresholds (struct parameter_list *path)
+{
+ set_thresholds(&path->freespace_units, warn_freespace_units, crit_freespace_units);
+ set_thresholds(&path->freespace_percent, warn_freespace_percent, crit_freespace_percent);
+ set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units);
+ set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
+ set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
+ set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
+}
/* TODO: Remove?