diff options
Diffstat (limited to 'lib/utils_base.h')
| -rw-r--r-- | lib/utils_base.h | 74 |
1 files changed, 23 insertions, 51 deletions
diff --git a/lib/utils_base.h b/lib/utils_base.h index 9d4dffed..27884bf0 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 | #include "states.h" | ||
| 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,65 +26,34 @@ | |||
| 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 | ||
| 37 | |||
| 38 | typedef struct state_data_struct { | ||
| 39 | time_t time; | ||
| 40 | void *data; | ||
| 41 | int length; /* Of binary data */ | ||
| 42 | } state_data; | ||
| 43 | |||
| 44 | |||
| 45 | typedef struct state_key_struct { | ||
| 46 | char *name; | ||
| 47 | char *plugin_name; | ||
| 48 | int data_version; | ||
| 49 | char *_filename; | ||
| 50 | state_data *state_data; | ||
| 51 | } state_key; | ||
| 52 | |||
| 53 | typedef struct np_struct { | 29 | typedef struct np_struct { |
| 54 | char *plugin_name; | 30 | char *plugin_name; |
| 55 | state_key *state; | 31 | int argc; |
| 56 | int argc; | 32 | char **argv; |
| 57 | char **argv; | 33 | } monitoring_plugin; |
| 58 | } monitoring_plugin; | ||
| 59 | 34 | ||
| 60 | range *parse_range_string (char *); | 35 | range *parse_range_string(char *); |
| 61 | int _set_thresholds(thresholds **, char *, char *); | 36 | int _set_thresholds(thresholds **, char *, char *); |
| 62 | void set_thresholds(thresholds **, char *, char *); | 37 | void set_thresholds(thresholds **, char *, char *); |
| 63 | void print_thresholds(const char *, thresholds *); | 38 | void print_thresholds(const char *, thresholds *); |
| 64 | bool check_range(double, range *); | 39 | bool check_range(double, range *); |
| 65 | int get_status(double, thresholds *); | 40 | bool mp_check_range(mp_perfdata_value, mp_range); |
| 41 | mp_state_enum get_status(double, thresholds *); | ||
| 66 | 42 | ||
| 67 | /* Handle timeouts */ | 43 | /* Handle timeouts */ |
| 68 | extern int timeout_state; | 44 | extern mp_state_enum timeout_state; |
| 69 | extern unsigned int timeout_interval; | 45 | extern unsigned int timeout_interval; |
| 70 | 46 | ||
| 71 | /* All possible characters in a threshold range */ | 47 | /* All possible characters in a threshold range */ |
| 72 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" | 48 | #define NP_THRESHOLDS_CHARS "-0123456789.:@~" |
| 73 | 49 | ||
| 74 | char *np_escaped_string (const char *); | 50 | char *np_escaped_string(const char *); |
| 75 | 51 | ||
| 76 | void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3))); | 52 | void die(int, const char *, ...) __attribute__((noreturn, format(printf, 2, 3))); |
| 77 | 53 | ||
| 78 | /* Return codes for _set_thresholds */ | 54 | /* Return codes for _set_thresholds */ |
| 79 | #define NP_RANGE_UNPARSEABLE 1 | 55 | #define NP_RANGE_UNPARSEABLE 1 |
| 80 | #define NP_WARN_WITHIN_CRIT 2 | 56 | #define NP_WARN_WITHIN_CRIT 2 |
| 81 | 57 | ||
| 82 | /* a simple check to see if we're running as root. | 58 | /* a simple check to see if we're running as root. |
| 83 | * returns zero on failure, nonzero on success */ | 59 | * returns zero on failure, nonzero on success */ |
| @@ -93,7 +69,7 @@ int np_check_if_root(void); | |||
| 93 | * This function can be used to parse NTP control packet data and performance | 69 | * This function can be used to parse NTP control packet data and performance |
| 94 | * data strings. | 70 | * data strings. |
| 95 | */ | 71 | */ |
| 96 | char *np_extract_value(const char*, const char*, char); | 72 | char *np_extract_value(const char *, const char *, char); |
| 97 | 73 | ||
| 98 | /* | 74 | /* |
| 99 | * Same as np_extract_value with separator suitable for NTP control packet | 75 | * Same as np_extract_value with separator suitable for NTP control packet |
| @@ -105,15 +81,11 @@ char *np_extract_value(const char*, const char*, char); | |||
| 105 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and | 81 | * Read a string representing a state (ok, warning... or numeric: 0, 1) and |
| 106 | * return the corresponding NP_STATE or ERROR) | 82 | * return the corresponding NP_STATE or ERROR) |
| 107 | */ | 83 | */ |
| 108 | int mp_translate_state (char *); | 84 | int mp_translate_state(char *); |
| 109 | |||
| 110 | void np_enable_state(char *, int); | ||
| 111 | state_data *np_state_read(); | ||
| 112 | void np_state_write_string(time_t, char *); | ||
| 113 | 85 | ||
| 114 | void np_init(char *, int argc, char **argv); | 86 | void np_init(char *, int argc, char **argv); |
| 115 | void np_set_args(int argc, char **argv); | 87 | void np_set_args(int argc, char **argv); |
| 116 | void np_cleanup(); | 88 | void np_cleanup(void); |
| 117 | const char *state_text (int); | 89 | const char *state_text(mp_state_enum); |
| 118 | 90 | ||
| 119 | #endif /* _UTILS_BASE_ */ | 91 | #endif /* _UTILS_BASE_ */ |
