--- nagios-plugins-1.4.13+git200906171200.orig/plugins/check_disk.c +++ nagios-plugins-1.4.13+git200906171200/plugins/check_disk.c @@ -3,7 +3,7 @@ * Nagios check_disk plugin * * License: GPL -* Copyright (c) 1999-2008 Nagios Plugins Development Team +* Copyright (c) 1999-2010 Nagios Plugins Development Team * * Description: * @@ -28,7 +28,7 @@ const char *progname = "check_disk"; const char *program_name = "check_disk"; /* Required for coreutils libs */ -const char *copyright = "1999-2008"; +const char *copyright = "1999-2010"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; @@ -51,6 +51,7 @@ # include #endif #include "regex.h" +#include "human.h" /* If nonzero, show inode information. */ @@ -129,6 +130,7 @@ char *exclude_device; char *units; uintmax_t mult = 1024 * 1024; +int human_readable_units = FALSE; int verbose = 0; int erronly = FALSE; int display_mntp = FALSE; @@ -167,6 +169,8 @@ double warning_high_tide; double critical_high_tide; int temp_result; + char buf[LONGEST_HUMAN_READABLE]; + int human_opts = human_suppress_point_zero | human_autoscale | human_SI | human_group_digits | human_base_1024; struct mount_entry *me; struct fs_usage fsp, tmpfsp; @@ -389,12 +393,19 @@ if (disk_result==STATE_OK && erronly && !verbose) continue; - asprintf (&output, "%s %s %.0f %s (%.0f%%", - output, - (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, - dfree_units, - units, - dfree_pct); + if (human_readable_units) + asprintf (&output, "%s %s %s (%.0f%%", + output, + (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, + human_readable (available, buf, human_opts, fsp.fsu_blocksize, 1), + dfree_pct); + else + asprintf (&output, "%s %s %.0f %s (%.0f%%", + output, + (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, + dfree_units, + units, + dfree_pct); if (dused_inodes_percent < 0) { asprintf(&output, "%s inode=-);", output); } else { @@ -473,6 +484,7 @@ {"kilobytes", no_argument, 0, 'k'}, {"megabytes", no_argument, 0, 'm'}, {"units", required_argument, 0, 'u'}, + {"human-readable", no_argument, 0, 'Z'}, {"path", required_argument, 0, 'p'}, {"partition", required_argument, 0, 'p'}, {"exclude_device", required_argument, 0, 'x'}, @@ -601,6 +613,9 @@ if (units == NULL) die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units"); break; + case 'Z': /* human readable */ + human_readable_units = TRUE; + break; case 'k': /* display mountpoint */ mult = 1024; if (units) @@ -958,6 +973,8 @@ printf (_(UT_VERBOSE)); printf (" %s\n", "-X, --exclude-type=TYPE"); printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)")); + printf (" %s\n", "--human-readable"); + printf (" %s\n", _("Print sizes in human readable format (e.g., 1K 234M 2G)")); #ifdef NP_EXTRA_OPTS printf ("\n"); @@ -986,7 +1003,7 @@ printf (_("Usage:")); printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname); printf ("[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); - printf ("[-t timeout] [-u unit] [-v] [-X type]\n"); + printf ("[-t timeout] [-u unit] [-v] [-X type] [--human-readable]\n"); } void