diff options
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r-- | plugins/check_disk.c | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 925dfa82..eb573f5f 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -51,6 +51,9 @@ const char *email = "devel@monitoring-plugins.org"; | |||
51 | # include <limits.h> | 51 | # include <limits.h> |
52 | #endif | 52 | #endif |
53 | #include "regex.h" | 53 | #include "regex.h" |
54 | #if HAVE_PTHREAD_H | ||
55 | # include <pthread.h> | ||
56 | #endif | ||
54 | 57 | ||
55 | #ifdef __CYGWIN__ | 58 | #ifdef __CYGWIN__ |
56 | # include <windows.h> | 59 | # include <windows.h> |
@@ -130,6 +133,7 @@ void print_help (void); | |||
130 | void print_usage (void); | 133 | void print_usage (void); |
131 | double calculate_percent(uintmax_t, uintmax_t); | 134 | double calculate_percent(uintmax_t, uintmax_t); |
132 | void stat_path (struct parameter_list *p); | 135 | void stat_path (struct parameter_list *p); |
136 | void *do_stat_path (void *p); | ||
133 | void get_stats (struct parameter_list *p, struct fs_usage *fsp); | 137 | void get_stats (struct parameter_list *p, struct fs_usage *fsp); |
134 | void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); | 138 | void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); |
135 | 139 | ||
@@ -171,6 +175,7 @@ main (int argc, char **argv) | |||
171 | char *details; | 175 | char *details; |
172 | char *perf; | 176 | char *perf; |
173 | char *preamble; | 177 | char *preamble; |
178 | char *flag_header; | ||
174 | double inode_space_pct; | 179 | double inode_space_pct; |
175 | double warning_high_tide; | 180 | double warning_high_tide; |
176 | double critical_high_tide; | 181 | double critical_high_tide; |
@@ -353,18 +358,23 @@ main (int argc, char **argv) | |||
353 | if (disk_result==STATE_OK && erronly && !verbose) | 358 | if (disk_result==STATE_OK && erronly && !verbose) |
354 | continue; | 359 | continue; |
355 | 360 | ||
356 | xasprintf (&output, "%s %s %.0f %s (%.0f%%", | 361 | if(disk_result && verbose >= 1) { |
357 | output, | 362 | xasprintf(&flag_header, " %s [", state_text (disk_result)); |
363 | } else { | ||
364 | xasprintf(&flag_header, ""); | ||
365 | } | ||
366 | xasprintf (&output, "%s%s %s %.0f %s (%.0f%%", | ||
367 | output, flag_header, | ||
358 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 368 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
359 | path->dfree_units, | 369 | path->dfree_units, |
360 | units, | 370 | units, |
361 | path->dfree_pct); | 371 | path->dfree_pct); |
362 | if (path->dused_inodes_percent < 0) { | 372 | if (path->dused_inodes_percent < 0) { |
363 | xasprintf(&output, "%s inode=-);", output); | 373 | xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); |
364 | } else { | 374 | } else { |
365 | xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent ); | 375 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); |
366 | } | 376 | } |
367 | 377 | free(flag_header); | |
368 | /* TODO: Need to do a similar debug line | 378 | /* TODO: Need to do a similar debug line |
369 | xasprintf (&details, _("%s\n\ | 379 | xasprintf (&details, _("%s\n\ |
370 | %.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), | 380 | %.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), |
@@ -962,6 +972,44 @@ print_usage (void) | |||
962 | void | 972 | void |
963 | stat_path (struct parameter_list *p) | 973 | stat_path (struct parameter_list *p) |
964 | { | 974 | { |
975 | #ifdef HAVE_PTHREAD_H | ||
976 | pthread_t stat_thread; | ||
977 | int statdone = 0; | ||
978 | int timer = timeout_interval; | ||
979 | struct timespec req, rem; | ||
980 | |||
981 | req.tv_sec = 0; | ||
982 | pthread_create(&stat_thread, NULL, do_stat_path, p); | ||
983 | while (timer-- > 0) { | ||
984 | req.tv_nsec = 10000000; | ||
985 | nanosleep(&req, &rem); | ||
986 | if (pthread_kill(stat_thread, 0)) { | ||
987 | statdone = 1; | ||
988 | break; | ||
989 | } else { | ||
990 | req.tv_nsec = 990000000; | ||
991 | nanosleep(&req, &rem); | ||
992 | } | ||
993 | } | ||
994 | if (statdone == 1) { | ||
995 | pthread_join(stat_thread, NULL); | ||
996 | } else { | ||
997 | pthread_detach(stat_thread); | ||
998 | if (verbose >= 3) | ||
999 | printf("stat did not return within %ds on %s\n", timeout_interval, p->name); | ||
1000 | printf("DISK %s - ", _("CRITICAL")); | ||
1001 | die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("hangs"), _("Timeout")); | ||
1002 | } | ||
1003 | #else | ||
1004 | do_stat_path(p); | ||
1005 | #endif | ||
1006 | } | ||
1007 | |||
1008 | void * | ||
1009 | do_stat_path (void *in) | ||
1010 | { | ||
1011 | struct parameter_list *p = in; | ||
1012 | |||
965 | /* Stat entry to check that dir exists and is accessible */ | 1013 | /* Stat entry to check that dir exists and is accessible */ |
966 | if (verbose >= 3) | 1014 | if (verbose >= 3) |
967 | printf("calling stat on %s\n", p->name); | 1015 | printf("calling stat on %s\n", p->name); |
@@ -971,6 +1019,7 @@ stat_path (struct parameter_list *p) | |||
971 | printf("DISK %s - ", _("CRITICAL")); | 1019 | printf("DISK %s - ", _("CRITICAL")); |
972 | die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno)); | 1020 | die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno)); |
973 | } | 1021 | } |
1022 | return NULL; | ||
974 | } | 1023 | } |
975 | 1024 | ||
976 | 1025 | ||