summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/utils_disk.c59
-rw-r--r--lib/utils_disk.h1
-rw-r--r--plugins/check_disk.c82
3 files changed, 90 insertions, 52 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index 74708c0..fd768b2 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -73,39 +73,54 @@ np_add_parameter(struct parameter_list **list, const char *name)
73 return new_path; 73 return new_path;
74} 74}
75 75
76/* returns a pointer to the struct found in the list */
77struct parameter_list *
78np_find_parameter(struct parameter_list *list, const char *name)
79{
80 struct parameter_list *temp_list;
81 for (temp_list = list; temp_list; temp_list = temp_list->name_next) {
82 if (! strcmp(temp_list->name, name))
83 return temp_list;
84 }
85
86 return NULL;
87}
88
76void 89void
77np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact) 90np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
78{ 91{
79 struct parameter_list *d; 92 struct parameter_list *d;
80 for (d = desired; d; d= d->name_next) { 93 for (d = desired; d; d= d->name_next) {
81 struct mount_entry *me; 94 if (! d->best_match) {
82 size_t name_len = strlen(d->name); 95 struct mount_entry *me;
83 size_t best_match_len = 0; 96 size_t name_len = strlen(d->name);
84 struct mount_entry *best_match = NULL; 97 size_t best_match_len = 0;
98 struct mount_entry *best_match = NULL;
85 99
86 for (me = mount_list; me; me = me->me_next) { 100 for (me = mount_list; me; me = me->me_next) {
87 size_t len = strlen (me->me_mountdir); 101 size_t len = strlen (me->me_mountdir);
88 if ((exact == FALSE && (best_match_len <= len && len <= name_len && 102 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
89 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) 103 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
90 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) 104 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
91 {
92 best_match = me;
93 best_match_len = len;
94 } else {
95 len = strlen (me->me_devname);
96 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
97 (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
98 || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
99 { 105 {
100 best_match = me; 106 best_match = me;
101 best_match_len = len; 107 best_match_len = len;
108 } else {
109 len = strlen (me->me_devname);
110 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
111 (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
112 || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
113 {
114 best_match = me;
115 best_match_len = len;
116 }
102 } 117 }
103 } 118 }
104 } 119 if (best_match) {
105 if (best_match) { 120 d->best_match = best_match;
106 d->best_match = best_match; 121 } else {
107 } else { 122 d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
108 d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ 123 }
109 } 124 }
110 } 125 }
111} 126}
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 8bf4f11..55de938 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -28,5 +28,6 @@ void np_add_name (struct name_list **list, const char *name);
28int np_find_name (struct name_list *list, const char *name); 28int np_find_name (struct name_list *list, const char *name);
29int np_seen_name (struct name_list *list, const char *name); 29int np_seen_name (struct name_list *list, const char *name);
30struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); 30struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
31struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name);
31int search_parameter_list (struct parameter_list *list, const char *name); 32int search_parameter_list (struct parameter_list *list, const char *name);
32void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact); 33void 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 88a1769..7bd044a 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -121,6 +121,7 @@ static struct mount_entry *mount_list;
121 121
122int process_arguments (int, char **); 122int process_arguments (int, char **);
123void print_path (const char *mypath); 123void print_path (const char *mypath);
124void set_all_thresholds (struct parameter_list *path);
124int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *); 125int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
125void print_help (void); 126void print_help (void);
126void print_usage (void); 127void print_usage (void);
@@ -148,6 +149,7 @@ char *warn_usedinodes_percent = NULL;
148char *crit_usedinodes_percent = NULL; 149char *crit_usedinodes_percent = NULL;
149char *warn_freeinodes_percent = NULL; 150char *warn_freeinodes_percent = NULL;
150char *crit_freeinodes_percent = NULL; 151char *crit_freeinodes_percent = NULL;
152bool path_selected = false;
151 153
152 154
153int 155int
@@ -190,33 +192,34 @@ main (int argc, char **argv)
190 /* If a list of paths has not been selected, find entire 192 /* If a list of paths has not been selected, find entire
191 mount list and create list of paths 193 mount list and create list of paths
192 */ 194 */
193 if (! path_select_list) { 195 if (path_selected == false) {
194 for (me = mount_list; me; me = me->me_next) { 196 for (me = mount_list; me; me = me->me_next) {
195 path = np_add_parameter(&path_select_list, me->me_mountdir); 197 if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
198 path = np_add_parameter(&path_select_list, me->me_mountdir);
199 }
196 path->best_match = me; 200 path->best_match = me;
197 set_thresholds(&path->freespace_units, warn_freespace_units, crit_freespace_units); 201 set_all_thresholds(path);
198 set_thresholds(&path->freespace_percent, warn_freespace_percent, crit_freespace_percent);
199 set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units);
200 set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
201 set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
202 set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
203 } 202 }
204 } else { 203 }
205 np_set_best_match(path_select_list, mount_list, exact_match); 204 np_set_best_match(path_select_list, mount_list, exact_match);
206 205
207 /* Error if no match found for specified paths */ 206 /* Error if no match found for specified paths */
208 temp_list = path_select_list; 207 temp_list = path_select_list;
209 while (temp_list) { 208 while (temp_list) {
210 if (! temp_list->best_match) { 209 if (! temp_list->best_match) {
211 die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name); 210 die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
212 }
213 temp_list = temp_list->name_next;
214 } 211 }
212 temp_list = temp_list->name_next;
215 } 213 }
214
216 215
217 /* Process for every path in list */ 216 /* Process for every path in list */
218 for (path = path_select_list; path; path=path->name_next) { 217 for (path = path_select_list; path; path=path->name_next) {
219 218
219 if (verbose > 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL)
220 printf("Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end,
221 path->freespace_percent->critical->end);
222
220 /* reset disk result */ 223 /* reset disk result */
221 disk_result = STATE_UNKNOWN; 224 disk_result = STATE_UNKNOWN;
222 225
@@ -548,13 +551,14 @@ process_arguments (int argc, char **argv)
548 crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) { 551 crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
549 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n")); 552 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
550 } 553 }
551 se = np_add_parameter(&path_select_list, optarg); 554
552 set_thresholds(&se->freespace_units, warn_freespace_units, crit_freespace_units); 555 /* add parameter if not found. overwrite thresholds if path has already been added */
553 set_thresholds(&se->freespace_percent, warn_freespace_percent, crit_freespace_percent); 556 if (! (se = np_find_parameter(path_select_list, optarg))) {
554 set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units); 557 se = np_add_parameter(&path_select_list, optarg);
555 set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent); 558 }
556 set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent); 559
557 set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent); 560 set_all_thresholds(se);
561 path_selected = true;
558 break; 562 break;
559 case 'x': /* exclude path or partition */ 563 case 'x': /* exclude path or partition */
560 np_add_name(&dp_exclude_list, optarg); 564 np_add_name(&dp_exclude_list, optarg);
@@ -578,6 +582,17 @@ process_arguments (int argc, char **argv)
578 display_mntp = TRUE; 582 display_mntp = TRUE;
579 break; 583 break;
580 case 'C': 584 case 'C':
585 /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */
586 if (path_selected == false) {
587 struct mount_entry *me;
588 struct parameter_list *path;
589 for (me = mount_list; me; me = me->me_next) {
590 if (! (path = np_find_parameter(path_select_list, me->me_mountdir)))
591 path = np_add_parameter(&path_select_list, me->me_mountdir);
592 path->best_match = me;
593 set_all_thresholds(path);
594 }
595 }
581 warn_freespace_units = NULL; 596 warn_freespace_units = NULL;
582 crit_freespace_units = NULL; 597 crit_freespace_units = NULL;
583 warn_usedspace_units = NULL; 598 warn_usedspace_units = NULL;
@@ -590,6 +605,8 @@ process_arguments (int argc, char **argv)
590 crit_usedinodes_percent = NULL; 605 crit_usedinodes_percent = NULL;
591 warn_freeinodes_percent = NULL; 606 warn_freeinodes_percent = NULL;
592 crit_freeinodes_percent = NULL; 607 crit_freeinodes_percent = NULL;
608
609 path_selected = false;
593 break; 610 break;
594 case 'V': /* version */ 611 case 'V': /* version */
595 print_revision (progname, revision); 612 print_revision (progname, revision);
@@ -612,12 +629,7 @@ process_arguments (int argc, char **argv)
612 629
613 if (argc > c && path == NULL) { 630 if (argc > c && path == NULL) {
614 se = np_add_parameter(&path_select_list, strdup(argv[c++])); 631 se = np_add_parameter(&path_select_list, strdup(argv[c++]));
615 set_thresholds(&se->freespace_units, warn_freespace_units, crit_freespace_units); 632 set_all_thresholds(se);
616 set_thresholds(&se->freespace_percent, warn_freespace_percent, crit_freespace_percent);
617 set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units);
618 set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
619 set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
620 set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
621 } 633 }
622 634
623 if (units == NULL) { 635 if (units == NULL) {
@@ -665,6 +677,16 @@ print_path (const char *mypath)
665} 677}
666 678
667 679
680void
681set_all_thresholds (struct parameter_list *path)
682{
683 set_thresholds(&path->freespace_units, warn_freespace_units, crit_freespace_units);
684 set_thresholds(&path->freespace_percent, warn_freespace_percent, crit_freespace_percent);
685 set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units);
686 set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
687 set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
688 set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
689}
668 690
669/* TODO: Remove? 691/* TODO: Remove?
670 692