summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_disk.c70
1 files changed, 59 insertions, 11 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 512344d..960902f 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -64,6 +64,7 @@ struct name_list
64{ 64{
65 char *name; 65 char *name;
66 int found; 66 int found;
67 int found_len;
67 uintmax_t w_df; 68 uintmax_t w_df;
68 uintmax_t c_df; 69 uintmax_t c_df;
69 double w_dfp; 70 double w_dfp;
@@ -166,26 +167,56 @@ main (int argc, char **argv)
166 if (process_arguments (argc, argv) == ERROR) 167 if (process_arguments (argc, argv) == ERROR)
167 usage4 (_("Could not parse arguments")); 168 usage4 (_("Could not parse arguments"));
168 169
169 for (me = mount_list; me; me = me->me_next) { 170 /* if a list of paths has been selected, preseed the list with
171 * the longest matching filesystem name by iterating across
172 * the mountlist once ahead of time. this will allow a query on
173 * "/var/log" to return information about "/var" if no "/var/log"
174 * filesystem exists, etc. this is the default behavior already
175 * with df-based checks, but for systems with their own space
176 * checking routines, this should make them more consistent.
177 */
178 if(path_select_list){
179 for (me = mount_list; me; me = me->me_next) {
180 walk_name_list(path_select_list, me->me_mountdir);
181 walk_name_list(path_select_list, me->me_devname);
182 }
183 /* now pretend we never saw anything, but keep found_len.
184 * thus future searches will only match the best match */
185 for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next){
186 temp_list->found=0;
187 }
188 }
170 189
190 /* for every mount entry */
191 for (me = mount_list; me; me = me->me_next) {
192 /* if there's a list of paths to select, the current mount
193 * entry matches in path or device name, get fs usage */
171 if (path_select_list && 194 if (path_select_list &&
172 (walk_name_list (path_select_list, me->me_mountdir) || 195 (walk_name_list (path_select_list, me->me_mountdir) ||
173 walk_name_list (path_select_list, me->me_devname) ) ) 196 walk_name_list (path_select_list, me->me_devname) ) ) {
174 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 197 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
175 else if (dev_select_list || path_select_list) 198 /* else if there's a list of paths/devices to select (but
199 * we didn't match above) skip to the next mount entry */
200 } else if (dev_select_list || path_select_list) {
176 continue; 201 continue;
177 else if (me->me_remote && show_local_fs) 202 /* skip remote filesystems if we're not interested in them */
203 } else if (me->me_remote && show_local_fs) {
178 continue; 204 continue;
179 else if (me->me_dummy && !show_all_fs) 205 /* skip pseudo fs's if we haven't asked for all fs's */
206 } else if (me->me_dummy && !show_all_fs) {
180 continue; 207 continue;
181 else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) 208 /* skip excluded fstypes */
209 } else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) {
182 continue; 210 continue;
183 else if (dp_exclude_list && 211 /* skip excluded fs's */
212 } else if (dp_exclude_list &&
184 (walk_name_list (dp_exclude_list, me->me_devname) || 213 (walk_name_list (dp_exclude_list, me->me_devname) ||
185 walk_name_list (dp_exclude_list, me->me_mountdir))) 214 walk_name_list (dp_exclude_list, me->me_mountdir))) {
186 continue; 215 continue;
187 else 216 /* otherwise, get fs usage */
217 } else {
188 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 218 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
219 }
189 220
190 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { 221 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
191 usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; 222 usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks;
@@ -229,7 +260,7 @@ main (int argc, char **argv)
229 /* Override result if paths specified and not found */ 260 /* Override result if paths specified and not found */
230 temp_list = path_select_list; 261 temp_list = path_select_list;
231 while (temp_list) { 262 while (temp_list) {
232 if (temp_list->found != TRUE) { 263 if (!temp_list->found) {
233 asprintf (&output, _("%s [%s not found]"), output, temp_list->name); 264 asprintf (&output, _("%s [%s not found]"), output, temp_list->name);
234 result = STATE_CRITICAL; 265 result = STATE_CRITICAL;
235 } 266 }
@@ -285,6 +316,8 @@ process_arguments (int argc, char **argv)
285 se = (struct name_list *) malloc (sizeof (struct name_list)); 316 se = (struct name_list *) malloc (sizeof (struct name_list));
286 se->name = strdup ("iso9660"); 317 se->name = strdup ("iso9660");
287 se->name_next = NULL; 318 se->name_next = NULL;
319 se->found = 0;
320 se->found_len = 0;
288 *fstail = se; 321 *fstail = se;
289 fstail = &se->name_next; 322 fstail = &se->name_next;
290 323
@@ -388,6 +421,8 @@ process_arguments (int argc, char **argv)
388 se->c_df = c_df; 421 se->c_df = c_df;
389 se->w_dfp = w_dfp; 422 se->w_dfp = w_dfp;
390 se->c_dfp = c_dfp; 423 se->c_dfp = c_dfp;
424 se->found = 0;
425 se->found_len = 0;
391 *pathtail = se; 426 *pathtail = se;
392 pathtail = &se->name_next; 427 pathtail = &se->name_next;
393 break; 428 break;
@@ -399,6 +434,8 @@ process_arguments (int argc, char **argv)
399 se->c_df = 0; 434 se->c_df = 0;
400 se->w_dfp = -1.0; 435 se->w_dfp = -1.0;
401 se->c_dfp = -1.0; 436 se->c_dfp = -1.0;
437 se->found = 0;
438 se->found_len = 0;
402 *dptail = se; 439 *dptail = se;
403 dptail = &se->name_next; 440 dptail = &se->name_next;
404 break; 441 break;
@@ -410,6 +447,8 @@ process_arguments (int argc, char **argv)
410 se->c_df = 0; 447 se->c_df = 0;
411 se->w_dfp = -1.0; 448 se->w_dfp = -1.0;
412 se->c_dfp = -1.0; 449 se->c_dfp = -1.0;
450 se->found = 0;
451 se->found_len = 0;
413 *fstail = se; 452 *fstail = se;
414 fstail = &se->name_next; 453 fstail = &se->name_next;
415 break; 454 break;
@@ -458,6 +497,8 @@ process_arguments (int argc, char **argv)
458 se->c_df = c_df; 497 se->c_df = c_df;
459 se->w_dfp = w_dfp; 498 se->w_dfp = w_dfp;
460 se->c_dfp = c_dfp; 499 se->c_dfp = c_dfp;
500 se->found =0;
501 se->found_len = 0;
461 *pathtail = se; 502 *pathtail = se;
462 } 503 }
463 504
@@ -549,9 +590,16 @@ check_disk (double usp, double free_disk)
549int 590int
550walk_name_list (struct name_list *list, const char *name) 591walk_name_list (struct name_list *list, const char *name)
551{ 592{
593 int name_len;
594 name_len = strlen(name);
552 while (list) { 595 while (list) {
553 if (! strcmp(list->name, name)) { 596 /* if the paths match up to the length of the mount path,
597 * AND if the mount path name is longer than the longest
598 * found match, we have a new winner */
599 if (name_len >= list->found_len &&
600 ! strncmp(list->name, name, name_len)) {
554 list->found = 1; 601 list->found = 1;
602 list->found_len = name_len;
555 /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */ 603 /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */
556 if (list->w_df) w_df = list->w_df; 604 if (list->w_df) w_df = list->w_df;
557 if (list->c_df) c_df = list->c_df; 605 if (list->c_df) c_df = list->c_df;