diff options
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r-- | plugins/check_disk.c | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 97465113..3e9fa46e 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -138,6 +138,7 @@ enum | |||
138 | int process_arguments (int, char **); | 138 | int process_arguments (int, char **); |
139 | int validate_arguments (void); | 139 | int validate_arguments (void); |
140 | int check_disk (int usp, int free_disk); | 140 | int check_disk (int usp, int free_disk); |
141 | int walk_name_list (struct name_list *list, const char *name); | ||
141 | void print_help (void); | 142 | void print_help (void); |
142 | void print_usage (void); | 143 | void print_usage (void); |
143 | 144 | ||
@@ -168,6 +169,7 @@ main (int argc, char **argv) | |||
168 | char file_system[MAX_INPUT_BUFFER]; | 169 | char file_system[MAX_INPUT_BUFFER]; |
169 | char mntp[MAX_INPUT_BUFFER]; | 170 | char mntp[MAX_INPUT_BUFFER]; |
170 | char *output = ""; | 171 | char *output = ""; |
172 | char *details = ""; | ||
171 | 173 | ||
172 | struct mount_entry *me; | 174 | struct mount_entry *me; |
173 | struct fs_usage fsp; | 175 | struct fs_usage fsp; |
@@ -181,12 +183,14 @@ main (int argc, char **argv) | |||
181 | for (me = mount_list; me; me = me->me_next) { | 183 | for (me = mount_list; me; me = me->me_next) { |
182 | 184 | ||
183 | if ((dev_select_list && | 185 | if ((dev_select_list && |
184 | ! strcmp (dev_select_list->name, me->me_devname)) || | 186 | walk_name_list (dev_select_list, me->me_devname)) || |
185 | (path_select_list && | 187 | (path_select_list && |
186 | ! strcmp (path_select_list->name, me->me_mountdir))) | 188 | walk_name_list (path_select_list, me->me_mountdir))) |
187 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); | 189 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); |
188 | else if (dev_select_list || path_select_list) | 190 | else if (dev_select_list || path_select_list) |
189 | continue; | 191 | continue; |
192 | else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) | ||
193 | continue; | ||
190 | else | 194 | else |
191 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); | 195 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); |
192 | 196 | ||
@@ -194,19 +198,36 @@ main (int argc, char **argv) | |||
194 | usp = (fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; | 198 | usp = (fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; |
195 | disk_result = check_disk (usp, fsp.fsu_bavail); | 199 | disk_result = check_disk (usp, fsp.fsu_bavail); |
196 | result = max_state (disk_result, result); | 200 | result = max_state (disk_result, result); |
197 | asprintf (&output, "%s %llu of %llu MB (%2.0f%%) free on %s\n", | 201 | if (disk_result==STATE_OK && erronly && !verbose) |
198 | output, | 202 | continue; |
203 | |||
204 | if (disk_result!=STATE_OK || verbose>=0) | ||
205 | asprintf (&output, "%s [%llu MB (%2.0f%%) free on %s]", | ||
206 | output, | ||
207 | fsp.fsu_bavail*fsp.fsu_blocksize/1024/1024, | ||
208 | (double)fsp.fsu_bavail*100/fsp.fsu_blocks, | ||
209 | (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir); | ||
210 | asprintf (&details, "%s\n%llu of %llu MB (%2.0f%%) free on %s (type %s mounted on %s)", | ||
211 | details, | ||
199 | fsp.fsu_bavail*fsp.fsu_blocksize/1024/1024, | 212 | fsp.fsu_bavail*fsp.fsu_blocksize/1024/1024, |
200 | fsp.fsu_blocks*fsp.fsu_blocksize/1024/1024, | 213 | fsp.fsu_blocks*fsp.fsu_blocksize/1024/1024, |
201 | (double)fsp.fsu_bavail*100/fsp.fsu_blocks, | 214 | (double)fsp.fsu_bavail*100/fsp.fsu_blocks, |
202 | display_mntp ? me->me_devname : me->me_mountdir); | 215 | me->me_devname, |
216 | me->me_type, | ||
217 | me->me_mountdir); | ||
203 | } | 218 | } |
204 | 219 | ||
205 | } | 220 | } |
206 | 221 | ||
207 | terminate (result, "DISK %s %s\n", state_text (result), output); | 222 | if (verbose > 2) |
223 | asprintf (&output, "%s%s", output, details); | ||
224 | |||
225 | terminate (result, "DISK %s%s\n", state_text (result), output, details); | ||
208 | } | 226 | } |
209 | 227 | ||
228 | |||
229 | |||
230 | |||
210 | /* process command-line arguments */ | 231 | /* process command-line arguments */ |
211 | int | 232 | int |
212 | process_arguments (int argc, char **argv) | 233 | process_arguments (int argc, char **argv) |
@@ -215,6 +236,7 @@ process_arguments (int argc, char **argv) | |||
215 | struct name_list *se; | 236 | struct name_list *se; |
216 | struct name_list **pathtail = &path_select_list; | 237 | struct name_list **pathtail = &path_select_list; |
217 | struct name_list **devtail = &dev_select_list; | 238 | struct name_list **devtail = &dev_select_list; |
239 | struct name_list **fstail = &fs_exclude_list; | ||
218 | 240 | ||
219 | int option_index = 0; | 241 | int option_index = 0; |
220 | static struct option long_options[] = { | 242 | static struct option long_options[] = { |
@@ -243,7 +265,7 @@ process_arguments (int argc, char **argv) | |||
243 | strcpy (argv[c], "-t"); | 265 | strcpy (argv[c], "-t"); |
244 | 266 | ||
245 | while (1) { | 267 | while (1) { |
246 | c = getopt_long (argc, argv, "+?Vqhvet:c:w:p:d:x:m", long_options, &option_index); | 268 | c = getopt_long (argc, argv, "+?Vqhvet:c:w:p:d:x:X:m", long_options, &option_index); |
247 | 269 | ||
248 | if (c == -1 || c == EOF) | 270 | if (c == -1 || c == EOF) |
249 | break; | 271 | break; |
@@ -292,15 +314,24 @@ process_arguments (int argc, char **argv) | |||
292 | case 'p': /* path or partition */ | 314 | case 'p': /* path or partition */ |
293 | se = (struct name_list *) malloc (sizeof (struct name_list)); | 315 | se = (struct name_list *) malloc (sizeof (struct name_list)); |
294 | se->name = strdup (optarg); | 316 | se->name = strdup (optarg); |
317 | se->name_next = NULL; | ||
295 | *pathtail = se; | 318 | *pathtail = se; |
296 | pathtail = &se->name_next; | 319 | pathtail = &se->name_next; |
297 | break; | 320 | break; |
298 | case 'd': /* path or partition */ | 321 | case 'd': /* path or partition */ |
299 | se = (struct name_list *) malloc (sizeof (struct name_list)); | 322 | se = (struct name_list *) malloc (sizeof (struct name_list)); |
300 | se->name = strdup (optarg); | 323 | se->name = strdup (optarg); |
324 | se->name_next = NULL; | ||
301 | *devtail = se; | 325 | *devtail = se; |
302 | devtail = &se->name_next; | 326 | devtail = &se->name_next; |
303 | break; | 327 | break; |
328 | case 'X': /* path or partition */ | ||
329 | se = (struct name_list *) malloc (sizeof (struct name_list)); | ||
330 | se->name = strdup (optarg); | ||
331 | se->name_next = NULL; | ||
332 | *fstail = se; | ||
333 | fstail = &se->name_next; | ||
334 | break; | ||
304 | case 'v': /* verbose */ | 335 | case 'v': /* verbose */ |
305 | verbose++; | 336 | verbose++; |
306 | break; | 337 | break; |
@@ -341,6 +372,8 @@ process_arguments (int argc, char **argv) | |||
341 | return validate_arguments (); | 372 | return validate_arguments (); |
342 | } | 373 | } |
343 | 374 | ||
375 | |||
376 | |||
344 | int | 377 | int |
345 | validate_arguments () | 378 | validate_arguments () |
346 | { | 379 | { |
@@ -367,8 +400,11 @@ validate_arguments () | |||
367 | } | 400 | } |
368 | } | 401 | } |
369 | 402 | ||
403 | |||
404 | |||
405 | |||
370 | int | 406 | int |
371 | check_disk (usp, free_disk) | 407 | check_disk (int usp, int free_disk) |
372 | { | 408 | { |
373 | int result = STATE_UNKNOWN; | 409 | int result = STATE_UNKNOWN; |
374 | /* check the percent used space against thresholds */ | 410 | /* check the percent used space against thresholds */ |
@@ -385,6 +421,22 @@ check_disk (usp, free_disk) | |||
385 | return result; | 421 | return result; |
386 | } | 422 | } |
387 | 423 | ||
424 | |||
425 | |||
426 | int | ||
427 | walk_name_list (struct name_list *list, const char *name) | ||
428 | { | ||
429 | while (list) { | ||
430 | if (! strcmp(list->name, name)) | ||
431 | return TRUE; | ||
432 | list = list->name_next; | ||
433 | } | ||
434 | return FALSE; | ||
435 | } | ||
436 | |||
437 | |||
438 | |||
439 | |||
388 | void | 440 | void |
389 | print_help (void) | 441 | print_help (void) |
390 | { | 442 | { |