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