diff options
Diffstat (limited to 'plugins/check_disk.c')
| -rw-r--r-- | plugins/check_disk.c | 288 |
1 files changed, 186 insertions, 102 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 515ddff0..d42b5486 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
| @@ -78,18 +78,21 @@ typedef struct { | |||
| 78 | } check_disk_config_wrapper; | 78 | } check_disk_config_wrapper; |
| 79 | static check_disk_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); | 79 | static check_disk_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); |
| 80 | 80 | ||
| 81 | static void set_all_thresholds(parameter_list_elem *path, char *warn_freespace_units, char *crit_freespace_units, | 81 | static void set_all_thresholds(parameter_list_elem *path, char *warn_freespace_units, |
| 82 | char *warn_freespace_percent, char *crit_freespace_percent, char *warn_freeinodes_percent, | 82 | char *crit_freespace_units, char *warn_freespace_percent, |
| 83 | char *crit_freespace_percent, char *warn_freeinodes_percent, | ||
| 83 | char *crit_freeinodes_percent); | 84 | char *crit_freeinodes_percent); |
| 84 | static double calculate_percent(uintmax_t /*value*/, uintmax_t /*total*/); | 85 | static double calculate_percent(uintmax_t /*value*/, uintmax_t /*total*/); |
| 85 | static bool stat_path(parameter_list_elem * /*parameters*/, bool /*ignore_missing*/); | 86 | static bool stat_path(parameter_list_elem * /*parameters*/, bool /*ignore_missing*/); |
| 86 | 87 | ||
| 87 | /* | 88 | /* |
| 88 | * Puts the values from a struct fs_usage into a parameter_list with an additional flag to control how reserved | 89 | * Puts the values from a struct fs_usage into a parameter_list with an additional flag to control |
| 89 | * and inodes should be judged (ignored or not) | 90 | * how reserved and inodes should be judged (ignored or not) |
| 90 | */ | 91 | */ |
| 91 | static parameter_list_elem get_path_stats(parameter_list_elem parameters, struct fs_usage fsp, bool freespace_ignore_reserved); | 92 | static parameter_list_elem get_path_stats(parameter_list_elem parameters, struct fs_usage fsp, |
| 92 | static mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_inodes_perfdata, byte_unit unit); | 93 | bool freespace_ignore_reserved); |
| 94 | static mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, | ||
| 95 | bool display_inodes_perfdata, byte_unit unit); | ||
| 93 | 96 | ||
| 94 | void print_usage(void); | 97 | void print_usage(void); |
| 95 | static void print_help(void); | 98 | static void print_help(void); |
| @@ -111,7 +114,6 @@ const byte_unit TeraBytes_factor = 1000000000000; | |||
| 111 | const byte_unit PetaBytes_factor = 1000000000000000; | 114 | const byte_unit PetaBytes_factor = 1000000000000000; |
| 112 | const byte_unit ExaBytes_factor = 1000000000000000000; | 115 | const byte_unit ExaBytes_factor = 1000000000000000000; |
| 113 | 116 | ||
| 114 | |||
| 115 | int main(int argc, char **argv) { | 117 | int main(int argc, char **argv) { |
| 116 | setlocale(LC_ALL, ""); | 118 | setlocale(LC_ALL, ""); |
| 117 | bindtextdomain(PACKAGE, LOCALEDIR); | 119 | bindtextdomain(PACKAGE, LOCALEDIR); |
| @@ -140,7 +142,8 @@ int main(int argc, char **argv) { | |||
| 140 | } | 142 | } |
| 141 | 143 | ||
| 142 | if (!config.path_ignored) { | 144 | if (!config.path_ignored) { |
| 143 | mp_int_fs_list_set_best_match(config.path_select_list, config.mount_list, config.exact_match); | 145 | mp_int_fs_list_set_best_match(config.path_select_list, config.mount_list, |
| 146 | config.exact_match); | ||
| 144 | } | 147 | } |
| 145 | 148 | ||
| 146 | // Error if no match found for specified paths | 149 | // Error if no match found for specified paths |
| @@ -203,20 +206,23 @@ int main(int argc, char **argv) { | |||
| 203 | } | 206 | } |
| 204 | 207 | ||
| 205 | if (path->group == NULL) { | 208 | if (path->group == NULL) { |
| 206 | if (config.fs_exclude_list && np_find_regmatch(config.fs_exclude_list, mount_entry->me_type)) { | 209 | if (config.fs_exclude_list && |
| 210 | np_find_regmatch(config.fs_exclude_list, mount_entry->me_type)) { | ||
| 207 | // Skip excluded fs's | 211 | // Skip excluded fs's |
| 208 | path = mp_int_fs_list_del(&config.path_select_list, path); | 212 | path = mp_int_fs_list_del(&config.path_select_list, path); |
| 209 | continue; | 213 | continue; |
| 210 | } | 214 | } |
| 211 | 215 | ||
| 212 | if (config.device_path_exclude_list && (np_find_name(config.device_path_exclude_list, mount_entry->me_devname) || | 216 | if (config.device_path_exclude_list && |
| 213 | np_find_name(config.device_path_exclude_list, mount_entry->me_mountdir))) { | 217 | (np_find_name(config.device_path_exclude_list, mount_entry->me_devname) || |
| 218 | np_find_name(config.device_path_exclude_list, mount_entry->me_mountdir))) { | ||
| 214 | // Skip excluded device or mount paths | 219 | // Skip excluded device or mount paths |
| 215 | path = mp_int_fs_list_del(&config.path_select_list, path); | 220 | path = mp_int_fs_list_del(&config.path_select_list, path); |
| 216 | continue; | 221 | continue; |
| 217 | } | 222 | } |
| 218 | 223 | ||
| 219 | if (config.fs_include_list && !np_find_regmatch(config.fs_include_list, mount_entry->me_type)) { | 224 | if (config.fs_include_list && |
| 225 | !np_find_regmatch(config.fs_include_list, mount_entry->me_type)) { | ||
| 220 | // Skip not included fstypes | 226 | // Skip not included fstypes |
| 221 | path = mp_int_fs_list_del(&config.path_select_list, path); | 227 | path = mp_int_fs_list_del(&config.path_select_list, path); |
| 222 | continue; | 228 | continue; |
| @@ -259,8 +265,8 @@ int main(int argc, char **argv) { | |||
| 259 | if (verbose >= 3) { | 265 | if (verbose >= 3) { |
| 260 | printf("For %s, used_units=%lu free_units=%lu total_units=%lu " | 266 | printf("For %s, used_units=%lu free_units=%lu total_units=%lu " |
| 261 | "fsp.fsu_blocksize=%lu\n", | 267 | "fsp.fsu_blocksize=%lu\n", |
| 262 | mount_entry->me_mountdir, filesystem->used_bytes, filesystem->free_bytes, filesystem->total_bytes, | 268 | mount_entry->me_mountdir, filesystem->used_bytes, filesystem->free_bytes, |
| 263 | fsp.fsu_blocksize); | 269 | filesystem->total_bytes, fsp.fsu_blocksize); |
| 264 | } | 270 | } |
| 265 | } else { | 271 | } else { |
| 266 | // failed to retrieve file system data or not mounted? | 272 | // failed to retrieve file system data or not mounted? |
| @@ -285,12 +291,14 @@ int main(int argc, char **argv) { | |||
| 285 | measurement_unit_list *measurements = NULL; | 291 | measurement_unit_list *measurements = NULL; |
| 286 | measurement_unit_list *current = NULL; | 292 | measurement_unit_list *current = NULL; |
| 287 | // create measuring units, because of groups | 293 | // create measuring units, because of groups |
| 288 | for (parameter_list_elem *filesystem = config.path_select_list.first; filesystem; filesystem = mp_int_fs_list_get_next(filesystem)) { | 294 | for (parameter_list_elem *filesystem = config.path_select_list.first; filesystem; |
| 295 | filesystem = mp_int_fs_list_get_next(filesystem)) { | ||
| 289 | assert(filesystem->best_match != NULL); | 296 | assert(filesystem->best_match != NULL); |
| 290 | 297 | ||
| 291 | if (filesystem->group == NULL) { | 298 | if (filesystem->group == NULL) { |
| 292 | // create a measurement unit for the fs | 299 | // create a measurement unit for the fs |
| 293 | measurement_unit unit = create_measurement_unit_from_filesystem(*filesystem, config.display_mntp); | 300 | measurement_unit unit = |
| 301 | create_measurement_unit_from_filesystem(*filesystem, config.display_mntp); | ||
| 294 | if (measurements == NULL) { | 302 | if (measurements == NULL) { |
| 295 | measurements = current = add_measurement_list(NULL, unit); | 303 | measurements = current = add_measurement_list(NULL, unit); |
| 296 | } else { | 304 | } else { |
| @@ -300,14 +308,17 @@ int main(int argc, char **argv) { | |||
| 300 | // Grouped elements are consecutive | 308 | // Grouped elements are consecutive |
| 301 | if (measurements == NULL) { | 309 | if (measurements == NULL) { |
| 302 | // first entry | 310 | // first entry |
| 303 | measurement_unit unit = create_measurement_unit_from_filesystem(*filesystem, config.display_mntp); | 311 | measurement_unit unit = |
| 312 | create_measurement_unit_from_filesystem(*filesystem, config.display_mntp); | ||
| 304 | unit.name = strdup(filesystem->group); | 313 | unit.name = strdup(filesystem->group); |
| 305 | measurements = current = add_measurement_list(NULL, unit); | 314 | measurements = current = add_measurement_list(NULL, unit); |
| 306 | } else { | 315 | } else { |
| 307 | // if this is the first element of a group, the name of the previous entry is different | 316 | // if this is the first element of a group, the name of the previous entry is |
| 317 | // different | ||
| 308 | if (strcmp(filesystem->group, current->unit.name) != 0) { | 318 | if (strcmp(filesystem->group, current->unit.name) != 0) { |
| 309 | // so, this must be the first element of a group | 319 | // so, this must be the first element of a group |
| 310 | measurement_unit unit = create_measurement_unit_from_filesystem(*filesystem, config.display_mntp); | 320 | measurement_unit unit = |
| 321 | create_measurement_unit_from_filesystem(*filesystem, config.display_mntp); | ||
| 311 | unit.name = filesystem->group; | 322 | unit.name = filesystem->group; |
| 312 | current = add_measurement_list(measurements, unit); | 323 | current = add_measurement_list(measurements, unit); |
| 313 | 324 | ||
| @@ -322,7 +333,8 @@ int main(int argc, char **argv) { | |||
| 322 | /* Process for every path in list */ | 333 | /* Process for every path in list */ |
| 323 | if (measurements != NULL) { | 334 | if (measurements != NULL) { |
| 324 | for (measurement_unit_list *unit = measurements; unit; unit = unit->next) { | 335 | for (measurement_unit_list *unit = measurements; unit; unit = unit->next) { |
| 325 | mp_subcheck unit_sc = evaluate_filesystem(unit->unit, config.display_inodes_perfdata, config.display_unit); | 336 | mp_subcheck unit_sc = evaluate_filesystem(unit->unit, config.display_inodes_perfdata, |
| 337 | config.display_unit); | ||
| 326 | mp_add_subcheck_to_check(&overall, unit_sc); | 338 | mp_add_subcheck_to_check(&overall, unit_sc); |
| 327 | } | 339 | } |
| 328 | } else { | 340 | } else { |
| @@ -433,7 +445,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 433 | 445 | ||
| 434 | while (true) { | 446 | while (true) { |
| 435 | int option = 0; | 447 | int option = 0; |
| 436 | int option_index = getopt_long(argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEAn", longopts, &option); | 448 | int option_index = getopt_long( |
| 449 | argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEAn", longopts, &option); | ||
| 437 | 450 | ||
| 438 | if (option_index == -1 || option_index == EOF) { | 451 | if (option_index == -1 || option_index == EOF) { |
| 439 | break; | 452 | break; |
| @@ -578,9 +591,10 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 578 | result.config.display_inodes_perfdata = true; | 591 | result.config.display_inodes_perfdata = true; |
| 579 | break; | 592 | break; |
| 580 | case 'p': /* select path */ { | 593 | case 'p': /* select path */ { |
| 581 | if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent || crit_freespace_percent || | 594 | if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent || |
| 582 | warn_freeinodes_percent || crit_freeinodes_percent)) { | 595 | crit_freespace_percent || warn_freeinodes_percent || crit_freeinodes_percent)) { |
| 583 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n")); | 596 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), |
| 597 | _("Must set a threshold value before using -p\n")); | ||
| 584 | } | 598 | } |
| 585 | 599 | ||
| 586 | /* add parameter if not found. overwrite thresholds if path has already been added */ | 600 | /* add parameter if not found. overwrite thresholds if path has already been added */ |
| @@ -595,7 +609,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 595 | // } | 609 | // } |
| 596 | } | 610 | } |
| 597 | search_entry->group = group; | 611 | search_entry->group = group; |
| 598 | set_all_thresholds(search_entry, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent, | 612 | set_all_thresholds(search_entry, warn_freespace_units, crit_freespace_units, |
| 613 | warn_freespace_percent, crit_freespace_percent, | ||
| 599 | 614 | ||
| 600 | warn_freeinodes_percent, crit_freeinodes_percent); | 615 | warn_freeinodes_percent, crit_freeinodes_percent); |
| 601 | 616 | ||
| @@ -603,7 +618,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 603 | // if (!stat_path(se, result.config.ignore_missing)) { | 618 | // if (!stat_path(se, result.config.ignore_missing)) { |
| 604 | // break; | 619 | // break; |
| 605 | // } | 620 | // } |
| 606 | mp_int_fs_list_set_best_match(result.config.path_select_list, result.config.mount_list, result.config.exact_match); | 621 | mp_int_fs_list_set_best_match(result.config.path_select_list, result.config.mount_list, |
| 622 | result.config.exact_match); | ||
| 607 | 623 | ||
| 608 | path_selected = true; | 624 | path_selected = true; |
| 609 | } break; | 625 | } break; |
| @@ -615,7 +631,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 615 | if (err != 0) { | 631 | if (err != 0) { |
| 616 | char errbuf[MAX_INPUT_BUFFER]; | 632 | char errbuf[MAX_INPUT_BUFFER]; |
| 617 | regerror(err, &result.config.fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); | 633 | regerror(err, &result.config.fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); |
| 618 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); | 634 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), |
| 635 | _("Could not compile regular expression"), errbuf); | ||
| 619 | } | 636 | } |
| 620 | break; | 637 | break; |
| 621 | case 'N': /* include file system type */ | 638 | case 'N': /* include file system type */ |
| @@ -623,7 +640,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 623 | if (err != 0) { | 640 | if (err != 0) { |
| 624 | char errbuf[MAX_INPUT_BUFFER]; | 641 | char errbuf[MAX_INPUT_BUFFER]; |
| 625 | regerror(err, &result.config.fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); | 642 | regerror(err, &result.config.fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); |
| 626 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); | 643 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), |
| 644 | _("Could not compile regular expression"), errbuf); | ||
| 627 | } | 645 | } |
| 628 | } break; | 646 | } break; |
| 629 | case 'v': /* verbose */ | 647 | case 'v': /* verbose */ |
| @@ -638,7 +656,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 638 | break; | 656 | break; |
| 639 | case 'E': | 657 | case 'E': |
| 640 | if (path_selected) { | 658 | if (path_selected) { |
| 641 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n")); | 659 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), |
| 660 | _("Must set -E before selecting paths\n")); | ||
| 642 | } | 661 | } |
| 643 | result.config.exact_match = true; | 662 | result.config.exact_match = true; |
| 644 | break; | 663 | break; |
| @@ -647,7 +666,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 647 | break; | 666 | break; |
| 648 | case 'g': | 667 | case 'g': |
| 649 | if (path_selected) { | 668 | if (path_selected) { |
| 650 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n")); | 669 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), |
| 670 | _("Must set group value before selecting paths\n")); | ||
| 651 | } | 671 | } |
| 652 | group = optarg; | 672 | group = optarg; |
| 653 | break; | 673 | break; |
| @@ -657,14 +677,16 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 657 | case 'i': { | 677 | case 'i': { |
| 658 | if (!path_selected) { | 678 | if (!path_selected) { |
| 659 | die(STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), | 679 | die(STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), |
| 660 | _("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly")); | 680 | _("Paths need to be selected before using -i/-I. Use -A to select all paths " |
| 681 | "explicitly")); | ||
| 661 | } | 682 | } |
| 662 | regex_t regex; | 683 | regex_t regex; |
| 663 | int err = regcomp(®ex, optarg, cflags); | 684 | int err = regcomp(®ex, optarg, cflags); |
| 664 | if (err != 0) { | 685 | if (err != 0) { |
| 665 | char errbuf[MAX_INPUT_BUFFER]; | 686 | char errbuf[MAX_INPUT_BUFFER]; |
| 666 | regerror(err, ®ex, errbuf, MAX_INPUT_BUFFER); | 687 | regerror(err, ®ex, errbuf, MAX_INPUT_BUFFER); |
| 667 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); | 688 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), |
| 689 | _("Could not compile regular expression"), errbuf); | ||
| 668 | } | 690 | } |
| 669 | 691 | ||
| 670 | for (parameter_list_elem *elem = result.config.path_select_list.first; elem;) { | 692 | for (parameter_list_elem *elem = result.config.path_select_list.first; elem;) { |
| @@ -695,10 +717,11 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 695 | cflags |= REG_ICASE; | 717 | cflags |= REG_ICASE; |
| 696 | // Intentional fallthrough | 718 | // Intentional fallthrough |
| 697 | case 'r': { | 719 | case 'r': { |
| 698 | if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent || crit_freespace_percent || | 720 | if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent || |
| 699 | warn_freeinodes_percent || crit_freeinodes_percent)) { | 721 | crit_freespace_percent || warn_freeinodes_percent || crit_freeinodes_percent)) { |
| 700 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), | 722 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), |
| 701 | _("Must set a threshold value before using -r/-R/-A (--ereg-path/--eregi-path/--all)\n")); | 723 | _("Must set a threshold value before using -r/-R/-A " |
| 724 | "(--ereg-path/--eregi-path/--all)\n")); | ||
| 702 | } | 725 | } |
| 703 | 726 | ||
| 704 | regex_t regex; | 727 | regex_t regex; |
| @@ -706,7 +729,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 706 | if (err != 0) { | 729 | if (err != 0) { |
| 707 | char errbuf[MAX_INPUT_BUFFER]; | 730 | char errbuf[MAX_INPUT_BUFFER]; |
| 708 | regerror(err, ®ex, errbuf, MAX_INPUT_BUFFER); | 731 | regerror(err, ®ex, errbuf, MAX_INPUT_BUFFER); |
| 709 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); | 732 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), |
| 733 | _("Could not compile regular expression"), errbuf); | ||
| 710 | } | 734 | } |
| 711 | 735 | ||
| 712 | bool found = false; | 736 | bool found = false; |
| @@ -714,16 +738,21 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 714 | if (np_regex_match_mount_entry(me, ®ex)) { | 738 | if (np_regex_match_mount_entry(me, ®ex)) { |
| 715 | found = true; | 739 | found = true; |
| 716 | if (verbose >= 3) { | 740 | if (verbose >= 3) { |
| 717 | printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg); | 741 | printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, |
| 742 | optarg); | ||
| 718 | } | 743 | } |
| 719 | 744 | ||
| 720 | /* add parameter if not found. overwrite thresholds if path has already been added */ | 745 | /* add parameter if not found. overwrite thresholds if path has already been |
| 746 | * added */ | ||
| 721 | parameter_list_elem *se = NULL; | 747 | parameter_list_elem *se = NULL; |
| 722 | if (!(se = mp_int_fs_list_find(result.config.path_select_list, me->me_mountdir))) { | 748 | if (!(se = mp_int_fs_list_find(result.config.path_select_list, |
| 723 | se = mp_int_fs_list_append(&result.config.path_select_list, me->me_mountdir); | 749 | me->me_mountdir))) { |
| 750 | se = | ||
| 751 | mp_int_fs_list_append(&result.config.path_select_list, me->me_mountdir); | ||
| 724 | } | 752 | } |
| 725 | se->group = group; | 753 | se->group = group; |
| 726 | set_all_thresholds(se, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent, | 754 | set_all_thresholds(se, warn_freespace_units, crit_freespace_units, |
| 755 | warn_freespace_percent, crit_freespace_percent, | ||
| 727 | warn_freeinodes_percent, crit_freeinodes_percent); | 756 | warn_freeinodes_percent, crit_freeinodes_percent); |
| 728 | } | 757 | } |
| 729 | } | 758 | } |
| @@ -735,11 +764,13 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 735 | break; | 764 | break; |
| 736 | } | 765 | } |
| 737 | 766 | ||
| 738 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Regular expression did not match any path or disk"), optarg); | 767 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), |
| 768 | _("Regular expression did not match any path or disk"), optarg); | ||
| 739 | } | 769 | } |
| 740 | 770 | ||
| 741 | path_selected = true; | 771 | path_selected = true; |
| 742 | mp_int_fs_list_set_best_match(result.config.path_select_list, result.config.mount_list, result.config.exact_match); | 772 | mp_int_fs_list_set_best_match(result.config.path_select_list, result.config.mount_list, |
| 773 | result.config.exact_match); | ||
| 743 | cflags = default_cflags; | 774 | cflags = default_cflags; |
| 744 | 775 | ||
| 745 | } break; | 776 | } break; |
| @@ -747,16 +778,20 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 747 | result.config.display_mntp = true; | 778 | result.config.display_mntp = true; |
| 748 | break; | 779 | break; |
| 749 | case 'C': { | 780 | case 'C': { |
| 750 | /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */ | 781 | /* add all mount entries to path_select list if no partitions have been explicitly |
| 782 | * defined using -p */ | ||
| 751 | if (!path_selected) { | 783 | if (!path_selected) { |
| 752 | parameter_list_elem *path; | 784 | parameter_list_elem *path; |
| 753 | for (struct mount_entry *me = result.config.mount_list; me; me = me->me_next) { | 785 | for (struct mount_entry *me = result.config.mount_list; me; me = me->me_next) { |
| 754 | if (!(path = mp_int_fs_list_find(result.config.path_select_list, me->me_mountdir))) { | 786 | if (!(path = mp_int_fs_list_find(result.config.path_select_list, |
| 755 | path = mp_int_fs_list_append(&result.config.path_select_list, me->me_mountdir); | 787 | me->me_mountdir))) { |
| 788 | path = | ||
| 789 | mp_int_fs_list_append(&result.config.path_select_list, me->me_mountdir); | ||
| 756 | } | 790 | } |
| 757 | path->best_match = me; | 791 | path->best_match = me; |
| 758 | path->group = group; | 792 | path->group = group; |
| 759 | set_all_thresholds(path, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent, | 793 | set_all_thresholds(path, warn_freespace_units, crit_freespace_units, |
| 794 | warn_freespace_percent, crit_freespace_percent, | ||
| 760 | warn_freeinodes_percent, crit_freeinodes_percent); | 795 | warn_freeinodes_percent, crit_freeinodes_percent); |
| 761 | } | 796 | } |
| 762 | } | 797 | } |
| @@ -843,10 +878,12 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 843 | if (verbose > 0) { | 878 | if (verbose > 0) { |
| 844 | printf("Got an positional filesystem: %s\n", argv[index]); | 879 | printf("Got an positional filesystem: %s\n", argv[index]); |
| 845 | } | 880 | } |
| 846 | struct parameter_list *se = mp_int_fs_list_append(&result.config.path_select_list, strdup(argv[index++])); | 881 | struct parameter_list *se = |
| 882 | mp_int_fs_list_append(&result.config.path_select_list, strdup(argv[index++])); | ||
| 847 | path_selected = true; | 883 | path_selected = true; |
| 848 | set_all_thresholds(se, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent, | 884 | set_all_thresholds(se, warn_freespace_units, crit_freespace_units, warn_freespace_percent, |
| 849 | warn_freeinodes_percent, crit_freeinodes_percent); | 885 | crit_freespace_percent, warn_freeinodes_percent, |
| 886 | crit_freeinodes_percent); | ||
| 850 | } | 887 | } |
| 851 | 888 | ||
| 852 | // If a list of paths has not been explicitly selected, find entire | 889 | // If a list of paths has not been explicitly selected, find entire |
| @@ -864,18 +901,21 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 864 | } | 901 | } |
| 865 | path->best_match = me; | 902 | path->best_match = me; |
| 866 | path->group = group; | 903 | path->group = group; |
| 867 | set_all_thresholds(path, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent, | 904 | set_all_thresholds(path, warn_freespace_units, crit_freespace_units, |
| 905 | warn_freespace_percent, crit_freespace_percent, | ||
| 868 | warn_freeinodes_percent, crit_freeinodes_percent); | 906 | warn_freeinodes_percent, crit_freeinodes_percent); |
| 869 | } | 907 | } |
| 870 | } | 908 | } |
| 871 | 909 | ||
| 872 | // Set thresholds to the appropriate unit | 910 | // Set thresholds to the appropriate unit |
| 873 | for (parameter_list_elem *tmp = result.config.path_select_list.first; tmp; tmp = mp_int_fs_list_get_next(tmp)) { | 911 | for (parameter_list_elem *tmp = result.config.path_select_list.first; tmp; |
| 912 | tmp = mp_int_fs_list_get_next(tmp)) { | ||
| 874 | 913 | ||
| 875 | mp_perfdata_value factor = mp_create_pd_value(unit); | 914 | mp_perfdata_value factor = mp_create_pd_value(unit); |
| 876 | 915 | ||
| 877 | if (tmp->freespace_units.critical_is_set) { | 916 | if (tmp->freespace_units.critical_is_set) { |
| 878 | tmp->freespace_units.critical = mp_range_multiply(tmp->freespace_units.critical, factor); | 917 | tmp->freespace_units.critical = |
| 918 | mp_range_multiply(tmp->freespace_units.critical, factor); | ||
| 879 | } | 919 | } |
| 880 | if (tmp->freespace_units.warning_is_set) { | 920 | if (tmp->freespace_units.warning_is_set) { |
| 881 | tmp->freespace_units.warning = mp_range_multiply(tmp->freespace_units.warning, factor); | 921 | tmp->freespace_units.warning = mp_range_multiply(tmp->freespace_units.warning, factor); |
| @@ -885,8 +925,10 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) { | |||
| 885 | return result; | 925 | return result; |
| 886 | } | 926 | } |
| 887 | 927 | ||
| 888 | void set_all_thresholds(parameter_list_elem *path, char *warn_freespace_units, char *crit_freespace_units, char *warn_freespace_percent, | 928 | void set_all_thresholds(parameter_list_elem *path, char *warn_freespace_units, |
| 889 | char *crit_freespace_percent, char *warn_freeinodes_percent, char *crit_freeinodes_percent) { | 929 | char *crit_freespace_units, char *warn_freespace_percent, |
| 930 | char *crit_freespace_percent, char *warn_freeinodes_percent, | ||
| 931 | char *crit_freeinodes_percent) { | ||
| 890 | mp_range_parsed tmp; | 932 | mp_range_parsed tmp; |
| 891 | 933 | ||
| 892 | if (warn_freespace_units) { | 934 | if (warn_freespace_units) { |
| @@ -927,7 +969,8 @@ void print_help(void) { | |||
| 927 | printf(COPYRIGHT, copyright, email); | 969 | printf(COPYRIGHT, copyright, email); |
| 928 | 970 | ||
| 929 | printf("%s\n", _("This plugin checks the amount of used disk space on a mounted file system")); | 971 | printf("%s\n", _("This plugin checks the amount of used disk space on a mounted file system")); |
| 930 | printf("%s\n", _("and generates an alert if free space is less than one of the threshold values")); | 972 | printf("%s\n", |
| 973 | _("and generates an alert if free space is less than one of the threshold values")); | ||
| 931 | 974 | ||
| 932 | printf("\n\n"); | 975 | printf("\n\n"); |
| 933 | 976 | ||
| @@ -949,7 +992,8 @@ void print_help(void) { | |||
| 949 | printf(" %s\n", "-K, --icritical=PERCENT%"); | 992 | printf(" %s\n", "-K, --icritical=PERCENT%"); |
| 950 | printf(" %s\n", _("Exit with CRITICAL status if less than PERCENT of inode space is free")); | 993 | printf(" %s\n", _("Exit with CRITICAL status if less than PERCENT of inode space is free")); |
| 951 | printf(" %s\n", "-p, --path=PATH, --partition=PARTITION"); | 994 | printf(" %s\n", "-p, --path=PATH, --partition=PARTITION"); |
| 952 | printf(" %s\n", _("Mount point or block device as emitted by the mount(8) command (may be repeated)")); | 995 | printf(" %s\n", |
| 996 | _("Mount point or block device as emitted by the mount(8) command (may be repeated)")); | ||
| 953 | printf(" %s\n", "-x, --exclude_device=PATH <STRING>"); | 997 | printf(" %s\n", "-x, --exclude_device=PATH <STRING>"); |
| 954 | printf(" %s\n", _("Ignore device (only works if -p unspecified)")); | 998 | printf(" %s\n", _("Ignore device (only works if -p unspecified)")); |
| 955 | printf(" %s\n", "-C, --clear"); | 999 | printf(" %s\n", "-C, --clear"); |
| @@ -963,71 +1007,88 @@ void print_help(void) { | |||
| 963 | printf(" %s\n", "-P, --iperfdata"); | 1007 | printf(" %s\n", "-P, --iperfdata"); |
| 964 | printf(" %s\n", _("Display inode usage in perfdata")); | 1008 | printf(" %s\n", _("Display inode usage in perfdata")); |
| 965 | printf(" %s\n", "-g, --group=NAME"); | 1009 | printf(" %s\n", "-g, --group=NAME"); |
| 966 | printf(" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together")); | 1010 | printf(" %s\n", |
| 1011 | _("Group paths. Thresholds apply to (free-)space of all partitions together")); | ||
| 967 | printf(" %s\n", "-l, --local"); | 1012 | printf(" %s\n", "-l, --local"); |
| 968 | printf(" %s\n", _("Only check local filesystems")); | 1013 | printf(" %s\n", _("Only check local filesystems")); |
| 969 | printf(" %s\n", "-L, --stat-remote-fs"); | 1014 | printf(" %s\n", "-L, --stat-remote-fs"); |
| 970 | printf(" %s\n", _("Only check local filesystems against thresholds. Yet call stat on remote filesystems")); | 1015 | printf( |
| 1016 | " %s\n", | ||
| 1017 | _("Only check local filesystems against thresholds. Yet call stat on remote filesystems")); | ||
| 971 | printf(" %s\n", _("to test if they are accessible (e.g. to detect Stale NFS Handles)")); | 1018 | printf(" %s\n", _("to test if they are accessible (e.g. to detect Stale NFS Handles)")); |
| 972 | printf(" %s\n", "-M, --mountpoint"); | 1019 | printf(" %s\n", "-M, --mountpoint"); |
| 973 | printf(" %s\n", _("Display the (block) device instead of the mount point")); | 1020 | printf(" %s\n", _("Display the (block) device instead of the mount point")); |
| 974 | printf(" %s\n", "-A, --all"); | 1021 | printf(" %s\n", "-A, --all"); |
| 975 | printf(" %s\n", _("Explicitly select all paths. This is equivalent to -R '.*'")); | 1022 | printf(" %s\n", _("Explicitly select all paths. This is equivalent to -R '.*'")); |
| 976 | printf(" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION"); | 1023 | printf(" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION"); |
| 977 | printf(" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)")); | 1024 | printf(" %s\n", |
| 1025 | _("Case insensitive regular expression for path/partition (may be repeated)")); | ||
| 978 | printf(" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION"); | 1026 | printf(" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION"); |
| 979 | printf(" %s\n", _("Regular expression for path or partition (may be repeated)")); | 1027 | printf(" %s\n", _("Regular expression for path or partition (may be repeated)")); |
| 980 | printf(" %s\n", "-I, --ignore-eregi-path=PATH, --ignore-eregi-partition=PARTITION"); | 1028 | printf(" %s\n", "-I, --ignore-eregi-path=PATH, --ignore-eregi-partition=PARTITION"); |
| 981 | printf(" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)")); | 1029 | printf(" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) " |
| 1030 | "(may be repeated)")); | ||
| 982 | printf(" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION"); | 1031 | printf(" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION"); |
| 983 | printf(" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)")); | 1032 | printf(" %s\n", |
| 1033 | _("Regular expression to ignore selected path or partition (may be repeated)")); | ||
| 984 | printf(" %s\n", "-n, --ignore-missing"); | 1034 | printf(" %s\n", "-n, --ignore-missing"); |
| 985 | printf(" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible.")); | 1035 | printf(" %s\n", |
| 1036 | _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible.")); | ||
| 986 | printf(" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)")); | 1037 | printf(" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)")); |
| 987 | printf(UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 1038 | printf(UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
| 988 | printf(" %s\n", "-u, --units=STRING"); | 1039 | printf(" %s\n", "-u, --units=STRING"); |
| 989 | printf(" %s\n", _("Select the unit used for the absolute value thresholds")); | 1040 | printf(" %s\n", _("Select the unit used for the absolute value thresholds")); |
| 990 | printf( | 1041 | printf(" %s\n", _("Choose one of \"bytes\", \"KiB\", \"kB\", \"MiB\", \"MB\", \"GiB\", " |
| 991 | " %s\n", | 1042 | "\"GB\", \"TiB\", \"TB\", \"PiB\", \"PB\" (default: MiB)")); |
| 992 | _("Choose one of \"bytes\", \"KiB\", \"kB\", \"MiB\", \"MB\", \"GiB\", \"GB\", \"TiB\", \"TB\", \"PiB\", \"PB\" (default: MiB)")); | ||
| 993 | printf(" %s\n", "-k, --kilobytes"); | 1043 | printf(" %s\n", "-k, --kilobytes"); |
| 994 | printf(" %s\n", _("Same as '--units kB'")); | 1044 | printf(" %s\n", _("Same as '--units kB'")); |
| 995 | printf(" %s\n", "--display-unit"); | 1045 | printf(" %s\n", "--display-unit"); |
| 996 | printf(" %s\n", _("Select the unit used for in the output")); | 1046 | printf(" %s\n", _("Select the unit used for in the output")); |
| 997 | printf( | 1047 | printf(" %s\n", _("Choose one of \"bytes\", \"KiB\", \"kB\", \"MiB\", \"MB\", \"GiB\", " |
| 998 | " %s\n", | 1048 | "\"GB\", \"TiB\", \"TB\", \"PiB\", \"PB\" (default: MiB)")); |
| 999 | _("Choose one of \"bytes\", \"KiB\", \"kB\", \"MiB\", \"MB\", \"GiB\", \"GB\", \"TiB\", \"TB\", \"PiB\", \"PB\" (default: MiB)")); | ||
| 1000 | printf(" %s\n", "-m, --megabytes"); | 1049 | printf(" %s\n", "-m, --megabytes"); |
| 1001 | printf(" %s\n", _("Same as '--units MB'")); | 1050 | printf(" %s\n", _("Same as '--units MB'")); |
| 1002 | printf(UT_VERBOSE); | 1051 | printf(UT_VERBOSE); |
| 1003 | printf(" %s\n", "-X, --exclude-type=TYPE_REGEX"); | 1052 | printf(" %s\n", "-X, --exclude-type=TYPE_REGEX"); |
| 1004 | printf(" %s\n", _("Ignore all filesystems of types matching given regex(7) (may be repeated)")); | 1053 | printf(" %s\n", |
| 1054 | _("Ignore all filesystems of types matching given regex(7) (may be repeated)")); | ||
| 1005 | printf(" %s\n", "-N, --include-type=TYPE_REGEX"); | 1055 | printf(" %s\n", "-N, --include-type=TYPE_REGEX"); |
| 1006 | printf(" %s\n", _("Check only filesystems where the type matches this given regex(7) (may be repeated)")); | 1056 | printf( |
| 1057 | " %s\n", | ||
| 1058 | _("Check only filesystems where the type matches this given regex(7) (may be repeated)")); | ||
| 1007 | printf(UT_OUTPUT_FORMAT); | 1059 | printf(UT_OUTPUT_FORMAT); |
| 1008 | 1060 | ||
| 1009 | printf("\n"); | 1061 | printf("\n"); |
| 1010 | printf("%s\n", _("General usage hints:")); | 1062 | printf("%s\n", _("General usage hints:")); |
| 1011 | printf(" %s\n", _("- Arguments are positional! \"-w 5 -c 1 -p /foo -w6 -c2 -p /bar\" is not the same as")); | 1063 | printf( |
| 1064 | " %s\n", | ||
| 1065 | _("- Arguments are positional! \"-w 5 -c 1 -p /foo -w6 -c2 -p /bar\" is not the same as")); | ||
| 1012 | printf(" %s\n", _("\"-w 5 -c 1 -p /bar w6 -c2 -p /foo\".")); | 1066 | printf(" %s\n", _("\"-w 5 -c 1 -p /bar w6 -c2 -p /foo\".")); |
| 1013 | printf(" %s\n", _("- The syntax is broadly: \"{thresholds a} {paths a} -C {thresholds b} {thresholds b} ...\"")); | 1067 | printf(" %s\n", _("- The syntax is broadly: \"{thresholds a} {paths a} -C {thresholds b} " |
| 1068 | "{thresholds b} ...\"")); | ||
| 1014 | 1069 | ||
| 1015 | printf("\n"); | 1070 | printf("\n"); |
| 1016 | printf("%s\n", _("Examples:")); | 1071 | printf("%s\n", _("Examples:")); |
| 1017 | printf(" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /"); | 1072 | printf(" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /"); |
| 1018 | printf(" %s\n\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB")); | 1073 | printf(" %s\n\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB")); |
| 1019 | printf(" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -g sidDATA -r '^/oracle/SID/data.*$'"); | 1074 | printf(" %s\n", |
| 1020 | printf(" %s\n", _("Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex")); | 1075 | "check_disk -w 100 -c 50 -C -w 1000 -c 500 -g sidDATA -r '^/oracle/SID/data.*$'"); |
| 1021 | printf(" %s\n\n", _("are grouped which means the freespace thresholds are applied to all disks together")); | 1076 | printf( |
| 1077 | " %s\n", | ||
| 1078 | _("Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex")); | ||
| 1079 | printf(" %s\n\n", | ||
| 1080 | _("are grouped which means the freespace thresholds are applied to all disks together")); | ||
| 1022 | printf(" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -p /foo -C -w 5% -c 3% -p /bar"); | 1081 | printf(" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -p /foo -C -w 5% -c 3% -p /bar"); |
| 1023 | printf(" %s\n", _("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M")); | 1082 | printf(" %s\n", |
| 1083 | _("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M")); | ||
| 1024 | 1084 | ||
| 1025 | printf(UT_SUPPORT); | 1085 | printf(UT_SUPPORT); |
| 1026 | } | 1086 | } |
| 1027 | 1087 | ||
| 1028 | void print_usage(void) { | 1088 | void print_usage(void) { |
| 1029 | printf("%s\n", _("Usage:")); | 1089 | printf("%s\n", _("Usage:")); |
| 1030 | printf(" %s {-w absolute_limit |-w percentage_limit%% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit%% | -K " | 1090 | printf(" %s {-w absolute_limit |-w percentage_limit%% | -W inode_percentage_limit } {-c " |
| 1091 | "absolute_limit|-c percentage_limit%% | -K " | ||
| 1031 | "inode_percentage_limit } {-p path | -x device}\n", | 1092 | "inode_percentage_limit } {-p path | -x device}\n", |
| 1032 | progname); | 1093 | progname); |
| 1033 | printf("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); | 1094 | printf("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); |
| @@ -1049,13 +1110,15 @@ bool stat_path(parameter_list_elem *parameters, bool ignore_missing) { | |||
| 1049 | return false; | 1110 | return false; |
| 1050 | } | 1111 | } |
| 1051 | printf("DISK %s - ", _("CRITICAL")); | 1112 | printf("DISK %s - ", _("CRITICAL")); |
| 1052 | die(STATE_CRITICAL, _("%s %s: %s\n"), parameters->name, _("is not accessible"), strerror(errno)); | 1113 | die(STATE_CRITICAL, _("%s %s: %s\n"), parameters->name, _("is not accessible"), |
| 1114 | strerror(errno)); | ||
| 1053 | } | 1115 | } |
| 1054 | 1116 | ||
| 1055 | return true; | 1117 | return true; |
| 1056 | } | 1118 | } |
| 1057 | 1119 | ||
| 1058 | static parameter_list_elem get_path_stats(parameter_list_elem parameters, const struct fs_usage fsp, bool freespace_ignore_reserved) { | 1120 | static parameter_list_elem get_path_stats(parameter_list_elem parameters, const struct fs_usage fsp, |
| 1121 | bool freespace_ignore_reserved) { | ||
| 1059 | uintmax_t available = fsp.fsu_bavail; | 1122 | uintmax_t available = fsp.fsu_bavail; |
| 1060 | uintmax_t available_to_root = fsp.fsu_bfree; | 1123 | uintmax_t available_to_root = fsp.fsu_bfree; |
| 1061 | uintmax_t used = fsp.fsu_blocks - fsp.fsu_bfree; | 1124 | uintmax_t used = fsp.fsu_blocks - fsp.fsu_bfree; |
| @@ -1082,7 +1145,8 @@ static parameter_list_elem get_path_stats(parameter_list_elem parameters, const | |||
| 1082 | /* option activated : we subtract the root-reserved inodes from the total */ | 1145 | /* option activated : we subtract the root-reserved inodes from the total */ |
| 1083 | /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */ | 1146 | /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */ |
| 1084 | /* for others, fsp->fsu_ffree == fsp->fsu_favail */ | 1147 | /* for others, fsp->fsu_ffree == fsp->fsu_favail */ |
| 1085 | parameters.inodes_total = fsp.fsu_files - parameters.inodes_free_to_root + parameters.inodes_free; | 1148 | parameters.inodes_total = |
| 1149 | fsp.fsu_files - parameters.inodes_free_to_root + parameters.inodes_free; | ||
| 1086 | } else { | 1150 | } else { |
| 1087 | /* default behaviour : take all the inodes into account */ | 1151 | /* default behaviour : take all the inodes into account */ |
| 1088 | parameters.inodes_total = fsp.fsu_files; | 1152 | parameters.inodes_total = fsp.fsu_files; |
| @@ -1091,7 +1155,8 @@ static parameter_list_elem get_path_stats(parameter_list_elem parameters, const | |||
| 1091 | return parameters; | 1155 | return parameters; |
| 1092 | } | 1156 | } |
| 1093 | 1157 | ||
| 1094 | mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_inodes_perfdata, byte_unit unit) { | 1158 | mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_inodes_perfdata, |
| 1159 | byte_unit unit) { | ||
| 1095 | mp_subcheck result = mp_subcheck_init(); | 1160 | mp_subcheck result = mp_subcheck_init(); |
| 1096 | result = mp_set_subcheck_default_state(result, STATE_UNKNOWN); | 1161 | result = mp_set_subcheck_default_state(result, STATE_UNKNOWN); |
| 1097 | xasprintf(&result.output, "%s", measurement_unit.name); | 1162 | xasprintf(&result.output, "%s", measurement_unit.name); |
| @@ -1108,10 +1173,12 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_ | |||
| 1108 | freespace_bytes_sc = mp_set_subcheck_default_state(freespace_bytes_sc, STATE_OK); | 1173 | freespace_bytes_sc = mp_set_subcheck_default_state(freespace_bytes_sc, STATE_OK); |
| 1109 | 1174 | ||
| 1110 | if (unit != Humanized) { | 1175 | if (unit != Humanized) { |
| 1111 | xasprintf(&freespace_bytes_sc.output, "Free space absolute: %ju%s (of %ju%s)", (uintmax_t)(measurement_unit.free_bytes / unit), | 1176 | xasprintf(&freespace_bytes_sc.output, "Free space absolute: %ju%s (of %ju%s)", |
| 1112 | get_unit_string(unit), (uintmax_t)(measurement_unit.total_bytes / unit), get_unit_string(unit)); | 1177 | (uintmax_t)(measurement_unit.free_bytes / unit), get_unit_string(unit), |
| 1178 | (uintmax_t)(measurement_unit.total_bytes / unit), get_unit_string(unit)); | ||
| 1113 | } else { | 1179 | } else { |
| 1114 | xasprintf(&freespace_bytes_sc.output, "Free space absolute: %s (of %s)", humanize_byte_value(measurement_unit.free_bytes, false), | 1180 | xasprintf(&freespace_bytes_sc.output, "Free space absolute: %s (of %s)", |
| 1181 | humanize_byte_value(measurement_unit.free_bytes, false), | ||
| 1115 | humanize_byte_value((unsigned long long)measurement_unit.total_bytes, false)); | 1182 | humanize_byte_value((unsigned long long)measurement_unit.total_bytes, false)); |
| 1116 | } | 1183 | } |
| 1117 | 1184 | ||
| @@ -1127,29 +1194,37 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_ | |||
| 1127 | // special case for absolute space thresholds here: | 1194 | // special case for absolute space thresholds here: |
| 1128 | // if absolute values are not set, compute the thresholds from percentage thresholds | 1195 | // if absolute values are not set, compute the thresholds from percentage thresholds |
| 1129 | mp_thresholds temp_thlds = measurement_unit.freespace_bytes_thresholds; | 1196 | mp_thresholds temp_thlds = measurement_unit.freespace_bytes_thresholds; |
| 1130 | if (!temp_thlds.critical_is_set && measurement_unit.freespace_percent_thresholds.critical_is_set) { | 1197 | if (!temp_thlds.critical_is_set && |
| 1198 | measurement_unit.freespace_percent_thresholds.critical_is_set) { | ||
| 1131 | mp_range tmp_range = measurement_unit.freespace_percent_thresholds.critical; | 1199 | mp_range tmp_range = measurement_unit.freespace_percent_thresholds.critical; |
| 1132 | 1200 | ||
| 1133 | if (!tmp_range.end_infinity) { | 1201 | if (!tmp_range.end_infinity) { |
| 1134 | tmp_range.end = mp_create_pd_value(mp_get_pd_value(tmp_range.end) / 100 * measurement_unit.total_bytes); | 1202 | tmp_range.end = mp_create_pd_value(mp_get_pd_value(tmp_range.end) / 100 * |
| 1203 | measurement_unit.total_bytes); | ||
| 1135 | } | 1204 | } |
| 1136 | 1205 | ||
| 1137 | if (!tmp_range.start_infinity) { | 1206 | if (!tmp_range.start_infinity) { |
| 1138 | tmp_range.start = mp_create_pd_value(mp_get_pd_value(tmp_range.start) / 100 * measurement_unit.total_bytes); | 1207 | tmp_range.start = mp_create_pd_value(mp_get_pd_value(tmp_range.start) / 100 * |
| 1208 | measurement_unit.total_bytes); | ||
| 1139 | } | 1209 | } |
| 1140 | measurement_unit.freespace_bytes_thresholds = mp_thresholds_set_crit(measurement_unit.freespace_bytes_thresholds, tmp_range); | 1210 | measurement_unit.freespace_bytes_thresholds = |
| 1211 | mp_thresholds_set_crit(measurement_unit.freespace_bytes_thresholds, tmp_range); | ||
| 1141 | used_space = mp_pd_set_thresholds(used_space, measurement_unit.freespace_bytes_thresholds); | 1212 | used_space = mp_pd_set_thresholds(used_space, measurement_unit.freespace_bytes_thresholds); |
| 1142 | } | 1213 | } |
| 1143 | 1214 | ||
| 1144 | if (!temp_thlds.warning_is_set && measurement_unit.freespace_percent_thresholds.warning_is_set) { | 1215 | if (!temp_thlds.warning_is_set && |
| 1216 | measurement_unit.freespace_percent_thresholds.warning_is_set) { | ||
| 1145 | mp_range tmp_range = measurement_unit.freespace_percent_thresholds.warning; | 1217 | mp_range tmp_range = measurement_unit.freespace_percent_thresholds.warning; |
| 1146 | if (!tmp_range.end_infinity) { | 1218 | if (!tmp_range.end_infinity) { |
| 1147 | tmp_range.end = mp_create_pd_value(mp_get_pd_value(tmp_range.end) / 100 * measurement_unit.total_bytes); | 1219 | tmp_range.end = mp_create_pd_value(mp_get_pd_value(tmp_range.end) / 100 * |
| 1220 | measurement_unit.total_bytes); | ||
| 1148 | } | 1221 | } |
| 1149 | if (!tmp_range.start_infinity) { | 1222 | if (!tmp_range.start_infinity) { |
| 1150 | tmp_range.start = mp_create_pd_value(mp_get_pd_value(tmp_range.start) / 100 * measurement_unit.total_bytes); | 1223 | tmp_range.start = mp_create_pd_value(mp_get_pd_value(tmp_range.start) / 100 * |
| 1224 | measurement_unit.total_bytes); | ||
| 1151 | } | 1225 | } |
| 1152 | measurement_unit.freespace_bytes_thresholds = mp_thresholds_set_warn(measurement_unit.freespace_bytes_thresholds, tmp_range); | 1226 | measurement_unit.freespace_bytes_thresholds = |
| 1227 | mp_thresholds_set_warn(measurement_unit.freespace_bytes_thresholds, tmp_range); | ||
| 1153 | used_space = mp_pd_set_thresholds(used_space, measurement_unit.freespace_bytes_thresholds); | 1228 | used_space = mp_pd_set_thresholds(used_space, measurement_unit.freespace_bytes_thresholds); |
| 1154 | } | 1229 | } |
| 1155 | 1230 | ||
| @@ -1161,15 +1236,18 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_ | |||
| 1161 | mp_subcheck freespace_percent_sc = mp_subcheck_init(); | 1236 | mp_subcheck freespace_percent_sc = mp_subcheck_init(); |
| 1162 | freespace_percent_sc = mp_set_subcheck_default_state(freespace_percent_sc, STATE_OK); | 1237 | freespace_percent_sc = mp_set_subcheck_default_state(freespace_percent_sc, STATE_OK); |
| 1163 | 1238 | ||
| 1164 | double free_percentage = calculate_percent(measurement_unit.free_bytes, measurement_unit.total_bytes); | 1239 | double free_percentage = |
| 1240 | calculate_percent(measurement_unit.free_bytes, measurement_unit.total_bytes); | ||
| 1165 | xasprintf(&freespace_percent_sc.output, "Free space percentage: %g%%", free_percentage); | 1241 | xasprintf(&freespace_percent_sc.output, "Free space percentage: %g%%", free_percentage); |
| 1166 | 1242 | ||
| 1167 | // Using perfdata here just to get to the test result | 1243 | // Using perfdata here just to get to the test result |
| 1168 | mp_perfdata free_space_percent_pd = perfdata_init(); | 1244 | mp_perfdata free_space_percent_pd = perfdata_init(); |
| 1169 | free_space_percent_pd.value = mp_create_pd_value(free_percentage); | 1245 | free_space_percent_pd.value = mp_create_pd_value(free_percentage); |
| 1170 | free_space_percent_pd = mp_pd_set_thresholds(free_space_percent_pd, measurement_unit.freespace_percent_thresholds); | 1246 | free_space_percent_pd = |
| 1247 | mp_pd_set_thresholds(free_space_percent_pd, measurement_unit.freespace_percent_thresholds); | ||
| 1171 | 1248 | ||
| 1172 | freespace_percent_sc = mp_set_subcheck_state(freespace_percent_sc, mp_get_pd_status(free_space_percent_pd)); | 1249 | freespace_percent_sc = |
| 1250 | mp_set_subcheck_state(freespace_percent_sc, mp_get_pd_status(free_space_percent_pd)); | ||
| 1173 | mp_add_subcheck_to_subcheck(&result, freespace_percent_sc); | 1251 | mp_add_subcheck_to_subcheck(&result, freespace_percent_sc); |
| 1174 | 1252 | ||
| 1175 | // ================ | 1253 | // ================ |
| @@ -1181,35 +1259,41 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_ | |||
| 1181 | mp_subcheck freeindodes_percent_sc = mp_subcheck_init(); | 1259 | mp_subcheck freeindodes_percent_sc = mp_subcheck_init(); |
| 1182 | freeindodes_percent_sc = mp_set_subcheck_default_state(freeindodes_percent_sc, STATE_OK); | 1260 | freeindodes_percent_sc = mp_set_subcheck_default_state(freeindodes_percent_sc, STATE_OK); |
| 1183 | 1261 | ||
| 1184 | double free_inode_percentage = calculate_percent(measurement_unit.inodes_free, measurement_unit.inodes_total); | 1262 | double free_inode_percentage = |
| 1263 | calculate_percent(measurement_unit.inodes_free, measurement_unit.inodes_total); | ||
| 1185 | 1264 | ||
| 1186 | if (verbose > 0) { | 1265 | if (verbose > 0) { |
| 1187 | printf("free inode percentage computed: %g\n", free_inode_percentage); | 1266 | printf("free inode percentage computed: %g\n", free_inode_percentage); |
| 1188 | } | 1267 | } |
| 1189 | 1268 | ||
| 1190 | xasprintf(&freeindodes_percent_sc.output, "Inodes free: %g%% (%ju of %ju)", free_inode_percentage, measurement_unit.inodes_free, | 1269 | xasprintf(&freeindodes_percent_sc.output, "Inodes free: %g%% (%ju of %ju)", |
| 1270 | free_inode_percentage, measurement_unit.inodes_free, | ||
| 1191 | measurement_unit.inodes_total); | 1271 | measurement_unit.inodes_total); |
| 1192 | 1272 | ||
| 1193 | mp_perfdata inodes_pd = perfdata_init(); | 1273 | mp_perfdata inodes_pd = perfdata_init(); |
| 1194 | xasprintf(&inodes_pd.label, "%s (inodes)", measurement_unit.name); | 1274 | xasprintf(&inodes_pd.label, "%s (inodes)", measurement_unit.name); |
| 1195 | inodes_pd = mp_set_pd_value(inodes_pd, measurement_unit.inodes_used); | 1275 | inodes_pd = mp_set_pd_value(inodes_pd, measurement_unit.inodes_used); |
| 1196 | inodes_pd = mp_set_pd_max_value(inodes_pd, mp_create_pd_value(measurement_unit.inodes_total)); | 1276 | inodes_pd = |
| 1277 | mp_set_pd_max_value(inodes_pd, mp_create_pd_value(measurement_unit.inodes_total)); | ||
| 1197 | inodes_pd = mp_set_pd_min_value(inodes_pd, mp_create_pd_value(0)); | 1278 | inodes_pd = mp_set_pd_min_value(inodes_pd, mp_create_pd_value(0)); |
| 1198 | 1279 | ||
| 1199 | mp_thresholds absolut_inode_thresholds = measurement_unit.freeinodes_percent_thresholds; | 1280 | mp_thresholds absolut_inode_thresholds = measurement_unit.freeinodes_percent_thresholds; |
| 1200 | 1281 | ||
| 1201 | if (absolut_inode_thresholds.critical_is_set) { | 1282 | if (absolut_inode_thresholds.critical_is_set) { |
| 1202 | absolut_inode_thresholds.critical = | 1283 | absolut_inode_thresholds.critical = |
| 1203 | mp_range_multiply(absolut_inode_thresholds.critical, mp_create_pd_value(measurement_unit.inodes_total / 100)); | 1284 | mp_range_multiply(absolut_inode_thresholds.critical, |
| 1285 | mp_create_pd_value(measurement_unit.inodes_total / 100)); | ||
| 1204 | } | 1286 | } |
| 1205 | if (absolut_inode_thresholds.warning_is_set) { | 1287 | if (absolut_inode_thresholds.warning_is_set) { |
| 1206 | absolut_inode_thresholds.warning = | 1288 | absolut_inode_thresholds.warning = |
| 1207 | mp_range_multiply(absolut_inode_thresholds.warning, mp_create_pd_value(measurement_unit.inodes_total / 100)); | 1289 | mp_range_multiply(absolut_inode_thresholds.warning, |
| 1290 | mp_create_pd_value(measurement_unit.inodes_total / 100)); | ||
| 1208 | } | 1291 | } |
| 1209 | 1292 | ||
| 1210 | inodes_pd = mp_pd_set_thresholds(inodes_pd, absolut_inode_thresholds); | 1293 | inodes_pd = mp_pd_set_thresholds(inodes_pd, absolut_inode_thresholds); |
| 1211 | 1294 | ||
| 1212 | freeindodes_percent_sc = mp_set_subcheck_state(freeindodes_percent_sc, mp_get_pd_status(inodes_pd)); | 1295 | freeindodes_percent_sc = |
| 1296 | mp_set_subcheck_state(freeindodes_percent_sc, mp_get_pd_status(inodes_pd)); | ||
| 1213 | if (display_inodes_perfdata) { | 1297 | if (display_inodes_perfdata) { |
| 1214 | mp_add_perfdata_to_subcheck(&freeindodes_percent_sc, inodes_pd); | 1298 | mp_add_perfdata_to_subcheck(&freeindodes_percent_sc, inodes_pd); |
| 1215 | } | 1299 | } |
