summaryrefslogtreecommitdiffstats
path: root/web/attachments/94931-check_disk-patch
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/94931-check_disk-patch')
-rw-r--r--web/attachments/94931-check_disk-patch273
1 files changed, 273 insertions, 0 deletions
diff --git a/web/attachments/94931-check_disk-patch b/web/attachments/94931-check_disk-patch
new file mode 100644
index 0000000..4920cc1
--- /dev/null
+++ b/web/attachments/94931-check_disk-patch
@@ -0,0 +1,273 @@
1--- check_disk.c-dist Thu Jul 22 15:46:18 2004
2+++ check_disk.c Fri Jul 23 12:38:12 2004
3@@ -21,6 +21,10 @@
4 const char *copyright = "1999-2003";
5 const char *email = "nagiosplug-devel@lists.sourceforge.net";
6
7+/*
8+ * Additional inode code by Jorgen Lundman <lundman@lundman.net>
9+ */
10+
11 #include "common.h"
12 #if HAVE_INTTYPES_H
13 # include <inttypes.h>
14@@ -65,6 +69,8 @@
15 uintmax_t c_df;
16 double w_dfp;
17 double c_dfp;
18+ double w_idfp;
19+ double c_idfp;
20 struct name_list *name_next;
21 };
22
23@@ -110,8 +116,8 @@
24
25 int process_arguments (int, char **);
26 void print_path (const char *mypath);
27-int validate_arguments (uintmax_t, uintmax_t, double, double, char *);
28-int check_disk (double usp, uintmax_t free_disk);
29+int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
30+int check_disk (double usp, uintmax_t free_disk, double uisp);
31 int walk_name_list (struct name_list *list, const char *name);
32 void print_help (void);
33 void print_usage (void);
34@@ -120,6 +126,8 @@
35 uintmax_t c_df = 0;
36 double w_dfp = -1.0;
37 double c_dfp = -1.0;
38+double w_idfp = -1.0;
39+double c_idfp = -1.0;
40 char *path;
41 char *exclude_device;
42 char *units;
43@@ -136,7 +144,7 @@
44 int
45 main (int argc, char **argv)
46 {
47- double usp = -1.0;
48+ double usp = -1.0, uisp = -1.0;
49 int result = STATE_UNKNOWN;
50 int disk_result = STATE_UNKNOWN;
51 char file_system[MAX_INPUT_BUFFER];
52@@ -144,7 +152,7 @@
53 char *details;
54 char *perf;
55 uintmax_t psize;
56- float free_space, free_space_pct, total_space;
57+ float free_space, free_space_pct, total_space, inode_space_pct;
58
59 struct mount_entry *me;
60 struct fs_usage fsp;
61@@ -181,20 +189,26 @@
62 (walk_name_list (dp_exclude_list, me->me_devname) ||
63 walk_name_list (dp_exclude_list, me->me_mountdir)))
64 continue;
65- else
66+ else
67 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
68
69 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
70 usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks;
71- disk_result = check_disk (usp, fsp.fsu_bavail);
72+ uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files;
73+ disk_result = check_disk (usp, fsp.fsu_bavail, uisp);
74 result = max_state (disk_result, result);
75 psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult;
76+
77+ /* Moved this computation up here so we can add it
78+ * to perf */
79+ inode_space_pct = (float)fsp.fsu_ffree*100/fsp.fsu_files;
80+
81 asprintf (&perf, "%s %s", perf,
82 perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
83 fsp.fsu_bavail*fsp.fsu_blocksize/mult, units,
84 TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)),
85 TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)),
86- TRUE, 0,
87+ TRUE, inode_space_pct,
88 TRUE, psize));
89 if (disk_result==STATE_OK && erronly && !verbose)
90 continue;
91@@ -203,17 +217,20 @@
92 free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks;
93 total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult;
94 if (disk_result!=STATE_OK || verbose>=0)
95- asprintf (&output, ("%s %s %.0f %s (%.0f%%);"),
96+ asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"),
97 output,
98 (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
99 free_space,
100 units,
101- free_space_pct);
102+ free_space_pct,
103+ inode_space_pct);
104+
105 asprintf (&details, _("%s\n\
106-%.0f of %.0f %s (%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
107- details, free_space, total_space, units, free_space_pct,
108+%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
109+ details, free_space, total_space, units, free_space_pct, inode_space_pct,
110 me->me_devname, me->me_type, me->me_mountdir,
111 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
112+
113 }
114
115 }
116@@ -259,6 +276,9 @@
117 {"timeout", required_argument, 0, 't'},
118 {"warning", required_argument, 0, 'w'},
119 {"critical", required_argument, 0, 'c'},
120+ {"iwarning", required_argument, 0, 'W'},
121+ /* Dang, -C is taken. We might want to reshuffle this. */
122+ {"icritical", required_argument, 0, 'K'},
123 {"local", required_argument, 0, 'l'},
124 {"kilobytes", required_argument, 0, 'k'},
125 {"megabytes", required_argument, 0, 'm'},
126@@ -291,7 +311,7 @@
127 strcpy (argv[c], "-t");
128
129 while (1) {
130- c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", longopts, &option);
131+ c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option);
132
133 if (c == -1 || c == EOF)
134 break;
135@@ -339,6 +359,24 @@
136 else {
137 usage (_("Critical threshold must be integer or percentage!\n"));
138 }
139+
140+
141+ case 'W': /* warning inode threshold */
142+ if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_idfp) == 1) {
143+ break;
144+ }
145+ else {
146+ usage (_("Warning inode threshold must be percentage!\n"));
147+ }
148+ case 'K': /* kritical inode threshold */
149+ if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) {
150+ break;
151+ }
152+ else {
153+ usage (_("Critical inode threshold must be percentage!\n"));
154+ }
155+
156+
157 case 'u':
158 if (units)
159 free(units);
160@@ -393,6 +431,14 @@
161 se = (struct name_list *) malloc (sizeof (struct name_list));
162 se->name = optarg;
163 se->name_next = NULL;
164+ /* If you don't clear the w_fd etc values here, they
165+ * get processed when you walk the list and assigned
166+ * to the global w_df!
167+ */
168+ se->w_df = 0;
169+ se->c_df = 0;
170+ se->w_dfp = 0;
171+ se->c_dfp = 0;
172 *dptail = se;
173 dptail = &se->name_next;
174 break;
175@@ -400,6 +446,14 @@
176 se = (struct name_list *) malloc (sizeof (struct name_list));
177 se->name = optarg;
178 se->name_next = NULL;
179+ /* If you don't clear the w_fd etc values here, they
180+ * get processed when you walk the list and assigned
181+ * to the global w_df!
182+ */
183+ se->w_df = 0;
184+ se->c_df = 0;
185+ se->w_dfp = 0;
186+ se->c_dfp = 0;
187 *fstail = se;
188 fstail = &se->name_next;
189 break;
190@@ -459,6 +513,8 @@
191 temp_list->c_df,
192 temp_list->w_dfp,
193 temp_list->c_dfp,
194+ temp_list->w_idfp,
195+ temp_list->c_idfp,
196 temp_list->name) == ERROR)
197 result = ERROR;
198 temp_list = temp_list->name_next;
199@@ -465,7 +521,7 @@
200 }
201 return result;
202 } else {
203- return validate_arguments (w_df, c_df, w_dfp, c_dfp, NULL);
204+ return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL);
205 }
206 }
207
208@@ -482,7 +538,7 @@
209 }
210
211 int
212-validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, char *mypath)
213+validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath)
214 {
215 if (w == 0 && c == 0 && wp < 0.0 && cp < 0.0) {
216 printf (_("INPUT ERROR: No thresholds specified"));
217@@ -497,6 +553,14 @@
218 print_path (mypath);
219 return ERROR;
220 }
221+ else if ((iwp >= 0.0 || icp >= 0.0) &&
222+ (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) {
223+ printf (_("\
224+INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"),
225+ icp, iwp);
226+ print_path (mypath);
227+ return ERROR;
228+ }
229 else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) {
230 printf (_("\
231 INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"),
232@@ -516,16 +580,20 @@
233
234
235 int
236-check_disk (double usp, uintmax_t free_disk)
237+check_disk (double usp, uintmax_t free_disk, double uisp)
238 {
239 int result = STATE_UNKNOWN;
240 /* check the percent used space against thresholds */
241 if (usp >= 0.0 && c_dfp >=0.0 && usp >= (100.0 - c_dfp))
242 result = STATE_CRITICAL;
243+ else if (uisp >= 0.0 && c_idfp >=0.0 && uisp >= (100.0 - c_idfp))
244+ result = STATE_CRITICAL;
245 else if (c_df > 0 && free_disk <= c_df)
246 result = STATE_CRITICAL;
247 else if (usp >= 0.0 && w_dfp >=0.0 && usp >= (100.0 - w_dfp))
248 result = STATE_WARNING;
249+ else if (uisp >= 0.0 && w_idfp >=0.0 && uisp >= (100.0 - w_idfp))
250+ result = STATE_WARNING;
251 else if (w_df > 0 && free_disk <= w_df)
252 result = STATE_WARNING;
253 else if (usp >= 0.0)
254@@ -579,6 +647,10 @@
255 Exit with WARNING status if less than INTEGER kilobytes of disk are free\n\
256 -w, --warning=PERCENT%%\n\
257 Exit with WARNING status if less than PERCENT of disk space is free\n\
258+ -W, --iwarning=PERCENT%%\n\
259+ Exit with WARNING status if less than PERCENT of inode space is free\n\
260+ -K, --icritical=PERCENT%%\n\
261+ Exit with CRITICAL status if less than PERCENT of inode space is free\n\
262 -c, --critical=INTEGER\n\
263 Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n\
264 -c, --critical=PERCENT%%\n\
265@@ -628,7 +700,7 @@
266 print_usage (void)
267 {
268 printf (_("\
269-Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e]\n\
270+Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e] [-W limit] [-K limit]\n\
271 [-v] [-q]\n\
272 %s (-h|--help)\n\
273 %s (-V|--version)\n"),