summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c1073
1 files changed, 584 insertions, 489 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 81dd6c7..3a5f476 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -19,9 +19,9 @@
19*****************************************************************************/ 19*****************************************************************************/
20 20
21const char *progname = "check_disk"; 21const char *progname = "check_disk";
22const char *program_name = "check_disk"; /* Required for coreutils libs */ 22const char *program_name = "check_disk"; /* Required for coreutils libs */
23const char *revision = "$Revision$"; 23const char *revision = "$Revision$";
24const char *copyright = "1999-2004"; 24const char *copyright = "1999-2005";
25const char *email = "nagiosplug-devel@lists.sourceforge.net"; 25const char *email = "nagiosplug-devel@lists.sourceforge.net";
26 26
27 /* 27 /*
@@ -149,92 +149,92 @@ static struct mount_entry *mount_list;
149int 149int
150main (int argc, char **argv) 150main (int argc, char **argv)
151{ 151{
152 double usp = -1.0, uisp = -1.0; 152 double usp = -1.0, uisp = -1.0;
153 int result = STATE_UNKNOWN; 153 int result = STATE_UNKNOWN;
154 int disk_result = STATE_UNKNOWN; 154 int disk_result = STATE_UNKNOWN;
155 char file_system[MAX_INPUT_BUFFER]; 155 char file_system[MAX_INPUT_BUFFER];
156 char *output; 156 char *output;
157 char *details; 157 char *details;
158 char *perf; 158 char *perf;
159 uintmax_t psize; 159 uintmax_t psize;
160 float free_space, free_space_pct, total_space, inode_space_pct; 160 float free_space, free_space_pct, total_space, inode_space_pct;
161 161
162 struct mount_entry *me; 162 struct mount_entry *me;
163 struct fs_usage fsp; 163 struct fs_usage fsp;
164 struct name_list *temp_list; 164 struct name_list *temp_list;
165 165
166 output = strdup (" - free space:"); 166 output = strdup (" - free space:");
167 details = strdup (""); 167 details = strdup ("");
168 perf = strdup (""); 168 perf = strdup ("");
169 169
170 setlocale (LC_ALL, ""); 170 setlocale (LC_ALL, "");
171 bindtextdomain (PACKAGE, LOCALEDIR); 171 bindtextdomain (PACKAGE, LOCALEDIR);
172 textdomain (PACKAGE); 172 textdomain (PACKAGE);
173 173
174 mount_list = read_filesystem_list (0); 174 mount_list = read_filesystem_list (0);
175 175
176 if (process_arguments (argc, argv) == ERROR) 176 if (process_arguments (argc, argv) == ERROR)
177 usage4 (_("Could not parse arguments")); 177 usage4 (_("Could not parse arguments"));
178 178
179 /* if a list of paths has been selected, preseed the list with 179 /* if a list of paths has been selected, preseed the list with
180 * the longest matching filesystem name by iterating across 180 * the longest matching filesystem name by iterating across
181 * the mountlist once ahead of time. this will allow a query on 181 * the mountlist once ahead of time. this will allow a query on
182 * "/var/log" to return information about "/var" if no "/var/log" 182 * "/var/log" to return information about "/var" if no "/var/log"
183 * filesystem exists, etc. this is the default behavior already 183 * filesystem exists, etc. this is the default behavior already
184 * with df-based checks, but for systems with their own space 184 * with df-based checks, but for systems with their own space
185 * checking routines, this should make them more consistent. 185 * checking routines, this should make them more consistent.
186 */ 186 */
187 if(path_select_list){ 187 if(path_select_list){
188 for (me = mount_list; me; me = me->me_next) { 188 for (me = mount_list; me; me = me->me_next) {
189 walk_name_list(path_select_list, me->me_mountdir); 189 walk_name_list(path_select_list, me->me_mountdir);
190 walk_name_list(path_select_list, me->me_devname); 190 walk_name_list(path_select_list, me->me_devname);
191 } 191 }
192 /* now pretend we never saw anything, but keep found_len. 192 /* now pretend we never saw anything, but keep found_len.
193 * thus future searches will only match the best match */ 193 * thus future searches will only match the best match */
194 for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next){ 194 for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next){
195 temp_list->found=0; 195 temp_list->found=0;
196 } 196 }
197 } 197 }
198 198
199 /* for every mount entry */ 199 /* for every mount entry */
200 for (me = mount_list; me; me = me->me_next) { 200 for (me = mount_list; me; me = me->me_next) {
201 /* if there's a list of paths to select, the current mount 201 /* if there's a list of paths to select, the current mount
202 * entry matches in path or device name, get fs usage */ 202 * entry matches in path or device name, get fs usage */
203 if (path_select_list && 203 if (path_select_list &&
204 (walk_name_list (path_select_list, me->me_mountdir) || 204 (walk_name_list (path_select_list, me->me_mountdir) ||
205 walk_name_list (path_select_list, me->me_devname) ) ) { 205 walk_name_list (path_select_list, me->me_devname) ) ) {
206 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 206 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
207 /* else if there's a list of paths/devices to select (but 207 /* else if there's a list of paths/devices to select (but
208 * we didn't match above) skip to the next mount entry */ 208 * we didn't match above) skip to the next mount entry */
209 } else if (dev_select_list || path_select_list) { 209 } else if (dev_select_list || path_select_list) {
210 continue; 210 continue;
211 /* skip remote filesystems if we're not interested in them */ 211 /* skip remote filesystems if we're not interested in them */
212 } else if (me->me_remote && show_local_fs) { 212 } else if (me->me_remote && show_local_fs) {
213 continue; 213 continue;
214 /* skip pseudo fs's if we haven't asked for all fs's */ 214 /* skip pseudo fs's if we haven't asked for all fs's */
215 } else if (me->me_dummy && !show_all_fs) { 215 } else if (me->me_dummy && !show_all_fs) {
216 continue; 216 continue;
217 /* skip excluded fstypes */ 217 /* skip excluded fstypes */
218 } else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) { 218 } else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) {
219 continue; 219 continue;
220 /* skip excluded fs's */ 220 /* skip excluded fs's */
221 } else if (dp_exclude_list && 221 } else if (dp_exclude_list &&
222 (walk_name_list (dp_exclude_list, me->me_devname) || 222 (walk_name_list (dp_exclude_list, me->me_devname) ||
223 walk_name_list (dp_exclude_list, me->me_mountdir))) { 223 walk_name_list (dp_exclude_list, me->me_mountdir))) {
224 continue; 224 continue;
225 /* otherwise, get fs usage */ 225 /* otherwise, get fs usage */
226 } else { 226 } else {
227 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 227 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
228 } 228 }
229 229
230 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { 230 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
231 usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; 231 usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks;
232 uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files; 232 uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files;
233 disk_result = check_disk (usp, fsp.fsu_bavail, uisp); 233 disk_result = check_disk (usp, fsp.fsu_bavail, uisp);
234 234
235 235
236 result = max_state (disk_result, result); 236 result = max_state (disk_result, result);
237 psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult; 237 psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult;
238 238
239 239
240 /* Moved this computation up here so we can add it 240 /* Moved this computation up here so we can add it
@@ -242,56 +242,56 @@ main (int argc, char **argv)
242 inode_space_pct = (float)fsp.fsu_ffree*100/fsp.fsu_files; 242 inode_space_pct = (float)fsp.fsu_ffree*100/fsp.fsu_files;
243 243
244 244
245 asprintf (&perf, "%s %s", perf, 245 asprintf (&perf, "%s %s", perf,
246 perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 246 perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
247 psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units, 247 psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units,
248 TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)), 248 TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)),
249 TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)), 249 TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)),
250 TRUE, inode_space_pct, 250 TRUE, inode_space_pct,
251 251
252 TRUE, psize)); 252 TRUE, psize));
253 if (disk_result==STATE_OK && erronly && !verbose) 253 if (disk_result==STATE_OK && erronly && !verbose)
254 continue; 254 continue;
255 255
256 free_space = (float)fsp.fsu_bavail*fsp.fsu_blocksize/mult; 256 free_space = (float)fsp.fsu_bavail*fsp.fsu_blocksize/mult;
257 free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks; 257 free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks;
258 total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult; 258 total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult;
259 if (disk_result!=STATE_OK || verbose>=0) 259 if (disk_result!=STATE_OK || verbose>=0)
260 asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"), 260 asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"),
261 output, 261 output,
262 (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 262 (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
263 free_space, 263 free_space,
264 units, 264 units,
265 free_space_pct, 265 free_space_pct,
266 inode_space_pct); 266 inode_space_pct);
267 267
268 asprintf (&details, _("%s\n\ 268 asprintf (&details, _("%s\n\
269%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), 269%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
270 details, free_space, total_space, units, free_space_pct, inode_space_pct, 270 details, free_space, total_space, units, free_space_pct, inode_space_pct,
271 me->me_devname, me->me_type, me->me_mountdir, 271 me->me_devname, me->me_type, me->me_mountdir,
272 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); 272 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
273 273
274 } 274 }
275 275
276 } 276 }
277 277
278 asprintf (&output, "%s|%s", output, perf); 278 asprintf (&output, "%s|%s", output, perf);
279 279
280 if (verbose > 2) 280 if (verbose > 2)
281 asprintf (&output, "%s%s", output, details); 281 asprintf (&output, "%s%s", output, details);
282 282
283 /* Override result if paths specified and not found */ 283 /* Override result if paths specified and not found */
284 temp_list = path_select_list; 284 temp_list = path_select_list;
285 while (temp_list) { 285 while (temp_list) {
286 if (!temp_list->found) { 286 if (!temp_list->found) {
287 asprintf (&output, _("%s [%s not found]"), output, temp_list->name); 287 asprintf (&output, _("%s [%s not found]"), output, temp_list->name);
288 result = STATE_CRITICAL; 288 result = STATE_CRITICAL;
289 } 289 }
290 temp_list = temp_list->name_next; 290 temp_list = temp_list->name_next;
291 } 291 }
292 292
293 printf ("DISK %s%s\n", state_text (result), output); 293 printf ("DISK %s%s\n", state_text (result), output);
294 return result; 294 return result;
295} 295}
296 296
297 297
@@ -300,106 +300,106 @@ main (int argc, char **argv)
300int 300int
301process_arguments (int argc, char **argv) 301process_arguments (int argc, char **argv)
302{ 302{
303 int c; 303 int c;
304 struct name_list *se; 304 struct name_list *se;
305 struct name_list **pathtail = &path_select_list; 305 struct name_list **pathtail = &path_select_list;
306 struct name_list **fstail = &fs_exclude_list; 306 struct name_list **fstail = &fs_exclude_list;
307 struct name_list **dptail = &dp_exclude_list; 307 struct name_list **dptail = &dp_exclude_list;
308 struct name_list *temp_list; 308 struct name_list *temp_list;
309 int result = OK; 309 int result = OK;
310 310
311 unsigned long l; 311 unsigned long l;
312 312
313 int option = 0; 313 int option = 0;
314 static struct option longopts[] = { 314 static struct option longopts[] = {
315 {"timeout", required_argument, 0, 't'}, 315 {"timeout", required_argument, 0, 't'},
316 {"warning", required_argument, 0, 'w'}, 316 {"warning", required_argument, 0, 'w'},
317 {"critical", required_argument, 0, 'c'}, 317 {"critical", required_argument, 0, 'c'},
318 {"iwarning", required_argument, 0, 'W'}, 318 {"iwarning", required_argument, 0, 'W'},
319 /* Dang, -C is taken. We might want to reshuffle this. */ 319 /* Dang, -C is taken. We might want to reshuffle this. */
320 {"icritical", required_argument, 0, 'K'}, 320 {"icritical", required_argument, 0, 'K'},
321 {"local", required_argument, 0, 'l'}, 321 {"local", required_argument, 0, 'l'},
322 {"kilobytes", required_argument, 0, 'k'}, 322 {"kilobytes", required_argument, 0, 'k'},
323 {"megabytes", required_argument, 0, 'm'}, 323 {"megabytes", required_argument, 0, 'm'},
324 {"units", required_argument, 0, 'u'}, 324 {"units", required_argument, 0, 'u'},
325 {"path", required_argument, 0, 'p'}, 325 {"path", required_argument, 0, 'p'},
326 {"partition", required_argument, 0, 'p'}, 326 {"partition", required_argument, 0, 'p'},
327 {"exclude_device", required_argument, 0, 'x'}, 327 {"exclude_device", required_argument, 0, 'x'},
328 {"exclude-type", required_argument, 0, 'X'}, 328 {"exclude-type", required_argument, 0, 'X'},
329 {"mountpoint", no_argument, 0, 'M'}, 329 {"mountpoint", no_argument, 0, 'M'},
330 {"errors-only", no_argument, 0, 'e'}, 330 {"errors-only", no_argument, 0, 'e'},
331 {"verbose", no_argument, 0, 'v'}, 331 {"verbose", no_argument, 0, 'v'},
332 {"quiet", no_argument, 0, 'q'}, 332 {"quiet", no_argument, 0, 'q'},
333 {"clear", no_argument, 0, 'C'}, 333 {"clear", no_argument, 0, 'C'},
334 {"version", no_argument, 0, 'V'}, 334 {"version", no_argument, 0, 'V'},
335 {"help", no_argument, 0, 'h'}, 335 {"help", no_argument, 0, 'h'},
336 {0, 0, 0, 0} 336 {0, 0, 0, 0}
337 }; 337 };
338 338
339 if (argc < 2) 339 if (argc < 2)
340 return ERROR; 340 return ERROR;
341 341
342 se = (struct name_list *) malloc (sizeof (struct name_list)); 342 se = (struct name_list *) malloc (sizeof (struct name_list));
343 se->name = strdup ("iso9660"); 343 se->name = strdup ("iso9660");
344 se->name_next = NULL; 344 se->name_next = NULL;
345 se->found = 0; 345 se->found = 0;
346 se->found_len = 0; 346 se->found_len = 0;
347 *fstail = se; 347 *fstail = se;
348 fstail = &se->name_next; 348 fstail = &se->name_next;
349 349
350 for (c = 1; c < argc; c++) 350 for (c = 1; c < argc; c++)
351 if (strcmp ("-to", argv[c]) == 0) 351 if (strcmp ("-to", argv[c]) == 0)
352 strcpy (argv[c], "-t"); 352 strcpy (argv[c], "-t");
353 353
354 while (1) { 354 while (1) {
355 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option); 355 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option);
356 356
357 if (c == -1 || c == EOF) 357 if (c == -1 || c == EOF)
358 break; 358 break;
359 359
360 switch (c) { 360 switch (c) {
361 case 't': /* timeout period */ 361 case 't': /* timeout period */
362 if (is_integer (optarg)) { 362 if (is_integer (optarg)) {
363 timeout_interval = atoi (optarg); 363 timeout_interval = atoi (optarg);
364 break; 364 break;
365 } 365 }
366 else { 366 else {
367 usage2 (_("Timeout interval must be a positive integer"), optarg); 367 usage2 (_("Timeout interval must be a positive integer"), optarg);
368 } 368 }
369 case 'w': /* warning threshold */ 369 case 'w': /* warning threshold */
370 if (is_intnonneg (optarg)) { 370 if (is_intnonneg (optarg)) {
371 w_df = atoi (optarg); 371 w_df = atoi (optarg);
372 break; 372 break;
373 } 373 }
374 else if (strpbrk (optarg, ",:") && 374 else if (strpbrk (optarg, ",:") &&
375 strstr (optarg, "%") && 375 strstr (optarg, "%") &&
376 sscanf (optarg, "%lu%*[:,]%lf%%", &l, &w_dfp) == 2) { 376 sscanf (optarg, "%lu%*[:,]%lf%%", &l, &w_dfp) == 2) {
377 w_df = (uintmax_t)l; 377 w_df = (uintmax_t)l;
378 break; 378 break;
379 } 379 }
380 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) { 380 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) {
381 break; 381 break;
382 } 382 }
383 else { 383 else {
384 usage4 (_("Warning threshold must be integer or percentage!")); 384 usage4 (_("Warning threshold must be integer or percentage!"));
385 } 385 }
386 case 'c': /* critical threshold */ 386 case 'c': /* critical threshold */
387 if (is_intnonneg (optarg)) { 387 if (is_intnonneg (optarg)) {
388 c_df = atoi (optarg); 388 c_df = atoi (optarg);
389 break; 389 break;
390 } 390 }
391 else if (strpbrk (optarg, ",:") && 391 else if (strpbrk (optarg, ",:") &&
392 strstr (optarg, "%") && 392 strstr (optarg, "%") &&
393 sscanf (optarg, "%lu%*[,:]%lf%%", &l, &c_dfp) == 2) { 393 sscanf (optarg, "%lu%*[,:]%lf%%", &l, &c_dfp) == 2) {
394 c_df = (uintmax_t)l; 394 c_df = (uintmax_t)l;
395 break; 395 break;
396 } 396 }
397 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) { 397 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) {
398 break; 398 break;
399 } 399 }
400 else { 400 else {
401 usage4 (_("Critical threshold must be integer or percentage!")); 401 usage4 (_("Critical threshold must be integer or percentage!"));
402 } 402 }
403 403
404 404
405 case 'W': /* warning inode threshold */ 405 case 'W': /* warning inode threshold */
@@ -407,71 +407,71 @@ process_arguments (int argc, char **argv)
407 break; 407 break;
408 } 408 }
409 else { 409 else {
410 usage (_("Warning inode threshold must be percentage!\n")); 410 usage (_("Warning inode threshold must be percentage!\n"));
411 } 411 }
412 case 'K': /* kritical inode threshold */ 412 case 'K': /* kritical inode threshold */
413 if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) { 413 if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) {
414 break; 414 break;
415 } 415 }
416 else { 416 else {
417 usage (_("Critical inode threshold must be percentage!\n")); 417 usage (_("Critical inode threshold must be percentage!\n"));
418 } 418 }
419 case 'u': 419 case 'u':
420 if (units) 420 if (units)
421 free(units); 421 free(units);
422 if (! strcmp (optarg, "bytes")) { 422 if (! strcmp (optarg, "bytes")) {
423 mult = (uintmax_t)1; 423 mult = (uintmax_t)1;
424 units = strdup ("B"); 424 units = strdup ("B");
425 } else if (! strcmp (optarg, "kB")) { 425 } else if (! strcmp (optarg, "kB")) {
426 mult = (uintmax_t)1024; 426 mult = (uintmax_t)1024;
427 units = strdup ("kB"); 427 units = strdup ("kB");
428 } else if (! strcmp (optarg, "MB")) { 428 } else if (! strcmp (optarg, "MB")) {
429 mult = (uintmax_t)1024 * 1024; 429 mult = (uintmax_t)1024 * 1024;
430 units = strdup ("MB"); 430 units = strdup ("MB");
431 } else if (! strcmp (optarg, "GB")) { 431 } else if (! strcmp (optarg, "GB")) {
432 mult = (uintmax_t)1024 * 1024 * 1024; 432 mult = (uintmax_t)1024 * 1024 * 1024;
433 units = strdup ("GB"); 433 units = strdup ("GB");
434 } else if (! strcmp (optarg, "TB")) { 434 } else if (! strcmp (optarg, "TB")) {
435 mult = (uintmax_t)1024 * 1024 * 1024 * 1024; 435 mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
436 units = strdup ("TB"); 436 units = strdup ("TB");
437 } else { 437 } else {
438 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); 438 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
439 } 439 }
440 if (units == NULL) 440 if (units == NULL)
441 die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units"); 441 die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units");
442 break; 442 break;
443 case 'k': /* display mountpoint */ 443 case 'k': /* display mountpoint */
444 mult = 1024; 444 mult = 1024;
445 if (units) 445 if (units)
446 free(units); 446 free(units);
447 units = strdup ("kB"); 447 units = strdup ("kB");
448 break; 448 break;
449 case 'm': /* display mountpoint */ 449 case 'm': /* display mountpoint */
450 mult = 1024 * 1024; 450 mult = 1024 * 1024;
451 if (units) 451 if (units)
452 free(units); 452 free(units);
453 units = strdup ("MB"); 453 units = strdup ("MB");
454 break; 454 break;
455 case 'l': 455 case 'l':
456 show_local_fs = 1; 456 show_local_fs = 1;
457 break; 457 break;
458 case 'p': /* select path */ 458 case 'p': /* select path */
459 se = (struct name_list *) malloc (sizeof (struct name_list)); 459 se = (struct name_list *) malloc (sizeof (struct name_list));
460 se->name = optarg; 460 se->name = optarg;
461 se->name_next = NULL; 461 se->name_next = NULL;
462 se->w_df = w_df; 462 se->w_df = w_df;
463 se->c_df = c_df; 463 se->c_df = c_df;
464 se->w_dfp = w_dfp; 464 se->w_dfp = w_dfp;
465 se->c_dfp = c_dfp; 465 se->c_dfp = c_dfp;
466 se->found = 0; 466 se->found = 0;
467 se->found_len = 0; 467 se->found_len = 0;
468 *pathtail = se; 468 *pathtail = se;
469 pathtail = &se->name_next; 469 pathtail = &se->name_next;
470 break; 470 break;
471 case 'x': /* exclude path or partition */ 471 case 'x': /* exclude path or partition */
472 se = (struct name_list *) malloc (sizeof (struct name_list)); 472 se = (struct name_list *) malloc (sizeof (struct name_list));
473 se->name = optarg; 473 se->name = optarg;
474 se->name_next = NULL; 474 se->name_next = NULL;
475 475
476 /* If you don't clear the w_fd etc values here, they 476 /* If you don't clear the w_fd etc values here, they
477 * get processed when you walk the list and assigned 477 * get processed when you walk the list and assigned
@@ -481,15 +481,15 @@ process_arguments (int argc, char **argv)
481 se->c_df = 0; 481 se->c_df = 0;
482 se->w_dfp = 0; 482 se->w_dfp = 0;
483 se->c_dfp = 0; 483 se->c_dfp = 0;
484 se->found = 0; 484 se->found = 0;
485 se->found_len = 0; 485 se->found_len = 0;
486 *dptail = se; 486 *dptail = se;
487 dptail = &se->name_next; 487 dptail = &se->name_next;
488 break; 488 break;
489 case 'X': /* exclude file system type */ 489 case 'X': /* exclude file system type */
490 se = (struct name_list *) malloc (sizeof (struct name_list)); 490 se = (struct name_list *) malloc (sizeof (struct name_list));
491 se->name = optarg; 491 se->name = optarg;
492 se->name_next = NULL; 492 se->name_next = NULL;
493 /* If you don't clear the w_fd etc values here, they 493 /* If you don't clear the w_fd etc values here, they
494 * get processed when you walk the list and assigned 494 * get processed when you walk the list and assigned
495 * to the global w_df! 495 * to the global w_df!
@@ -498,78 +498,78 @@ process_arguments (int argc, char **argv)
498 se->c_df = 0; 498 se->c_df = 0;
499 se->w_dfp = 0; 499 se->w_dfp = 0;
500 se->c_dfp = 0; 500 se->c_dfp = 0;
501 se->found = 0; 501 se->found = 0;
502 se->found_len = 0; 502 se->found_len = 0;
503 *fstail = se; 503 *fstail = se;
504 fstail = &se->name_next; 504 fstail = &se->name_next;
505 break; 505 break;
506 case 'v': /* verbose */ 506 case 'v': /* verbose */
507 verbose++; 507 verbose++;
508 break; 508 break;
509 case 'q': /* verbose */ 509 case 'q': /* verbose */
510 verbose--; 510 verbose--;
511 break; 511 break;
512 case 'e': 512 case 'e':
513 erronly = TRUE; 513 erronly = TRUE;
514 break; 514 break;
515 case 'M': /* display mountpoint */ 515 case 'M': /* display mountpoint */
516 display_mntp = TRUE; 516 display_mntp = TRUE;
517 break; 517 break;
518 case 'C': 518 case 'C':
519 w_df = 0; 519 w_df = 0;
520 c_df = 0; 520 c_df = 0;
521 w_dfp = -1.0; 521 w_dfp = -1.0;
522 c_dfp = -1.0; 522 c_dfp = -1.0;
523 break; 523 break;
524 case 'V': /* version */ 524 case 'V': /* version */
525 print_revision (progname, revision); 525 print_revision (progname, revision);
526 exit (STATE_OK); 526 exit (STATE_OK);
527 case 'h': /* help */ 527 case 'h': /* help */
528 print_help (); 528 print_help ();
529 exit (STATE_OK); 529 exit (STATE_OK);
530 case '?': /* help */ 530 case '?': /* help */
531 usage2 (_("Unknown argument"), optarg); 531 usage (_("Unknown argument"));
532 } 532 }
533 } 533 }
534 534
535 /* Support for "check_disk warn crit [fs]" with thresholds at used level */ 535 /* Support for "check_disk warn crit [fs]" with thresholds at used level */
536 c = optind; 536 c = optind;
537 if (w_dfp < 0 && argc > c && is_intnonneg (argv[c])) 537 if (w_dfp < 0 && argc > c && is_intnonneg (argv[c]))
538 w_dfp = (100.0 - atof (argv[c++])); 538 w_dfp = (100.0 - atof (argv[c++]));
539 539
540 if (c_dfp < 0 && argc > c && is_intnonneg (argv[c])) 540 if (c_dfp < 0 && argc > c && is_intnonneg (argv[c]))
541 c_dfp = (100.0 - atof (argv[c++])); 541 c_dfp = (100.0 - atof (argv[c++]));
542 542
543 if (argc > c && path == NULL) { 543 if (argc > c && path == NULL) {
544 se = (struct name_list *) malloc (sizeof (struct name_list)); 544 se = (struct name_list *) malloc (sizeof (struct name_list));
545 se->name = strdup (argv[c++]); 545 se->name = strdup (argv[c++]);
546 se->name_next = NULL; 546 se->name_next = NULL;
547 se->w_df = w_df; 547 se->w_df = w_df;
548 se->c_df = c_df; 548 se->c_df = c_df;
549 se->w_dfp = w_dfp; 549 se->w_dfp = w_dfp;
550 se->c_dfp = c_dfp; 550 se->c_dfp = c_dfp;
551 se->found =0; 551 se->found =0;
552 se->found_len = 0; 552 se->found_len = 0;
553 *pathtail = se; 553 *pathtail = se;
554 } 554 }
555 555
556 if (path_select_list) { 556 if (path_select_list) {
557 temp_list = path_select_list; 557 temp_list = path_select_list;
558 while (temp_list) { 558 while (temp_list) {
559 if (validate_arguments (temp_list->w_df, 559 if (validate_arguments (temp_list->w_df,
560 temp_list->c_df, 560 temp_list->c_df,
561 temp_list->w_dfp, 561 temp_list->w_dfp,
562 temp_list->c_dfp, 562 temp_list->c_dfp,
563 temp_list->w_idfp, 563 temp_list->w_idfp,
564 temp_list->c_idfp, 564 temp_list->c_idfp,
565 temp_list->name) == ERROR) 565 temp_list->name) == ERROR)
566 result = ERROR; 566 result = ERROR;
567 temp_list = temp_list->name_next; 567 temp_list = temp_list->name_next;
568 } 568 }
569 return result; 569 return result;
570 } else { 570 } else {
571 return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL); 571 return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL);
572 } 572 }
573} 573}
574 574
575 575
@@ -577,12 +577,12 @@ process_arguments (int argc, char **argv)
577void 577void
578print_path (const char *mypath) 578print_path (const char *mypath)
579{ 579{
580 if (mypath == NULL) 580 if (mypath == NULL)
581 printf ("\n"); 581 printf ("\n");
582 else 582 else
583 printf (_(" for %s\n"), mypath); 583 printf (_(" for %s\n"), mypath);
584 584
585 return; 585 return;
586} 586}
587 587
588 588
@@ -590,40 +590,40 @@ print_path (const char *mypath)
590int 590int
591validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath) 591validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath)
592{ 592{
593 if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) { 593 if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) {
594 printf (_("INPUT ERROR: No thresholds specified")); 594 printf (_("INPUT ERROR: No thresholds specified"));
595 print_path (mypath); 595 print_path (mypath);
596 return ERROR; 596 return ERROR;
597 } 597 }
598 else if ((wp >= 0.0 || cp >= 0.0) && 598 else if ((wp >= 0.0 || cp >= 0.0) &&
599 (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) { 599 (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) {
600 printf (_("\ 600 printf (_("\
601INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"), 601INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"),
602 cp, wp); 602 cp, wp);
603 print_path (mypath); 603 print_path (mypath);
604 return ERROR; 604 return ERROR;
605 } 605 }
606 else if ((iwp >= 0.0 || icp >= 0.0) && 606 else if ((iwp >= 0.0 || icp >= 0.0) &&
607 (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) { 607 (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) {
608 printf (_("\ 608 printf (_("\
609INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"), 609INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"),
610 icp, iwp); 610 icp, iwp);
611 print_path (mypath); 611 print_path (mypath);
612 return ERROR; 612 return ERROR;
613 } 613 }
614 else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) { 614 else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) {
615 printf (_("\ 615 printf (_("\
616INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"), 616INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"),
617 (unsigned long)c, (unsigned long)w); 617 (unsigned long)c, (unsigned long)w);
618 print_path (mypath); 618 print_path (mypath);
619 return ERROR; 619 return ERROR;
620 } 620 }
621 621
622 if (units == NULL) { 622 if (units == NULL) {
623 units = strdup ("MB"); 623 units = strdup ("MB");
624 mult = (uintmax_t)1024 * 1024; 624 mult = (uintmax_t)1024 * 1024;
625 } 625 }
626 return OK; 626 return OK;
627} 627}
628 628
629 629
@@ -647,8 +647,8 @@ check_disk (double usp, uintmax_t free_disk, double uisp)
647 else if (w_df > 0 && free_disk <= w_df) 647 else if (w_df > 0 && free_disk <= w_df)
648 result = STATE_WARNING; 648 result = STATE_WARNING;
649 else if (usp >= 0.0) 649 else if (usp >= 0.0)
650 result = STATE_OK; 650 result = STATE_OK;
651 return result; 651 return result;
652} 652}
653 653
654 654
@@ -656,26 +656,26 @@ check_disk (double usp, uintmax_t free_disk, double uisp)
656int 656int
657walk_name_list (struct name_list *list, const char *name) 657walk_name_list (struct name_list *list, const char *name)
658{ 658{
659 int name_len; 659 int name_len;
660 name_len = strlen(name); 660 name_len = strlen(name);
661 while (list) { 661 while (list) {
662 /* if the paths match up to the length of the mount path, 662 /* if the paths match up to the length of the mount path,
663 * AND if the mount path name is longer than the longest 663 * AND if the mount path name is longer than the longest
664 * found match, we have a new winner */ 664 * found match, we have a new winner */
665 if (name_len >= list->found_len && 665 if (name_len >= list->found_len &&
666 ! strncmp(list->name, name, name_len)) { 666 ! strncmp(list->name, name, name_len)) {
667 list->found = 1; 667 list->found = 1;
668 list->found_len = name_len; 668 list->found_len = name_len;
669 /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */ 669 /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */
670 if (list->w_df) w_df = list->w_df; 670 if (list->w_df) w_df = list->w_df;
671 if (list->c_df) c_df = list->c_df; 671 if (list->c_df) c_df = list->c_df;
672 if (list->w_dfp>=0.0) w_dfp = list->w_dfp; 672 if (list->w_dfp>=0.0) w_dfp = list->w_dfp;
673 if (list->c_dfp>=0.0) c_dfp = list->c_dfp; 673 if (list->c_dfp>=0.0) c_dfp = list->c_dfp;
674 return TRUE; 674 return TRUE;
675 } 675 }
676 list = list->name_next; 676 list = list->name_next;
677 } 677 }
678 return FALSE; 678 return FALSE;
679} 679}
680 680
681 681
@@ -683,68 +683,163 @@ walk_name_list (struct name_list *list, const char *name)
683void 683void
684print_help (void) 684print_help (void)
685{ 685{
686 print_revision (progname, revision); 686 print_revision (progname, revision);
687 687
688 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); 688 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
689 printf (COPYRIGHT, copyright, email); 689 printf (COPYRIGHT, copyright, email);
690 690
691 printf (_("\ 691 printf (_("This plugin checks the amount of used disk space on a mounted file system"));
692This plugin checks the amount of used disk space on a mounted file system\n\ 692 printf (_("and generates an alert if free space is less than one of the threshold values"));
693and generates an alert if free space is less than one of the threshold values.\n\n")); 693
694 694 printf ("\n\n");
695 print_usage (); 695
696 696 print_usage ();
697 printf (_(UT_HELP_VRSN)); 697
698 698 printf (_(UT_HELP_VRSN));
699 printf (_("\ 699
700 -w, --warning=INTEGER\n\ 700 printf (" -w, --warning=INTEGER");
701 Exit with WARNING status if less than INTEGER --units of disk are free\n\ 701
702 -w, --warning=PERCENT%%\n\ 702 printf ("\n");
703 Exit with WARNING status if less than PERCENT of disk space is free\n\ 703
704 -W, --iwarning=PERCENT%%\n\ 704 printf (_("exit with WARNING status if less than INTEGER units of disk are free"));
705 Exit with WARNING status if less than PERCENT of inode space is free\n\ 705
706 -K, --icritical=PERCENT%%\n\ 706 printf (" -w, --warning=PERCENT%%");
707 Exit with CRITICAL status if less than PERCENT of inode space is free\n\ 707
708 -c, --critical=INTEGER\n\ 708 printf ("\n");
709 Exit with CRITICAL status if less than INTEGER --units of disk are free\n\ 709
710 -c, --critical=PERCENT%%\n\ 710 printf (_("exit with WARNING status if less than PERCENT of disk space is free"));
711 Exit with CRITCAL status if less than PERCENT of disk space is free\n\ 711
712 -C, --clear\n\ 712 printf ("\n");
713 Clear thresholds\n")); 713
714 714 printf (" -W, --iwarning=PERCENT%%");
715 printf (_("\ 715
716 -u, --units=STRING\n\ 716 printf ("\n");
717 Choose bytes, kB, MB, GB, TB (default: MB)\n\ 717
718 -k, --kilobytes\n\ 718 printf (_("exit with WARNING status if less than PERCENT of inode space is free"));
719 Same as '--units kB'\n\ 719
720 -m, --megabytes\n\ 720 printf ("\n");
721 Same as '--units MB'\n")); 721
722 722 printf (" -K, --icritical=PERCENT%%");
723 printf (_("\ 723
724 -l, --local\n\ 724 printf ("\n");
725 Only check local filesystems\n\ 725
726 -p, --path=PATH, --partition=PARTITION\n\ 726 printf (_("exit with CRITICAL status if less than PERCENT of inode space is free"));
727 Path or partition (may be repeated)\n\ 727
728 -x, --exclude_device=PATH <STRING>\n\ 728 printf ("\n");
729 Ignore device (only works if -p unspecified)\n\ 729
730 -X, --exclude-type=TYPE <STRING>\n\ 730 printf (" -c, --critical=INTEGER");
731 Ignore all filesystems of indicated type (may be repeated)\n\ 731
732 -M, --mountpoint\n\ 732 printf ("\n");
733 Display the mountpoint instead of the partition\n\ 733
734 -e, --errors-only\n\ 734 printf (_("exit with CRITICAL status if less than INTEGER --units of disk are free"));
735 Display only devices/mountpoints with errors\n")); 735
736 736 printf ("\n");
737 printf (_(UT_WARN_CRIT)); 737
738 738 printf (" -c, --critical=PERCENT%%");
739 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 739
740 740 printf ("\n");
741 printf (_(UT_VERBOSE)); 741
742 742 printf (_("exit with CRITCAL status if less than PERCENT of disk space is free"));
743 printf ("%s", _("Examples:\n\ 743
744 check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\ 744 printf ("\n");
745 Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n")); 745
746 746 printf (" -C, --clear");
747 printf (_(UT_SUPPORT)); 747
748 printf ("\n");
749
750 printf (_("clear thresholds"));
751
752 printf ("\n");
753
754 printf (" -u, --units=STRING");
755
756 printf ("\n");
757
758 printf (_("choose bytes, kB, MB, GB, TB (default: MB)"));
759
760 printf ("\n");
761
762 printf (" -k, --kilobytes");
763
764 printf ("\n");
765
766 printf (_("same as '--units kB'"));
767
768 printf ("\n");
769
770 printf (" -m, --megabytes");
771
772 printf ("\n");
773
774 printf (_("same as '--units MB'\n"));
775
776 printf (" -l, --local");
777
778 printf ("\n");
779
780 printf (_("only check local filesystems"));
781
782 printf ("\n");
783
784 printf (" -p, --path=PATH, --partition=PARTITION");
785
786 printf ("\n");
787
788 printf (_("path or partition (may be repeated)"));
789
790 printf ("\n");
791
792 printf (" -x, --exclude_device=PATH <STRING>");
793
794 printf ("\n");
795
796 printf (_("ignore device (only works if -p unspecified)"));
797
798 printf ("\n");
799
800 printf (" -X, --exclude-type=TYPE <STRING>");
801
802 printf ("\n");
803
804 printf (_("ignore all filesystems of indicated type (may be repeated)"));
805
806 printf ("\n");
807
808 printf ("-m, --mountpoint");
809
810 printf ("\n");
811
812 printf (_("display the mountpoint instead of the partition"));
813
814 printf ("\n");
815
816 printf ("-e, --errors-only");
817
818 printf ("\n");
819
820 printf (_("display only devices/mountpoints with errors"));
821
822 printf ("\n");
823
824 printf (_(UT_WARN_CRIT));
825
826 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
827
828 printf (_(UT_VERBOSE));
829
830 printf (_("examples:"));
831
832 printf ("\n");
833
834 printf ("check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /");
835
836 printf ("\n");
837
838 printf (_("checks /tmp and /var at 10% and 5% and / at 100MB, 50MB"));
839
840 printf ("\n");
841
842 printf (_(UT_SUPPORT));
748} 843}
749 844
750 845
@@ -752,7 +847,7 @@ and generates an alert if free space is less than one of the threshold values.\n
752void 847void
753print_usage (void) 848print_usage (void)
754{ 849{
755 printf ("\ 850 printf (_("Usage:"));
756Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e] [-W limit] [-K limit]\n\ 851 printf (" %s -w limit -c limit [-p path | -x device] [-t timeout]", progname);
757 [-v] [-q]\n", progname); 852 printf ("[-m] [-e] [-W limit] [-K limit] [-v] [-q]\n");
758} 853}