summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_disk.c92
1 files changed, 72 insertions, 20 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 7bd044a..1009564 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -150,6 +150,7 @@ char *crit_usedinodes_percent = NULL;
150char *warn_freeinodes_percent = NULL; 150char *warn_freeinodes_percent = NULL;
151char *crit_freeinodes_percent = NULL; 151char *crit_freeinodes_percent = NULL;
152bool path_selected = false; 152bool path_selected = false;
153char *group = NULL;
153 154
154 155
155int 156int
@@ -171,7 +172,7 @@ main (int argc, char **argv)
171 int temp_result; 172 int temp_result;
172 173
173 struct mount_entry *me; 174 struct mount_entry *me;
174 struct fs_usage fsp; 175 struct fs_usage fsp, tmpfsp;
175 struct parameter_list *temp_list, *path; 176 struct parameter_list *temp_list, *path;
176 struct name_list *seen = NULL; 177 struct name_list *seen = NULL;
177 178
@@ -198,6 +199,7 @@ main (int argc, char **argv)
198 path = np_add_parameter(&path_select_list, me->me_mountdir); 199 path = np_add_parameter(&path_select_list, me->me_mountdir);
199 } 200 }
200 path->best_match = me; 201 path->best_match = me;
202 path->group = group;
201 set_all_thresholds(path); 203 set_all_thresholds(path);
202 } 204 }
203 } 205 }
@@ -220,6 +222,9 @@ main (int argc, char **argv)
220 printf("Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end, 222 printf("Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end,
221 path->freespace_percent->critical->end); 223 path->freespace_percent->critical->end);
222 224
225 if (verbose > 3 && path->group != NULL)
226 printf("Group of %s: %s\n",path->name,path->group);
227
223 /* reset disk result */ 228 /* reset disk result */
224 disk_result = STATE_UNKNOWN; 229 disk_result = STATE_UNKNOWN;
225 230
@@ -231,25 +236,62 @@ main (int argc, char **argv)
231 if (np_seen_name(seen, me->me_mountdir)) { 236 if (np_seen_name(seen, me->me_mountdir)) {
232 continue; 237 continue;
233 } else { 238 } else {
234 np_add_name(&seen, me->me_mountdir); 239 if (path->group != NULL) {
235 } 240 /* find all group members */
236 /* Skip remote filesystems if we're not interested in them */ 241 fsp.fsu_blocksize = 0;
237 if (me->me_remote && show_local_fs) { 242 fsp.fsu_blocks = 0;
238 continue; 243 fsp.fsu_bfree = 0;
239 /* Skip pseudo fs's if we haven't asked for all fs's */ 244 fsp.fsu_bavail = 0;
240 } else if (me->me_dummy && !show_all_fs) { 245 fsp.fsu_files = 0;
241 continue; 246 fsp.fsu_ffree = 0;
242 /* Skip excluded fstypes */ 247
243 } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) { 248
244 continue; 249 for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next) {
245 /* Skip excluded fs's */ 250 if (temp_list->group && ! (strcmp(temp_list->group, path->group))) {
246 } else if (dp_exclude_list && 251
247 (np_find_name (dp_exclude_list, me->me_devname) || 252 get_fs_usage (temp_list->best_match->me_mountdir, temp_list->best_match->me_devname, &tmpfsp);
248 np_find_name (dp_exclude_list, me->me_mountdir))) { 253
249 continue; 254 /* possibly differing blocksizes if disks are grouped. Calculating average */
255 fsp.fsu_blocksize = (fsp.fsu_blocksize * fsp.fsu_blocks + tmpfsp.fsu_blocksize * tmpfsp.fsu_blocks) / \
256 (fsp.fsu_blocks + tmpfsp.fsu_blocks); /* Size of a block. */
257 fsp.fsu_blocks += tmpfsp.fsu_blocks; /* Total blocks. */
258 fsp.fsu_bfree += tmpfsp.fsu_bfree; /* Free blocks available to superuser. */
259 fsp.fsu_bavail += tmpfsp.fsu_bavail; /* Free blocks available to non-superuser. */
260 fsp.fsu_files += tmpfsp.fsu_files; /* Total file nodes. */
261 fsp.fsu_ffree += tmpfsp.fsu_ffree; /* Free file nodes. */
262
263 if (verbose > 3)
264 printf("Group %s: add %llu blocks (%s) \n", path->group, tmpfsp.fsu_bavail, temp_list->name);
265 // printf("Group %s: add %u blocks (%s)\n", temp_list->name); // path->group, tmpfsp.fsu_bavail, temp_list->name);
266
267 np_add_name(&seen, temp_list->best_match->me_mountdir);
268 }
269 }
270 /* modify devname and mountdir for output */
271 me->me_mountdir = me->me_devname = path->group;
272 } else
273 np_add_name(&seen, me->me_mountdir);
250 } 274 }
251 275
252 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 276 if (path->group == NULL) {
277 /* Skip remote filesystems if we're not interested in them */
278 if (me->me_remote && show_local_fs) {
279 continue;
280 /* Skip pseudo fs's if we haven't asked for all fs's */
281 } else if (me->me_dummy && !show_all_fs) {
282 continue;
283 /* Skip excluded fstypes */
284 } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) {
285 continue;
286 /* Skip excluded fs's */
287 } else if (dp_exclude_list &&
288 (np_find_name (dp_exclude_list, me->me_devname) ||
289 np_find_name (dp_exclude_list, me->me_mountdir))) {
290 continue;
291 }
292
293 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
294 }
253 295
254 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { 296 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
255 total = fsp.fsu_blocks; 297 total = fsp.fsu_blocks;
@@ -417,6 +459,7 @@ process_arguments (int argc, char **argv)
417 {"partition", required_argument, 0, 'p'}, 459 {"partition", required_argument, 0, 'p'},
418 {"exclude_device", required_argument, 0, 'x'}, 460 {"exclude_device", required_argument, 0, 'x'},
419 {"exclude-type", required_argument, 0, 'X'}, 461 {"exclude-type", required_argument, 0, 'X'},
462 {"group", required_argument, 0, 'g'},
420 {"mountpoint", no_argument, 0, 'M'}, 463 {"mountpoint", no_argument, 0, 'M'},
421 {"errors-only", no_argument, 0, 'e'}, 464 {"errors-only", no_argument, 0, 'e'},
422 {"exact-match", no_argument, 0, 'E'}, 465 {"exact-match", no_argument, 0, 'E'},
@@ -438,7 +481,7 @@ process_arguments (int argc, char **argv)
438 strcpy (argv[c], "-t"); 481 strcpy (argv[c], "-t");
439 482
440 while (1) { 483 while (1) {
441 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklME", longopts, &option); 484 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:ME", longopts, &option);
442 485
443 if (c == -1 || c == EOF) 486 if (c == -1 || c == EOF)
444 break; 487 break;
@@ -556,7 +599,7 @@ process_arguments (int argc, char **argv)
556 if (! (se = np_find_parameter(path_select_list, optarg))) { 599 if (! (se = np_find_parameter(path_select_list, optarg))) {
557 se = np_add_parameter(&path_select_list, optarg); 600 se = np_add_parameter(&path_select_list, optarg);
558 } 601 }
559 602 se->group = group;
560 set_all_thresholds(se); 603 set_all_thresholds(se);
561 path_selected = true; 604 path_selected = true;
562 break; 605 break;
@@ -578,6 +621,11 @@ process_arguments (int argc, char **argv)
578 case 'E': 621 case 'E':
579 exact_match = TRUE; 622 exact_match = TRUE;
580 break; 623 break;
624 case 'g':
625 if (path_selected)
626 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before using -p\n"));
627 group = optarg;
628 break;
581 case 'M': /* display mountpoint */ 629 case 'M': /* display mountpoint */
582 display_mntp = TRUE; 630 display_mntp = TRUE;
583 break; 631 break;
@@ -590,6 +638,7 @@ process_arguments (int argc, char **argv)
590 if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) 638 if (! (path = np_find_parameter(path_select_list, me->me_mountdir)))
591 path = np_add_parameter(&path_select_list, me->me_mountdir); 639 path = np_add_parameter(&path_select_list, me->me_mountdir);
592 path->best_match = me; 640 path->best_match = me;
641 path->group = group;
593 set_all_thresholds(path); 642 set_all_thresholds(path);
594 } 643 }
595 } 644 }
@@ -607,6 +656,7 @@ process_arguments (int argc, char **argv)
607 crit_freeinodes_percent = NULL; 656 crit_freeinodes_percent = NULL;
608 657
609 path_selected = false; 658 path_selected = false;
659 group = NULL;
610 break; 660 break;
611 case 'V': /* version */ 661 case 'V': /* version */
612 print_revision (progname, revision); 662 print_revision (progname, revision);
@@ -774,6 +824,8 @@ print_help (void)
774 printf (" %s\n", _("Only check local filesystems")); 824 printf (" %s\n", _("Only check local filesystems"));
775 printf (" %s\n", "-p, --path=PATH, --partition=PARTITION"); 825 printf (" %s\n", "-p, --path=PATH, --partition=PARTITION");
776 printf (" %s\n", _("Path or partition (may be repeated)")); 826 printf (" %s\n", _("Path or partition (may be repeated)"));
827 printf (" %s\n", "-g, --group=NAME");
828 printf (" %s\n", _("Group pathes. Thresholds apply to (free-)space of all partitions together"));
777 printf (" %s\n", "-x, --exclude_device=PATH <STRING>"); 829 printf (" %s\n", "-x, --exclude_device=PATH <STRING>");
778 printf (" %s\n", _("Ignore device (only works if -p unspecified)")); 830 printf (" %s\n", _("Ignore device (only works if -p unspecified)"));
779 printf (" %s\n", "-X, --exclude-type=TYPE <STRING>"); 831 printf (" %s\n", "-X, --exclude-type=TYPE <STRING>");