summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2019-04-04 11:09:15 (GMT)
committerAndreas Baumann <mail@andreasbaumann.cc>2019-04-04 11:09:15 (GMT)
commit2f4d6764d78cf085601b34ac92486405bd11095d (patch)
tree550601dc79e74fd4c184dc96a95687d1d1238b43 /lib
parentfaea5899ba3264581bf75649e4b399d0b69bd125 (diff)
parent5f16ba81c4af1a05e67806ca989a1dd46248a5fd (diff)
downloadmonitoring-plugins-2f4d6764d78cf085601b34ac92486405bd11095d.tar.gz
Merge branch 'master' into feature_check_curl
Diffstat (limited to 'lib')
-rw-r--r--lib/utils_base.c19
-rw-r--r--lib/utils_base.h5
-rw-r--r--lib/utils_cmd.c42
-rw-r--r--lib/utils_cmd.h13
-rw-r--r--lib/utils_disk.c2
-rw-r--r--lib/utils_disk.h3
6 files changed, 58 insertions, 26 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c
index 19a531f..fd7058d 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -37,6 +37,9 @@
37 37
38monitoring_plugin *this_monitoring_plugin=NULL; 38monitoring_plugin *this_monitoring_plugin=NULL;
39 39
40unsigned int timeout_state = STATE_CRITICAL;
41unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
42
40int _np_state_read_file(FILE *); 43int _np_state_read_file(FILE *);
41 44
42void np_init( char *plugin_name, int argc, char **argv ) { 45void np_init( char *plugin_name, int argc, char **argv ) {
@@ -359,6 +362,22 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
359 return value; 362 return value;
360} 363}
361 364
365const char *
366state_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}
362 381
363/* 382/*
364 * 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 *);
61int check_range(double, range *); 61int check_range(double, range *);
62int get_status(double, thresholds *); 62int get_status(double, thresholds *);
63 63
64/* Handle timeouts */
65extern unsigned int timeout_state;
66extern 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 *);
107void np_init(char *, int argc, char **argv); 111void np_init(char *, int argc, char **argv);
108void np_set_args(int argc, char **argv); 112void np_set_args(int argc, char **argv);
109void np_cleanup(); 113void np_cleanup();
114const 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. */
76static 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
85static 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 **/
94static int _cmd_open (char *const *, int *, int *) 70static 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
386void
387timeout_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. */
43static pid_t *_cmd_pids = NULL;
44
45RETSIGTYPE 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;