1 #ifndef _UTILS_BASE_ 2 #define _UTILS_BASE_ 3 /* Header file for Monitoring Plugins utils_base.c */ 4 5 #include "sha1.h" 6 7 /* This file holds header information for thresholds - use this in preference to 8 individual plugin logic */ 9 10 /* This has not been merged with utils.h because of problems with 11 timeout_interval when other utils_*.h files use utils.h */ 12 13 /* Long term, add new functions to utils_base.h for common routines 14 and utils_*.h for specific to plugin routines. If routines are 15 placed in utils_*.h, then these can be tested with libtap */ 16 17 #define OUTSIDE 0 18 #define INSIDE 1 19 20 typedef struct range_struct { 21 double start; 22 int start_infinity; /* FALSE (default) or TRUE */ 23 double end; 24 int end_infinity; 25 int alert_on; /* OUTSIDE (default) or INSIDE */ 26 } range; 27 28 typedef struct thresholds_struct { 29 range *warning; 30 range *critical; 31 } thresholds; 32 33 #define NP_STATE_FORMAT_VERSION 1 34 35 typedef struct state_data_struct { 36 time_t time; 37 void *data; 38 int length; /* Of binary data */ 39 } state_data; 40 41 42 typedef struct state_key_struct { 43 char *name; 44 char *plugin_name; 45 int data_version; 46 char *_filename; 47 state_data *state_data; 48 } state_key; 49 50 typedef struct np_struct { 51 char *plugin_name; 52 state_key *state; 53 int argc; 54 char **argv; 55 } monitoring_plugin; 56 57 range *parse_range_string (char *); 58 int _set_thresholds(thresholds **, char *, char *); 59 void set_thresholds(thresholds **, char *, char *); 60 void print_thresholds(const char *, thresholds *); 61 int check_range(double, range *); 62 int get_status(double, thresholds *); 63 64 /* Handle timeouts */ 65 extern unsigned int timeout_state; 66 extern unsigned int timeout_interval; 67 68 /* All possible characters in a threshold range */ 69 #define NP_THRESHOLDS_CHARS "-0123456789.:@~" 70 71 char *np_escaped_string (const char *); 72 73 void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3))); 74 75 /* Return codes for _set_thresholds */ 76 #define NP_RANGE_UNPARSEABLE 1 77 #define NP_WARN_WITHIN_CRIT 2 78 79 /* a simple check to see if we're running as root. 80 * returns zero on failure, nonzero on success */ 81 int np_check_if_root(void); 82 83 /* mp_suid() returns true if the real and effective uids differs, such as when 84 * running a suid plugin */ 85 #define mp_suid() (getuid() != geteuid()) 86 87 /* 88 * Extract the value from key/value pairs, or return NULL. The value returned 89 * can be free()ed. 90 * This function can be used to parse NTP control packet data and performance 91 * data strings. 92 */ 93 char *np_extract_value(const char*, const char*, char); 94 95 /* 96 * Same as np_extract_value with separator suitable for NTP control packet 97 * payloads (comma) 98 */ 99 #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',') 100 101 /* 102 * Read a string representing a state (ok, warning... or numeric: 0, 1) and 103 * return the corresponding NP_STATE or ERROR) 104 */ 105 int mp_translate_state (char *); 106 107 void np_enable_state(char *, int); 108 state_data *np_state_read(); 109 void np_state_write_string(time_t, char *); 110 111 void np_init(char *, int argc, char **argv); 112 void np_set_args(int argc, char **argv); 113 void np_cleanup(); 114 const char *state_text (int); 115 116 #endif /* _UTILS_BASE_ */ 117