diff options
Diffstat (limited to 'lib/utils_base.h')
-rw-r--r-- | lib/utils_base.h | 69 |
1 files changed, 31 insertions, 38 deletions
diff --git a/lib/utils_base.h b/lib/utils_base.h index 9d4dffed..123066f8 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h | |||
@@ -2,8 +2,15 @@ | |||
2 | #define _UTILS_BASE_ | 2 | #define _UTILS_BASE_ |
3 | /* Header file for Monitoring Plugins utils_base.c */ | 3 | /* Header file for Monitoring Plugins utils_base.c */ |
4 | 4 | ||
5 | #include "../config.h" | ||
6 | #include <time.h> | ||
7 | |||
8 | #include "./perfdata.h" | ||
9 | #include "./thresholds.h" | ||
10 | |||
11 | |||
5 | #ifndef USE_OPENSSL | 12 | #ifndef USE_OPENSSL |
6 | # include "sha256.h" | 13 | # include "sha256.h" |
7 | #endif | 14 | #endif |
8 | 15 | ||
9 | /* This file holds header information for thresholds - use this in preference to | 16 | /* This file holds header information for thresholds - use this in preference to |
@@ -19,49 +26,35 @@ | |||
19 | #define OUTSIDE 0 | 26 | #define OUTSIDE 0 |
20 | #define INSIDE 1 | 27 | #define INSIDE 1 |
21 | 28 | ||
22 | typedef struct range_struct { | ||
23 | double start; | ||
24 | bool start_infinity; | ||
25 | double end; | ||
26 | int end_infinity; | ||
27 | int alert_on; /* OUTSIDE (default) or INSIDE */ | ||
28 | char* text; /* original unparsed text input */ | ||
29 | } range; | ||
30 | |||
31 | typedef struct thresholds_struct { | ||
32 | range *warning; | ||
33 | range *critical; | ||
34 | } thresholds; | ||
35 | |||
36 | #define NP_STATE_FORMAT_VERSION 1 | 29 | #define NP_STATE_FORMAT_VERSION 1 |
37 | 30 | ||
38 | typedef struct state_data_struct { | 31 | typedef struct state_data_struct { |
39 | time_t time; | 32 | time_t time; |
40 | void *data; | 33 | void *data; |
41 | int length; /* Of binary data */ | 34 | int length; /* Of binary data */ |
42 | } state_data; | 35 | } state_data; |
43 | |||
44 | 36 | ||
45 | typedef struct state_key_struct { | 37 | typedef struct state_key_struct { |
46 | char *name; | 38 | char *name; |
47 | char *plugin_name; | 39 | char *plugin_name; |
48 | int data_version; | 40 | int data_version; |
49 | char *_filename; | 41 | char *_filename; |
50 | state_data *state_data; | 42 | state_data *state_data; |
51 | } state_key; | 43 | } state_key; |
52 | 44 | ||
53 | typedef struct np_struct { | 45 | typedef struct np_struct { |
54 | char *plugin_name; | 46 | char *plugin_name; |
55 | state_key *state; | 47 | state_key *state; |
56 | int argc; | 48 | int argc; |
57 | char **argv; | 49 | char **argv; |
58 | } monitoring_plugin; | 50 | } monitoring_plugin; |
59 | 51 | ||
60 | range *parse_range_string (char *); | 52 | range *parse_range_string(char *); |
61 | int _set_thresholds(thresholds **, char *, char *); | 53 | int _set_thresholds(thresholds **, char *, char *); |
62 | void set_thresholds(thresholds **, char *, char *); | 54 | void set_thresholds(thresholds **, char *, char *); |
63 | void print_thresholds(const char *, thresholds *); | 55 | void print_thresholds(const char *, thresholds *); |
64 | bool check_range(double, range *); | 56 | bool check_range(double, range *); |
57 | bool mp_check_range(mp_perfdata_value, mp_range); | ||
65 | int get_status(double, thresholds *); | 58 | int get_status(double, thresholds *); |
66 | 59 | ||
67 | /* Handle timeouts */ | 60 | /* Handle timeouts */ |
@@ -71,13 +64,13 @@ extern unsigned int timeout_interval; | |||
71 | /* All possible characters in a threshold range */ | 64 | /* All possible characters in a threshold range */ |
72 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" | 65 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" |
73 | 66 | ||
74 | char *np_escaped_string (const char *); | 67 | char *np_escaped_string(const char *); |
75 | 68 | ||
76 | void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3))); | 69 | void die(int, const char *, ...) __attribute__((noreturn, format(printf, 2, 3))); |
77 | 70 | ||
78 | /* Return codes for _set_thresholds */ | 71 | /* Return codes for _set_thresholds */ |
79 | #define NP_RANGE_UNPARSEABLE 1 | 72 | #define NP_RANGE_UNPARSEABLE 1 |
80 | #define NP_WARN_WITHIN_CRIT 2 | 73 | #define NP_WARN_WITHIN_CRIT 2 |
81 | 74 | ||
82 | /* a simple check to see if we're running as root. | 75 | /* a simple check to see if we're running as root. |
83 | * returns zero on failure, nonzero on success */ | 76 | * returns zero on failure, nonzero on success */ |
@@ -93,7 +86,7 @@ int np_check_if_root(void); | |||
93 | * This function can be used to parse NTP control packet data and performance | 86 | * This function can be used to parse NTP control packet data and performance |
94 | * data strings. | 87 | * data strings. |
95 | */ | 88 | */ |
96 | char *np_extract_value(const char*, const char*, char); | 89 | char *np_extract_value(const char *, const char *, char); |
97 | 90 | ||
98 | /* | 91 | /* |
99 | * Same as np_extract_value with separator suitable for NTP control packet | 92 | * Same as np_extract_value with separator suitable for NTP control packet |
@@ -105,15 +98,15 @@ char *np_extract_value(const char*, const char*, char); | |||
105 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and | 98 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and |
106 | * return the corresponding NP_STATE or ERROR) | 99 | * return the corresponding NP_STATE or ERROR) |
107 | */ | 100 | */ |
108 | int mp_translate_state (char *); | 101 | int mp_translate_state(char *); |
109 | 102 | ||
110 | void np_enable_state(char *, int); | 103 | void np_enable_state(char *, int); |
111 | state_data *np_state_read(); | 104 | state_data *np_state_read(void); |
112 | void np_state_write_string(time_t, char *); | 105 | void np_state_write_string(time_t, char *); |
113 | 106 | ||
114 | void np_init(char *, int argc, char **argv); | 107 | void np_init(char *, int argc, char **argv); |
115 | void np_set_args(int argc, char **argv); | 108 | void np_set_args(int argc, char **argv); |
116 | void np_cleanup(); | 109 | void np_cleanup(void); |
117 | const char *state_text (int); | 110 | const char *state_text(int); |
118 | 111 | ||
119 | #endif /* _UTILS_BASE_ */ | 112 | #endif /* _UTILS_BASE_ */ |