diff options
-rw-r--r-- | plugins/check_disk.c | 121 |
1 files changed, 90 insertions, 31 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 347c4c7..bc2d3dd 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -39,12 +39,22 @@ const char *options = "\ | |||
39 | Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n\ | 39 | Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n\ |
40 | -c, --critical=PERCENT%%\n\ | 40 | -c, --critical=PERCENT%%\n\ |
41 | Exit with CRITCAL status if less than PERCENT of disk space is free\n\ | 41 | Exit with CRITCAL status if less than PERCENT of disk space is free\n\ |
42 | -u, --units=STRING\n\ | ||
43 | Choose bytes, kB, MB, GB, TB (default: MB)\n\ | ||
44 | -k, --kilobytes\n\ | ||
45 | Same as '--units kB'\n\ | ||
46 | -m, --megabytes\n\ | ||
47 | Same as '--units MB'\n\ | ||
48 | -l, --local\n\ | ||
49 | Only check local filesystems\n\ | ||
42 | -p, --path=PATH, --partition=PARTTION\n\ | 50 | -p, --path=PATH, --partition=PARTTION\n\ |
43 | Path or partition (checks all mounted partitions if unspecified)\n\ | 51 | Path or partition (may be repeated)\n\ |
44 | -m, --mountpoint\n\ | 52 | -x, --exclude_device=PATH <STRING>\n\ |
45 | Display the mountpoint instead of the partition\n\ | ||
46 | -x, --exclude_device=PATH\n\ | ||
47 | Ignore device (only works if -p unspecified)\n\ | 53 | Ignore device (only works if -p unspecified)\n\ |
54 | -X, --exclude-type=TYPE <STRING>\n\ | ||
55 | Ignore all filesystems of indicated type (may be repeated)\n\ | ||
56 | -M, --mountpoint\n\ | ||
57 | Display the mountpoint instead of the partition\n\ | ||
48 | -e, --errors-only\n\ | 58 | -e, --errors-only\n\ |
49 | Display only devices/mountpoints with errors\n\ | 59 | Display only devices/mountpoints with errors\n\ |
50 | -v, --verbose\n\ | 60 | -v, --verbose\n\ |
@@ -54,6 +64,9 @@ const char *options = "\ | |||
54 | -V, --version\n\ | 64 | -V, --version\n\ |
55 | Print version information\n"; | 65 | Print version information\n"; |
56 | 66 | ||
67 | const char *notes = "\ | ||
68 | \n"; | ||
69 | |||
57 | #include "common.h" | 70 | #include "common.h" |
58 | #if HAVE_INTTYPES_H | 71 | #if HAVE_INTTYPES_H |
59 | # include <inttypes.h> | 72 | # include <inttypes.h> |
@@ -73,14 +86,10 @@ static int inode_format; | |||
73 | 86 | ||
74 | /* If nonzero, show even filesystems with zero size or | 87 | /* If nonzero, show even filesystems with zero size or |
75 | uninteresting types. */ | 88 | uninteresting types. */ |
76 | static int show_all_fs; | 89 | static int show_all_fs = 1; |
77 | 90 | ||
78 | /* If nonzero, show only local filesystems. */ | 91 | /* If nonzero, show only local filesystems. */ |
79 | static int show_local_fs; | 92 | static int show_local_fs = 0; |
80 | |||
81 | /* If nonzero, output data for each filesystem corresponding to a | ||
82 | command line argument -- even if it's a dummy (automounter) entry. */ | ||
83 | static int show_listed_fs; | ||
84 | 93 | ||
85 | /* If positive, the units to use when printing sizes; | 94 | /* If positive, the units to use when printing sizes; |
86 | if negative, the human-readable base. */ | 95 | if negative, the human-readable base. */ |
@@ -153,6 +162,8 @@ float w_dfp = -1.0; | |||
153 | float c_dfp = -1.0; | 162 | float c_dfp = -1.0; |
154 | char *path = ""; | 163 | char *path = ""; |
155 | char *exclude_device = ""; | 164 | char *exclude_device = ""; |
165 | char *units = "MB"; | ||
166 | unsigned long mult = 1024 * 1024; | ||
156 | int verbose = 0; | 167 | int verbose = 0; |
157 | int erronly = FALSE; | 168 | int erronly = FALSE; |
158 | int display_mntp = FALSE; | 169 | int display_mntp = FALSE; |
@@ -194,6 +205,10 @@ main (int argc, char **argv) | |||
194 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); | 205 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); |
195 | else if (dev_select_list || path_select_list) | 206 | else if (dev_select_list || path_select_list) |
196 | continue; | 207 | continue; |
208 | else if (me->me_remote && show_local_fs) | ||
209 | continue; | ||
210 | else if (me->me_dummy && !show_all_fs) | ||
211 | continue; | ||
197 | else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) | 212 | else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) |
198 | continue; | 213 | continue; |
199 | else if (dp_exclude_list && | 214 | else if (dp_exclude_list && |
@@ -211,15 +226,17 @@ main (int argc, char **argv) | |||
211 | continue; | 226 | continue; |
212 | 227 | ||
213 | if (disk_result!=STATE_OK || verbose>=0) | 228 | if (disk_result!=STATE_OK || verbose>=0) |
214 | asprintf (&output, "%s [%llu MB (%2.0f%%) free on %s]", | 229 | asprintf (&output, "%s [%llu %s (%2.0f%%) free on %s]", |
215 | output, | 230 | output, |
216 | fsp.fsu_bavail*fsp.fsu_blocksize/1024/1024, | 231 | fsp.fsu_bavail*fsp.fsu_blocksize/mult, |
232 | units, | ||
217 | (double)fsp.fsu_bavail*100/fsp.fsu_blocks, | 233 | (double)fsp.fsu_bavail*100/fsp.fsu_blocks, |
218 | (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir); | 234 | (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir); |
219 | asprintf (&details, "%s\n%llu of %llu MB (%2.0f%%) free on %s (type %s mounted on %s)", | 235 | asprintf (&details, "%s\n%llu of %llu %s (%2.0f%%) free on %s (type %s mounted on %s)", |
220 | details, | 236 | details, |
221 | fsp.fsu_bavail*fsp.fsu_blocksize/1024/1024, | 237 | fsp.fsu_bavail*fsp.fsu_blocksize/mult, |
222 | fsp.fsu_blocks*fsp.fsu_blocksize/1024/1024, | 238 | units, |
239 | fsp.fsu_blocks*fsp.fsu_blocksize/mult, | ||
223 | (double)fsp.fsu_bavail*100/fsp.fsu_blocks, | 240 | (double)fsp.fsu_bavail*100/fsp.fsu_blocks, |
224 | me->me_devname, | 241 | me->me_devname, |
225 | me->me_type, | 242 | me->me_type, |
@@ -250,37 +267,55 @@ process_arguments (int argc, char **argv) | |||
250 | 267 | ||
251 | int option_index = 0; | 268 | int option_index = 0; |
252 | static struct option long_options[] = { | 269 | static struct option long_options[] = { |
270 | {"timeout", required_argument, 0, 't'}, | ||
253 | {"warning", required_argument, 0, 'w'}, | 271 | {"warning", required_argument, 0, 'w'}, |
254 | {"critical", required_argument, 0, 'c'}, | 272 | {"critical", required_argument, 0, 'c'}, |
255 | {"timeout", required_argument, 0, 't'}, | 273 | {"local", required_argument, 0, 'l'}, |
274 | {"kilobytes", required_argument, 0, 'k'}, | ||
275 | {"megabytes", required_argument, 0, 'm'}, | ||
276 | {"units", required_argument, 0, 'u'}, | ||
256 | {"path", required_argument, 0, 'p'}, | 277 | {"path", required_argument, 0, 'p'}, |
257 | {"partition", required_argument, 0, 'p'}, | 278 | {"partition", required_argument, 0, 'p'}, |
279 | {"device", required_argument, 0, 'd'}, | ||
280 | {"exclude_device", required_argument, 0, 'x'}, | ||
281 | {"exclude-type", required_argument, 0, 'X'}, | ||
282 | {"mountpoint", no_argument, 0, 'M'}, | ||
283 | {"errors-only", no_argument, 0, 'e'}, | ||
258 | {"verbose", no_argument, 0, 'v'}, | 284 | {"verbose", no_argument, 0, 'v'}, |
285 | {"quiet", no_argument, 0, 'q'}, | ||
259 | {"version", no_argument, 0, 'V'}, | 286 | {"version", no_argument, 0, 'V'}, |
260 | {"errors-only", no_argument, 0, 'e'}, | ||
261 | {"help", no_argument, 0, 'h'}, | 287 | {"help", no_argument, 0, 'h'}, |
262 | {"mountpoint", no_argument, 0, 'm'}, | ||
263 | {"device", no_argument, 0, 'd'}, | ||
264 | {"exclude_device", required_argument, 0, 'x'}, | ||
265 | {"quiet", no_argument, 0, 'q'}, | ||
266 | |||
267 | {0, 0, 0, 0} | 288 | {0, 0, 0, 0} |
268 | }; | 289 | }; |
269 | 290 | ||
270 | if (argc < 2) | 291 | if (argc < 2) |
271 | return ERROR; | 292 | return ERROR; |
272 | 293 | ||
294 | se = (struct name_list *) malloc (sizeof (struct name_list)); | ||
295 | se->name = strdup ("iso9660"); | ||
296 | se->name_next = NULL; | ||
297 | *fstail = se; | ||
298 | fstail = &se->name_next; | ||
299 | |||
273 | for (c = 1; c < argc; c++) | 300 | for (c = 1; c < argc; c++) |
274 | if (strcmp ("-to", argv[c]) == 0) | 301 | if (strcmp ("-to", argv[c]) == 0) |
275 | strcpy (argv[c], "-t"); | 302 | strcpy (argv[c], "-t"); |
276 | 303 | ||
277 | while (1) { | 304 | while (1) { |
278 | c = getopt_long (argc, argv, "+?Vqhvet:c:w:p:d:x:X:m", long_options, &option_index); | 305 | c = getopt_long (argc, argv, "+?Vqhvet:c:w:u:p:d:x:X:mklM", long_options, &option_index); |
279 | 306 | ||
280 | if (c == -1 || c == EOF) | 307 | if (c == -1 || c == EOF) |
281 | break; | 308 | break; |
282 | 309 | ||
283 | switch (c) { | 310 | switch (c) { |
311 | case 't': /* timeout period */ | ||
312 | if (is_integer (optarg)) { | ||
313 | timeout_interval = atoi (optarg); | ||
314 | break; | ||
315 | } | ||
316 | else { | ||
317 | usage ("Timeout Interval must be an integer!\n"); | ||
318 | } | ||
284 | case 'w': /* warning time threshold */ | 319 | case 'w': /* warning time threshold */ |
285 | if (is_intnonneg (optarg)) { | 320 | if (is_intnonneg (optarg)) { |
286 | w_df = atoi (optarg); | 321 | w_df = atoi (optarg); |
@@ -313,14 +348,37 @@ process_arguments (int argc, char **argv) | |||
313 | else { | 348 | else { |
314 | usage ("Critical threshold must be integer or percentage!\n"); | 349 | usage ("Critical threshold must be integer or percentage!\n"); |
315 | } | 350 | } |
316 | case 't': /* timeout period */ | 351 | case 'u': |
317 | if (is_integer (optarg)) { | 352 | if (! strcmp (optarg, "bytes")) { |
318 | timeout_interval = atoi (optarg); | 353 | mult = 1; |
319 | break; | 354 | units = "B"; |
320 | } | 355 | } else if (! strcmp (optarg, "kB")) { |
321 | else { | 356 | mult = 1024; |
322 | usage ("Timeout Interval must be an integer!\n"); | 357 | units = "kB"; |
358 | } else if (! strcmp (optarg, "MB")) { | ||
359 | mult = 1024 * 1024; | ||
360 | units = "MB"; | ||
361 | } else if (! strcmp (optarg, "GB")) { | ||
362 | mult = 1024 * 1024 * 1024; | ||
363 | units = "GB"; | ||
364 | } else if (! strcmp (optarg, "TB")) { | ||
365 | mult = (unsigned long)1024 * 1024 * 1024 * 1024; | ||
366 | units = "TB"; | ||
367 | } else { | ||
368 | terminate (STATE_UNKNOWN, "unit type %s not known", optarg); | ||
323 | } | 369 | } |
370 | break; | ||
371 | case 'k': /* display mountpoint */ | ||
372 | mult = 1024; | ||
373 | units = "kB"; | ||
374 | break; | ||
375 | case 'm': /* display mountpoint */ | ||
376 | mult = 1024 * 1024; | ||
377 | units = "MB"; | ||
378 | break; | ||
379 | case 'l': | ||
380 | show_local_fs = 1; | ||
381 | break; | ||
324 | case 'p': /* selec path */ | 382 | case 'p': /* selec path */ |
325 | se = (struct name_list *) malloc (sizeof (struct name_list)); | 383 | se = (struct name_list *) malloc (sizeof (struct name_list)); |
326 | se->name = strdup (optarg); | 384 | se->name = strdup (optarg); |
@@ -359,7 +417,7 @@ process_arguments (int argc, char **argv) | |||
359 | case 'e': | 417 | case 'e': |
360 | erronly = TRUE; | 418 | erronly = TRUE; |
361 | break; | 419 | break; |
362 | case 'm': /* display mountpoint */ | 420 | case 'M': /* display mountpoint */ |
363 | display_mntp = TRUE; | 421 | display_mntp = TRUE; |
364 | break; | 422 | break; |
365 | case 'V': /* version */ | 423 | case 'V': /* version */ |
@@ -461,6 +519,7 @@ print_help (void) | |||
461 | print_usage (); | 519 | print_usage (); |
462 | printf ("\nOptions:\n"); | 520 | printf ("\nOptions:\n"); |
463 | printf (options); | 521 | printf (options); |
522 | printf (notes); | ||
464 | support (); | 523 | support (); |
465 | } | 524 | } |
466 | 525 | ||