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.c71
1 files changed, 17 insertions, 54 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 9693bad3..4b5ba5fe 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -51,9 +51,6 @@ 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
57 54
58#ifdef __CYGWIN__ 55#ifdef __CYGWIN__
59# include <windows.h> 56# include <windows.h>
@@ -61,9 +58,6 @@ const char *email = "devel@monitoring-plugins.org";
61# define ERROR -1 58# define ERROR -1
62#endif 59#endif
63 60
64/* If nonzero, show inode information. */
65static int inode_format = 1;
66
67/* If nonzero, show even filesystems with zero size or 61/* If nonzero, show even filesystems with zero size or
68 uninteresting types. */ 62 uninteresting types. */
69static int show_all_fs = 1; 63static int show_all_fs = 1;
@@ -133,7 +127,6 @@ void print_help (void);
133void print_usage (void); 127void print_usage (void);
134double calculate_percent(uintmax_t, uintmax_t); 128double calculate_percent(uintmax_t, uintmax_t);
135void stat_path (struct parameter_list *p); 129void stat_path (struct parameter_list *p);
136void *do_stat_path (void *p);
137void get_stats (struct parameter_list *p, struct fs_usage *fsp); 130void get_stats (struct parameter_list *p, struct fs_usage *fsp);
138void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); 131void get_path_stats (struct parameter_list *p, struct fs_usage *fsp);
139 132
@@ -172,6 +165,7 @@ main (int argc, char **argv)
172 int result = STATE_UNKNOWN; 165 int result = STATE_UNKNOWN;
173 int disk_result = STATE_UNKNOWN; 166 int disk_result = STATE_UNKNOWN;
174 char *output; 167 char *output;
168 char *ko_output;
175 char *details; 169 char *details;
176 char *perf; 170 char *perf;
177 char *preamble; 171 char *preamble;
@@ -182,7 +176,7 @@ main (int argc, char **argv)
182 int temp_result; 176 int temp_result;
183 177
184 struct mount_entry *me; 178 struct mount_entry *me;
185 struct fs_usage fsp, tmpfsp; 179 struct fs_usage fsp;
186 struct parameter_list *temp_list, *path; 180 struct parameter_list *temp_list, *path;
187 181
188#ifdef __CYGWIN__ 182#ifdef __CYGWIN__
@@ -191,6 +185,7 @@ main (int argc, char **argv)
191 185
192 preamble = strdup (" - free space:"); 186 preamble = strdup (" - free space:");
193 output = strdup (""); 187 output = strdup ("");
188 ko_output = strdup ("");
194 details = strdup (""); 189 details = strdup ("");
195 perf = strdup (""); 190 perf = strdup ("");
196 stat_buf = malloc(sizeof *stat_buf); 191 stat_buf = malloc(sizeof *stat_buf);
@@ -355,9 +350,6 @@ main (int argc, char **argv)
355 TRUE, 0, 350 TRUE, 0,
356 TRUE, path->dtotal_units)); 351 TRUE, path->dtotal_units));
357 352
358 if (disk_result==STATE_OK && erronly && !verbose)
359 continue;
360
361 if(disk_result && verbose >= 1) { 353 if(disk_result && verbose >= 1) {
362 xasprintf(&flag_header, " %s [", state_text (disk_result)); 354 xasprintf(&flag_header, " %s [", state_text (disk_result));
363 } else { 355 } else {
@@ -383,15 +375,27 @@ main (int argc, char **argv)
383 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); 375 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
384 */ 376 */
385 377
378 /* OS: #1420 save all not ok paths to different output, but only in case of error only option */
379 if (disk_result!=STATE_OK && erronly) {
380 xasprintf (&ko_output, "%s%s %s %.0f %s (%.0f%%",
381 ko_output, flag_header,
382 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
383 path->dfree_units,
384 units,
385 path->dfree_pct);
386 }
387
386 } 388 }
387 389
390 /* OS: #1420 only show offending paths if error only option is set, but show all paths if everything is ok */
391 output = (erronly && result!=STATE_OK) ? ko_output : output;
388 } 392 }
389 393
390 if (verbose >= 2) 394 if (verbose >= 2)
391 xasprintf (&output, "%s%s", output, details); 395 xasprintf (&output, "%s%s", output, details);
392 396
393 397
394 printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf); 398 printf ("DISK %s%s%s|%s\n", state_text (result), preamble, output, perf);
395 return result; 399 return result;
396} 400}
397 401
@@ -427,9 +431,7 @@ process_arguments (int argc, char **argv)
427 int c, err; 431 int c, err;
428 struct parameter_list *se; 432 struct parameter_list *se;
429 struct parameter_list *temp_list = NULL, *previous = NULL; 433 struct parameter_list *temp_list = NULL, *previous = NULL;
430 struct parameter_list *temp_path_select_list = NULL; 434 struct mount_entry *me;
431 struct mount_entry *me, *temp_me;
432 int result = OK;
433 regex_t re; 435 regex_t re;
434 int cflags = REG_NOSUB | REG_EXTENDED; 436 int cflags = REG_NOSUB | REG_EXTENDED;
435 int default_cflags = cflags; 437 int default_cflags = cflags;
@@ -972,44 +974,6 @@ print_usage (void)
972void 974void
973stat_path (struct parameter_list *p) 975stat_path (struct parameter_list *p)
974{ 976{
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
1008void *
1009do_stat_path (void *in)
1010{
1011 struct parameter_list *p = in;
1012
1013 /* Stat entry to check that dir exists and is accessible */ 977 /* Stat entry to check that dir exists and is accessible */
1014 if (verbose >= 3) 978 if (verbose >= 3)
1015 printf("calling stat on %s\n", p->name); 979 printf("calling stat on %s\n", p->name);
@@ -1019,7 +983,6 @@ do_stat_path (void *in)
1019 printf("DISK %s - ", _("CRITICAL")); 983 printf("DISK %s - ", _("CRITICAL"));
1020 die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno)); 984 die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno));
1021 } 985 }
1022 return NULL;
1023} 986}
1024 987
1025 988