summaryrefslogtreecommitdiffstats
path: root/web/attachments/357353-interdiff.txt
blob: aaf329951e686531f048319b7e27e3b3bbaecb6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--- 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 <limits.h>
 #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