diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2023-03-10 10:33:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-10 10:33:25 (GMT) |
commit | 5077120a251980b4fafed61b4aa8fa5730a85443 (patch) | |
tree | 8500b8f5dbe774b399cfdc79f5665ba88ef7f255 /plugins/check_disk.c | |
parent | a3de84594104ac87a91e200d569fb57edacca928 (diff) | |
parent | 269718094177fb8a7e3d3005d1310495009fe8c4 (diff) | |
download | monitoring-plugins-5077120a251980b4fafed61b4aa8fa5730a85443.tar.gz |
Merge branch 'master' into master
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r-- | plugins/check_disk.c | 270 |
1 files changed, 120 insertions, 150 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 844e625..935acce 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -1,29 +1,29 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_disk plugin | 3 | * Monitoring check_disk plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2008 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2008 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_disk plugin | 10 | * This file contains the check_disk plugin |
11 | * | 11 | * |
12 | * | 12 | * |
13 | * This program is free software: you can redistribute it and/or modify | 13 | * This program is free software: you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
15 | * the Free Software Foundation, either version 3 of the License, or | 15 | * the Free Software Foundation, either version 3 of the License, or |
16 | * (at your option) any later version. | 16 | * (at your option) any later version. |
17 | * | 17 | * |
18 | * This program is distributed in the hope that it will be useful, | 18 | * This program is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | * GNU General Public License for more details. | 21 | * GNU General Public License for more details. |
22 | * | 22 | * |
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
25 | * | 25 | * |
26 | * | 26 | * |
27 | *****************************************************************************/ | 27 | *****************************************************************************/ |
28 | 28 | ||
29 | const char *progname = "check_disk"; | 29 | const char *progname = "check_disk"; |
@@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
46 | #include <stdarg.h> | 46 | #include <stdarg.h> |
47 | #include "fsusage.h" | 47 | #include "fsusage.h" |
48 | #include "mountlist.h" | 48 | #include "mountlist.h" |
49 | #include "intprops.h" /* necessary for TYPE_MAXIMUM */ | 49 | #include "intprops.h" /* necessary for TYPE_MAXIMUM */ |
50 | #if HAVE_LIMITS_H | 50 | #if HAVE_LIMITS_H |
51 | # include <limits.h> | 51 | # include <limits.h> |
52 | #endif | 52 | #endif |
@@ -171,9 +171,6 @@ main (int argc, char **argv) | |||
171 | char *perf_ilabel; | 171 | char *perf_ilabel; |
172 | char *preamble; | 172 | char *preamble; |
173 | char *flag_header; | 173 | char *flag_header; |
174 | double inode_space_pct; | ||
175 | double warning_high_tide; | ||
176 | double critical_high_tide; | ||
177 | int temp_result; | 174 | int temp_result; |
178 | 175 | ||
179 | struct mount_entry *me; | 176 | struct mount_entry *me; |
@@ -232,8 +229,10 @@ main (int argc, char **argv) | |||
232 | /* Process for every path in list */ | 229 | /* Process for every path in list */ |
233 | for (path = path_select_list; path; path=path->name_next) { | 230 | for (path = path_select_list; path; path=path->name_next) { |
234 | if (verbose >= 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL) | 231 | if (verbose >= 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL) |
235 | printf("Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end, | 232 | printf("Thresholds(pct) for %s warn: %f crit %f\n", |
236 | path->freespace_percent->critical->end); | 233 | path->name, |
234 | path->freespace_percent->warning->end, | ||
235 | path->freespace_percent->critical->end); | ||
237 | 236 | ||
238 | if (verbose >= 3 && path->group != NULL) | 237 | if (verbose >= 3 && path->group != NULL) |
239 | printf("Group of %s: %s\n",path->name,path->group); | 238 | printf("Group of %s: %s\n",path->name,path->group); |
@@ -245,17 +244,17 @@ main (int argc, char **argv) | |||
245 | 244 | ||
246 | #ifdef __CYGWIN__ | 245 | #ifdef __CYGWIN__ |
247 | if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) | 246 | if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) |
248 | continue; | 247 | continue; |
249 | snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); | 248 | snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); |
250 | if (GetDriveType(mountdir) != DRIVE_FIXED) | 249 | if (GetDriveType(mountdir) != DRIVE_FIXED) |
251 | me->me_remote = 1; | 250 | me->me_remote = 1; |
252 | #endif | 251 | #endif |
253 | /* Filters */ | 252 | /* Filters */ |
254 | 253 | ||
255 | /* Remove filesystems already seen */ | 254 | /* Remove filesystems already seen */ |
256 | if (np_seen_name(seen, me->me_mountdir)) { | 255 | if (np_seen_name(seen, me->me_mountdir)) { |
257 | continue; | 256 | continue; |
258 | } | 257 | } |
259 | np_add_name(&seen, me->me_mountdir); | 258 | np_add_name(&seen, me->me_mountdir); |
260 | 259 | ||
261 | if (path->group == NULL) { | 260 | if (path->group == NULL) { |
@@ -288,8 +287,17 @@ main (int argc, char **argv) | |||
288 | get_stats (path, &fsp); | 287 | get_stats (path, &fsp); |
289 | 288 | ||
290 | if (verbose >= 3) { | 289 | if (verbose >= 3) { |
291 | printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", | 290 | printf ("For %s, used_pct=%g free_pct=%g used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%lu mult=%lu\n", |
292 | me->me_mountdir, path->dused_pct, path->dfree_pct, path->dused_units, path->dfree_units, path->dtotal_units, path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, mult); | 291 | me->me_mountdir, |
292 | path->dused_pct, | ||
293 | path->dfree_pct, | ||
294 | path->dused_units, | ||
295 | path->dfree_units, | ||
296 | path->dtotal_units, | ||
297 | path->dused_inodes_percent, | ||
298 | path->dfree_inodes_percent, | ||
299 | fsp.fsu_blocksize, | ||
300 | mult); | ||
293 | } | 301 | } |
294 | 302 | ||
295 | /* Threshold comparisons */ | 303 | /* Threshold comparisons */ |
@@ -326,84 +334,78 @@ main (int argc, char **argv) | |||
326 | */ | 334 | */ |
327 | 335 | ||
328 | /* *_high_tide must be reinitialized at each run */ | 336 | /* *_high_tide must be reinitialized at each run */ |
329 | warning_high_tide = UINT_MAX; | 337 | uint64_t warning_high_tide = UINT64_MAX; |
330 | critical_high_tide = UINT_MAX; | ||
331 | 338 | ||
332 | if (path->freespace_units->warning != NULL) { | 339 | if (path->freespace_units->warning != NULL) { |
333 | warning_high_tide = path->dtotal_units - path->freespace_units->warning->end; | 340 | warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult; |
334 | } | 341 | } |
335 | if (path->freespace_percent->warning != NULL) { | 342 | if (path->freespace_percent->warning != NULL) { |
336 | warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)*path->dtotal_units )); | 343 | warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) ); |
337 | } | 344 | } |
345 | |||
346 | uint64_t critical_high_tide = UINT64_MAX; | ||
347 | |||
338 | if (path->freespace_units->critical != NULL) { | 348 | if (path->freespace_units->critical != NULL) { |
339 | critical_high_tide = path->dtotal_units - path->freespace_units->critical->end; | 349 | critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult; |
340 | } | 350 | } |
341 | if (path->freespace_percent->critical != NULL) { | 351 | if (path->freespace_percent->critical != NULL) { |
342 | critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units )); | 352 | critical_high_tide = min( critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end/100) * (path->dtotal_units * mult)) ); |
343 | } | 353 | } |
344 | 354 | ||
345 | /* Nb: *_high_tide are unset when == UINT_MAX */ | 355 | /* Nb: *_high_tide are unset when == UINT64_MAX */ |
346 | xasprintf (&perf, "%s %s", perf, | 356 | xasprintf (&perf, "%s %s", perf, |
347 | perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 357 | perfdata_uint64 ( |
348 | path->dused_units, units, | 358 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
349 | (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, | 359 | path->dused_units * mult, "B", |
350 | (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, | 360 | (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide, |
351 | TRUE, 0, | 361 | (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide, |
352 | TRUE, path->dtotal_units)); | 362 | TRUE, 0, |
363 | TRUE, path->dtotal_units * mult)); | ||
353 | 364 | ||
354 | if (display_inodes_perfdata) { | 365 | if (display_inodes_perfdata) { |
355 | /* *_high_tide must be reinitialized at each run */ | 366 | /* *_high_tide must be reinitialized at each run */ |
356 | warning_high_tide = UINT_MAX; | 367 | warning_high_tide = UINT64_MAX; |
357 | critical_high_tide = UINT_MAX; | 368 | critical_high_tide = UINT64_MAX; |
358 | 369 | ||
359 | if (path->freeinodes_percent->warning != NULL) { | 370 | if (path->freeinodes_percent->warning != NULL) { |
360 | warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); | 371 | warning_high_tide = (uint64_t) fabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); |
361 | } | 372 | } |
362 | if (path->freeinodes_percent->critical != NULL) { | 373 | if (path->freeinodes_percent->critical != NULL) { |
363 | critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); | 374 | critical_high_tide = (uint64_t) fabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); |
364 | } | 375 | } |
365 | 376 | ||
366 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); | 377 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); |
367 | /* Nb: *_high_tide are unset when == UINT_MAX */ | 378 | /* Nb: *_high_tide are unset when == UINT64_MAX */ |
368 | xasprintf (&perf, "%s %s", perf, | 379 | xasprintf (&perf, "%s %s", perf, |
369 | perfdata (perf_ilabel, | 380 | perfdata_uint64 (perf_ilabel, |
370 | path->inodes_used, "", | 381 | path->inodes_used, "", |
371 | (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, | 382 | (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide, |
372 | (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, | 383 | (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide, |
373 | TRUE, 0, | 384 | TRUE, 0, |
374 | TRUE, path->inodes_total)); | 385 | TRUE, path->inodes_total)); |
375 | } | 386 | } |
376 | 387 | ||
377 | if (disk_result==STATE_OK && erronly && !verbose) | 388 | if (disk_result==STATE_OK && erronly && !verbose) |
378 | continue; | 389 | continue; |
379 | 390 | ||
380 | if(disk_result && verbose >= 1) { | 391 | if(disk_result && verbose >= 1) { |
381 | xasprintf(&flag_header, " %s [", state_text (disk_result)); | 392 | xasprintf(&flag_header, " %s [", state_text (disk_result)); |
382 | } else { | 393 | } else { |
383 | xasprintf(&flag_header, ""); | 394 | xasprintf(&flag_header, ""); |
384 | } | 395 | } |
385 | xasprintf (&output, "%s%s %s %.0f %s (%.0f%%", | 396 | xasprintf (&output, "%s%s %s %llu%s (%.0f%%", |
386 | output, flag_header, | 397 | output, flag_header, |
387 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 398 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
388 | path->dfree_units, | 399 | path->dfree_units, |
389 | units, | 400 | units, |
390 | path->dfree_pct); | 401 | path->dfree_pct); |
391 | if (path->dused_inodes_percent < 0) { | 402 | if (path->dused_inodes_percent < 0) { |
392 | xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); | 403 | xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); |
393 | } else { | 404 | } else { |
394 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); | 405 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); |
395 | } | 406 | } |
396 | free(flag_header); | 407 | free(flag_header); |
397 | /* TODO: Need to do a similar debug line | ||
398 | xasprintf (&details, _("%s\n\ | ||
399 | %.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), | ||
400 | details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, | ||
401 | me->me_devname, me->me_type, me->me_mountdir, | ||
402 | (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); | ||
403 | */ | ||
404 | |||
405 | } | 408 | } |
406 | |||
407 | } | 409 | } |
408 | 410 | ||
409 | if (verbose >= 2) | 411 | if (verbose >= 2) |
@@ -557,14 +559,14 @@ process_arguments (int argc, char **argv) | |||
557 | } | 559 | } |
558 | break; | 560 | break; |
559 | 561 | ||
560 | case 'W': /* warning inode threshold */ | 562 | case 'W': /* warning inode threshold */ |
561 | if (*optarg == '@') { | 563 | if (*optarg == '@') { |
562 | warn_freeinodes_percent = optarg; | 564 | warn_freeinodes_percent = optarg; |
563 | } else { | 565 | } else { |
564 | xasprintf(&warn_freeinodes_percent, "@%s", optarg); | 566 | xasprintf(&warn_freeinodes_percent, "@%s", optarg); |
565 | } | 567 | } |
566 | break; | 568 | break; |
567 | case 'K': /* critical inode threshold */ | 569 | case 'K': /* critical inode threshold */ |
568 | if (*optarg == '@') { | 570 | if (*optarg == '@') { |
569 | crit_freeinodes_percent = optarg; | 571 | crit_freeinodes_percent = optarg; |
570 | } else { | 572 | } else { |
@@ -574,21 +576,24 @@ process_arguments (int argc, char **argv) | |||
574 | case 'u': | 576 | case 'u': |
575 | if (units) | 577 | if (units) |
576 | free(units); | 578 | free(units); |
577 | if (! strcmp (optarg, "bytes")) { | 579 | if (! strcasecmp (optarg, "bytes")) { |
578 | mult = (uintmax_t)1; | 580 | mult = (uintmax_t)1; |
579 | units = strdup ("B"); | 581 | units = strdup ("B"); |
580 | } else if (! strcmp (optarg, "kB")) { | 582 | } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) { |
581 | mult = (uintmax_t)1024; | 583 | mult = (uintmax_t)1024; |
582 | units = strdup ("kB"); | 584 | units = strdup ("kiB"); |
583 | } else if (! strcmp (optarg, "MB")) { | 585 | } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) { |
584 | mult = (uintmax_t)1024 * 1024; | 586 | mult = (uintmax_t)1024 * 1024; |
585 | units = strdup ("MB"); | 587 | units = strdup ("MiB"); |
586 | } else if (! strcmp (optarg, "GB")) { | 588 | } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) { |
587 | mult = (uintmax_t)1024 * 1024 * 1024; | 589 | mult = (uintmax_t)1024 * 1024 * 1024; |
588 | units = strdup ("GB"); | 590 | units = strdup ("GiB"); |
589 | } else if (! strcmp (optarg, "TB")) { | 591 | } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) { |
590 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024; | 592 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024; |
591 | units = strdup ("TB"); | 593 | units = strdup ("TiB"); |
594 | } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) { | ||
595 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024; | ||
596 | units = strdup ("PiB"); | ||
592 | } else { | 597 | } else { |
593 | die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); | 598 | die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); |
594 | } | 599 | } |
@@ -599,13 +604,13 @@ process_arguments (int argc, char **argv) | |||
599 | mult = 1024; | 604 | mult = 1024; |
600 | if (units) | 605 | if (units) |
601 | free(units); | 606 | free(units); |
602 | units = strdup ("kB"); | 607 | units = strdup ("kiB"); |
603 | break; | 608 | break; |
604 | case 'm': /* display mountpoint */ | 609 | case 'm': /* display mountpoint */ |
605 | mult = 1024 * 1024; | 610 | mult = 1024 * 1024; |
606 | if (units) | 611 | if (units) |
607 | free(units); | 612 | free(units); |
608 | units = strdup ("MB"); | 613 | units = strdup ("MiB"); |
609 | break; | 614 | break; |
610 | case 'L': | 615 | case 'L': |
611 | stat_remote_fs = 1; | 616 | stat_remote_fs = 1; |
@@ -675,6 +680,7 @@ process_arguments (int argc, char **argv) | |||
675 | break; | 680 | break; |
676 | case 'I': | 681 | case 'I': |
677 | cflags |= REG_ICASE; | 682 | cflags |= REG_ICASE; |
683 | // Intentional fallthrough | ||
678 | case 'i': | 684 | case 'i': |
679 | if (!path_selected) | 685 | if (!path_selected) |
680 | die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly")); | 686 | die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly")); |
@@ -714,8 +720,10 @@ process_arguments (int argc, char **argv) | |||
714 | 720 | ||
715 | case 'A': | 721 | case 'A': |
716 | optarg = strdup(".*"); | 722 | optarg = strdup(".*"); |
723 | // Intentional fallthrough | ||
717 | case 'R': | 724 | case 'R': |
718 | cflags |= REG_ICASE; | 725 | cflags |= REG_ICASE; |
726 | // Intentional fallthrough | ||
719 | case 'r': | 727 | case 'r': |
720 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || | 728 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || |
721 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || | 729 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || |
@@ -812,7 +820,7 @@ process_arguments (int argc, char **argv) | |||
812 | } | 820 | } |
813 | 821 | ||
814 | if (units == NULL) { | 822 | if (units == NULL) { |
815 | units = strdup ("MB"); | 823 | units = strdup ("MiB"); |
816 | mult = (uintmax_t)1024 * 1024; | 824 | mult = (uintmax_t)1024 * 1024; |
817 | } | 825 | } |
818 | 826 | ||
@@ -848,51 +856,6 @@ set_all_thresholds (struct parameter_list *path) | |||
848 | set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent); | 856 | set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent); |
849 | } | 857 | } |
850 | 858 | ||
851 | /* TODO: Remove? | ||
852 | |||
853 | int | ||
854 | validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath) | ||
855 | { | ||
856 | if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) { | ||
857 | printf (_("INPUT ERROR: No thresholds specified")); | ||
858 | print_path (mypath); | ||
859 | return ERROR; | ||
860 | } | ||
861 | else if ((wp >= 0.0 || cp >= 0.0) && | ||
862 | (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) { | ||
863 | printf (_("\ | ||
864 | INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"), | ||
865 | cp, wp); | ||
866 | print_path (mypath); | ||
867 | return ERROR; | ||
868 | } | ||
869 | else if ((iwp >= 0.0 || icp >= 0.0) && | ||
870 | (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) { | ||
871 | printf (_("\ | ||
872 | INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"), | ||
873 | icp, iwp); | ||
874 | print_path (mypath); | ||
875 | return ERROR; | ||
876 | } | ||
877 | else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) { | ||
878 | printf (_("\ | ||
879 | INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"), | ||
880 | (unsigned long)c, (unsigned long)w); | ||
881 | print_path (mypath); | ||
882 | return ERROR; | ||
883 | } | ||
884 | |||
885 | return OK; | ||
886 | } | ||
887 | |||
888 | */ | ||
889 | |||
890 | |||
891 | |||
892 | |||
893 | |||
894 | |||
895 | |||
896 | void | 859 | void |
897 | print_help (void) | 860 | print_help (void) |
898 | { | 861 | { |
@@ -947,7 +910,7 @@ print_help (void) | |||
947 | printf (" %s\n", _("Only check local filesystems against thresholds. Yet call stat on remote filesystems")); | 910 | printf (" %s\n", _("Only check local filesystems against thresholds. Yet call stat on remote filesystems")); |
948 | printf (" %s\n", _("to test if they are accessible (e.g. to detect Stale NFS Handles)")); | 911 | printf (" %s\n", _("to test if they are accessible (e.g. to detect Stale NFS Handles)")); |
949 | printf (" %s\n", "-M, --mountpoint"); | 912 | printf (" %s\n", "-M, --mountpoint"); |
950 | printf (" %s\n", _("Display the mountpoint instead of the partition")); | 913 | printf (" %s\n", _("Display the (block) device instead of the mount point")); |
951 | printf (" %s\n", "-m, --megabytes"); | 914 | printf (" %s\n", "-m, --megabytes"); |
952 | printf (" %s\n", _("Same as '--units MB'")); | 915 | printf (" %s\n", _("Same as '--units MB'")); |
953 | printf (" %s\n", "-A, --all"); | 916 | printf (" %s\n", "-A, --all"); |
@@ -988,7 +951,7 @@ void | |||
988 | print_usage (void) | 951 | print_usage (void) |
989 | { | 952 | { |
990 | printf ("%s\n", _("Usage:")); | 953 | printf ("%s\n", _("Usage:")); |
991 | printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname); | 954 | printf (" %s {-w absolute_limit |-w percentage_limit% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit% | -K inode_percentage_limit } {-p path | -x device}\n", progname); |
992 | printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); | 955 | printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); |
993 | printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); | 956 | printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); |
994 | } | 957 | } |
@@ -1026,20 +989,26 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1026 | if (p_list->group && ! (strcmp(p_list->group, p->group))) { | 989 | if (p_list->group && ! (strcmp(p_list->group, p->group))) { |
1027 | stat_path(p_list); | 990 | stat_path(p_list); |
1028 | get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); | 991 | get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); |
1029 | get_path_stats(p_list, &tmpfsp); | 992 | get_path_stats(p_list, &tmpfsp); |
1030 | if (verbose >= 3) | 993 | if (verbose >= 3) |
1031 | printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", | 994 | printf("Group %s: adding %lu blocks sized %lu, (%s) used_units=%lu free_units=%lu total_units=%lu mult=%lu\n", |
1032 | p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units, | 995 | p_list->group, |
1033 | p_list->dtotal_units, mult); | 996 | tmpfsp.fsu_blocks, |
1034 | 997 | tmpfsp.fsu_blocksize, | |
1035 | /* prevent counting the first FS of a group twice since its parameter_list entry | 998 | p_list->best_match->me_mountdir, |
999 | p_list->dused_units, | ||
1000 | p_list->dfree_units, | ||
1001 | p_list->dtotal_units, | ||
1002 | mult); | ||
1003 | |||
1004 | /* prevent counting the first FS of a group twice since its parameter_list entry | ||
1036 | * is used to carry the information of all file systems of the entire group */ | 1005 | * is used to carry the information of all file systems of the entire group */ |
1037 | if (! first) { | 1006 | if (! first) { |
1038 | p->total += p_list->total; | 1007 | p->total += p_list->total; |
1039 | p->available += p_list->available; | 1008 | p->available += p_list->available; |
1040 | p->available_to_root += p_list->available_to_root; | 1009 | p->available_to_root += p_list->available_to_root; |
1041 | p->used += p_list->used; | 1010 | p->used += p_list->used; |
1042 | 1011 | ||
1043 | p->dused_units += p_list->dused_units; | 1012 | p->dused_units += p_list->dused_units; |
1044 | p->dfree_units += p_list->dfree_units; | 1013 | p->dfree_units += p_list->dfree_units; |
1045 | p->dtotal_units += p_list->dtotal_units; | 1014 | p->dtotal_units += p_list->dtotal_units; |
@@ -1050,28 +1019,29 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1050 | } | 1019 | } |
1051 | first = 0; | 1020 | first = 0; |
1052 | } | 1021 | } |
1053 | if (verbose >= 3) | 1022 | if (verbose >= 3) |
1054 | printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", | 1023 | printf("Group %s now has: used_units=%lu free_units=%lu total_units=%lu fsu_blocksize=%lu mult=%lu\n", |
1055 | p->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p->best_match->me_mountdir, p->dused_units, | 1024 | p->group, |
1056 | p->dfree_units, p->dtotal_units, mult); | 1025 | p->dused_units, |
1026 | p->dfree_units, | ||
1027 | p->dtotal_units, | ||
1028 | tmpfsp.fsu_blocksize, | ||
1029 | mult); | ||
1057 | } | 1030 | } |
1058 | /* modify devname and mountdir for output */ | 1031 | /* modify devname and mountdir for output */ |
1059 | p->best_match->me_mountdir = p->best_match->me_devname = p->group; | 1032 | p->best_match->me_mountdir = p->best_match->me_devname = p->group; |
1060 | } | 1033 | } |
1061 | /* finally calculate percentages for either plain FS or summed up group */ | 1034 | /* finally calculate percentages for either plain FS or summed up group */ |
1062 | p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ | 1035 | p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ |
1063 | p->dfree_pct = 100 - p->dused_pct; | 1036 | p->dfree_pct = 100 - p->dused_pct; |
1064 | p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); | 1037 | p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); |
1065 | p->dfree_inodes_percent = 100 - p->dused_inodes_percent; | 1038 | p->dfree_inodes_percent = 100 - p->dused_inodes_percent; |
1066 | 1039 | ||
1067 | } | 1040 | } |
1068 | 1041 | ||
1069 | void | 1042 | void |
1070 | get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | 1043 | get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { |
1071 | /* 2007-12-08 - Workaround for Gnulib reporting insanely high available | 1044 | p->available = fsp->fsu_bavail; |
1072 | * space on BSD (the actual value should be negative but fsp->fsu_bavail | ||
1073 | * is unsigned) */ | ||
1074 | p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail; | ||
1075 | p->available_to_root = fsp->fsu_bfree; | 1045 | p->available_to_root = fsp->fsu_bfree; |
1076 | p->used = fsp->fsu_blocks - fsp->fsu_bfree; | 1046 | p->used = fsp->fsu_blocks - fsp->fsu_bfree; |
1077 | if (freespace_ignore_reserved) { | 1047 | if (freespace_ignore_reserved) { |
@@ -1081,12 +1051,12 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1081 | /* default behaviour : take all the blocks into account */ | 1051 | /* default behaviour : take all the blocks into account */ |
1082 | p->total = fsp->fsu_blocks; | 1052 | p->total = fsp->fsu_blocks; |
1083 | } | 1053 | } |
1084 | 1054 | ||
1085 | p->dused_units = p->used*fsp->fsu_blocksize/mult; | 1055 | p->dused_units = p->used*fsp->fsu_blocksize/mult; |
1086 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; | 1056 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; |
1087 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; | 1057 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; |
1088 | /* Free file nodes. Not sure the workaround is required, but in case...*/ | 1058 | /* Free file nodes. Not sure the workaround is required, but in case...*/ |
1089 | p->inodes_free = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail; | 1059 | p->inodes_free = fsp->fsu_ffree; |
1090 | p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */ | 1060 | p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */ |
1091 | p->inodes_used = fsp->fsu_files - fsp->fsu_ffree; | 1061 | p->inodes_used = fsp->fsu_files - fsp->fsu_ffree; |
1092 | if (freespace_ignore_reserved) { | 1062 | if (freespace_ignore_reserved) { |