diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils_base.c | 30 | ||||
-rw-r--r-- | lib/utils_base.h | 5 | ||||
-rw-r--r-- | lib/utils_cmd.c | 42 | ||||
-rw-r--r-- | lib/utils_cmd.h | 13 | ||||
-rw-r--r-- | lib/utils_disk.c | 2 | ||||
-rw-r--r-- | lib/utils_disk.h | 3 |
6 files changed, 65 insertions, 30 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c index 3822bcf..fd7058d 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
@@ -37,6 +37,9 @@ | |||
37 | 37 | ||
38 | monitoring_plugin *this_monitoring_plugin=NULL; | 38 | monitoring_plugin *this_monitoring_plugin=NULL; |
39 | 39 | ||
40 | unsigned int timeout_state = STATE_CRITICAL; | ||
41 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; | ||
42 | |||
40 | int _np_state_read_file(FILE *); | 43 | int _np_state_read_file(FILE *); |
41 | 44 | ||
42 | void np_init( char *plugin_name, int argc, char **argv ) { | 45 | void np_init( char *plugin_name, int argc, char **argv ) { |
@@ -87,10 +90,13 @@ void _get_monitoring_plugin( monitoring_plugin **pointer ){ | |||
87 | void | 90 | void |
88 | die (int result, const char *fmt, ...) | 91 | die (int result, const char *fmt, ...) |
89 | { | 92 | { |
90 | va_list ap; | 93 | if(fmt!=NULL) { |
91 | va_start (ap, fmt); | 94 | va_list ap; |
92 | vprintf (fmt, ap); | 95 | va_start (ap, fmt); |
93 | va_end (ap); | 96 | vprintf (fmt, ap); |
97 | va_end (ap); | ||
98 | } | ||
99 | |||
94 | if(this_monitoring_plugin!=NULL) { | 100 | if(this_monitoring_plugin!=NULL) { |
95 | np_cleanup(); | 101 | np_cleanup(); |
96 | } | 102 | } |
@@ -356,6 +362,22 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { | |||
356 | return value; | 362 | return value; |
357 | } | 363 | } |
358 | 364 | ||
365 | const char * | ||
366 | state_text (int result) | ||
367 | { | ||
368 | switch (result) { | ||
369 | case STATE_OK: | ||
370 | return "OK"; | ||
371 | case STATE_WARNING: | ||
372 | return "WARNING"; | ||
373 | case STATE_CRITICAL: | ||
374 | return "CRITICAL"; | ||
375 | case STATE_DEPENDENT: | ||
376 | return "DEPENDENT"; | ||
377 | default: | ||
378 | return "UNKNOWN"; | ||
379 | } | ||
380 | } | ||
359 | 381 | ||
360 | /* | 382 | /* |
361 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and | 383 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and |
diff --git a/lib/utils_base.h b/lib/utils_base.h index 42ae0c0..d7e7dff 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h | |||
@@ -61,6 +61,10 @@ void print_thresholds(const char *, thresholds *); | |||
61 | int check_range(double, range *); | 61 | int check_range(double, range *); |
62 | int get_status(double, thresholds *); | 62 | int get_status(double, thresholds *); |
63 | 63 | ||
64 | /* Handle timeouts */ | ||
65 | extern unsigned int timeout_state; | ||
66 | extern unsigned int timeout_interval; | ||
67 | |||
64 | /* All possible characters in a threshold range */ | 68 | /* All possible characters in a threshold range */ |
65 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" | 69 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" |
66 | 70 | ||
@@ -107,5 +111,6 @@ void np_state_write_string(time_t, char *); | |||
107 | void np_init(char *, int argc, char **argv); | 111 | void np_init(char *, int argc, char **argv); |
108 | void np_set_args(int argc, char **argv); | 112 | void np_set_args(int argc, char **argv); |
109 | void np_cleanup(); | 113 | void np_cleanup(); |
114 | const char *state_text (int); | ||
110 | 115 | ||
111 | #endif /* _UTILS_BASE_ */ | 116 | #endif /* _UTILS_BASE_ */ |
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 7eb9a3a..795840d 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c | |||
@@ -40,6 +40,7 @@ | |||
40 | 40 | ||
41 | /** includes **/ | 41 | /** includes **/ |
42 | #include "common.h" | 42 | #include "common.h" |
43 | #include "utils.h" | ||
43 | #include "utils_cmd.h" | 44 | #include "utils_cmd.h" |
44 | #include "utils_base.h" | 45 | #include "utils_base.h" |
45 | #include <fcntl.h> | 46 | #include <fcntl.h> |
@@ -65,31 +66,6 @@ extern char **environ; | |||
65 | # define SIG_ERR ((Sigfunc *)-1) | 66 | # define SIG_ERR ((Sigfunc *)-1) |
66 | #endif | 67 | #endif |
67 | 68 | ||
68 | /* This variable must be global, since there's no way the caller | ||
69 | * can forcibly slay a dead or ungainly running program otherwise. | ||
70 | * Multithreading apps and plugins can initialize it (via CMD_INIT) | ||
71 | * in an async safe manner PRIOR to calling cmd_run() or cmd_run_array() | ||
72 | * for the first time. | ||
73 | * | ||
74 | * The check for initialized values is atomic and can | ||
75 | * occur in any number of threads simultaneously. */ | ||
76 | static pid_t *_cmd_pids = NULL; | ||
77 | |||
78 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | ||
79 | * If that fails and the macro isn't defined, we fall back to an educated | ||
80 | * guess. There's no guarantee that our guess is adequate and the program | ||
81 | * will die with SIGSEGV if it isn't and the upper boundary is breached. */ | ||
82 | #define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ | ||
83 | #define MAXFD_LIMIT 8192 /* upper limit of open files */ | ||
84 | #ifdef _SC_OPEN_MAX | ||
85 | static long maxfd = 0; | ||
86 | #elif defined(OPEN_MAX) | ||
87 | # define maxfd OPEN_MAX | ||
88 | #else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ | ||
89 | # define maxfd DEFAULT_MAXFD | ||
90 | #endif | ||
91 | |||
92 | |||
93 | /** prototypes **/ | 69 | /** prototypes **/ |
94 | static int _cmd_open (char *const *, int *, int *) | 70 | static int _cmd_open (char *const *, int *, int *) |
95 | __attribute__ ((__nonnull__ (1, 2, 3))); | 71 | __attribute__ ((__nonnull__ (1, 2, 3))); |
@@ -406,3 +382,19 @@ cmd_file_read ( char *filename, output *out, int flags) | |||
406 | 382 | ||
407 | return 0; | 383 | return 0; |
408 | } | 384 | } |
385 | |||
386 | void | ||
387 | timeout_alarm_handler (int signo) | ||
388 | { | ||
389 | size_t i; | ||
390 | if (signo == SIGALRM) { | ||
391 | printf (_("%s - Plugin timed out after %d seconds\n"), | ||
392 | state_text(timeout_state), timeout_interval); | ||
393 | |||
394 | if(_cmd_pids) for(i = 0; i < maxfd; i++) { | ||
395 | if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); | ||
396 | } | ||
397 | |||
398 | exit (timeout_state); | ||
399 | } | ||
400 | } | ||
diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h index ebaf15b..6f3aeb8 100644 --- a/lib/utils_cmd.h +++ b/lib/utils_cmd.h | |||
@@ -32,4 +32,17 @@ void cmd_init (void); | |||
32 | #define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */ | 32 | #define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */ |
33 | #define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */ | 33 | #define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */ |
34 | 34 | ||
35 | /* This variable must be global, since there's no way the caller | ||
36 | * can forcibly slay a dead or ungainly running program otherwise. | ||
37 | * Multithreading apps and plugins can initialize it (via CMD_INIT) | ||
38 | * in an async safe manner PRIOR to calling cmd_run() or cmd_run_array() | ||
39 | * for the first time. | ||
40 | * | ||
41 | * The check for initialized values is atomic and can | ||
42 | * occur in any number of threads simultaneously. */ | ||
43 | static pid_t *_cmd_pids = NULL; | ||
44 | |||
45 | RETSIGTYPE timeout_alarm_handler (int); | ||
46 | |||
47 | |||
35 | #endif /* _UTILS_CMD_ */ | 48 | #endif /* _UTILS_CMD_ */ |
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index efe35fc..c7c9126 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
@@ -69,6 +69,8 @@ np_add_parameter(struct parameter_list **list, const char *name) | |||
69 | new_path->dtotal_units = 0; | 69 | new_path->dtotal_units = 0; |
70 | new_path->inodes_total = 0; | 70 | new_path->inodes_total = 0; |
71 | new_path->inodes_free = 0; | 71 | new_path->inodes_free = 0; |
72 | new_path->inodes_free_to_root = 0; | ||
73 | new_path->inodes_used = 0; | ||
72 | new_path->dused_inodes_percent = 0; | 74 | new_path->dused_inodes_percent = 0; |
73 | new_path->dfree_inodes_percent = 0; | 75 | new_path->dfree_inodes_percent = 0; |
74 | 76 | ||
diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 83a3763..999270c 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h | |||
@@ -24,7 +24,8 @@ struct parameter_list | |||
24 | char *group; | 24 | char *group; |
25 | struct mount_entry *best_match; | 25 | struct mount_entry *best_match; |
26 | struct parameter_list *name_next; | 26 | struct parameter_list *name_next; |
27 | uintmax_t total, available, available_to_root, used, inodes_free, inodes_total; | 27 | uintmax_t total, available, available_to_root, used, |
28 | inodes_free, inodes_free_to_root, inodes_used, inodes_total; | ||
28 | double dfree_pct, dused_pct; | 29 | double dfree_pct, dused_pct; |
29 | double dused_units, dfree_units, dtotal_units; | 30 | double dused_units, dfree_units, dtotal_units; |
30 | double dused_inodes_percent, dfree_inodes_percent; | 31 | double dused_inodes_percent, dfree_inodes_percent; |