CI: Fallback on mysql service
[monitoring-plugins.git] / lib / utils_base.h
blob59065504551197fe5bf22505cd0841c8891753fc
1 #ifndef _UTILS_BASE_
2 #define _UTILS_BASE_
3 /* Header file for Monitoring Plugins utils_base.c */
5 #include "sha256.h"
7 /* This file holds header information for thresholds - use this in preference to
8 individual plugin logic */
10 /* This has not been merged with utils.h because of problems with
11 timeout_interval when other utils_*.h files use utils.h */
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 */
17 #define OUTSIDE 0
18 #define INSIDE 1
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 char* text; /* original unparsed text input */
27 } range;
29 typedef struct thresholds_struct {
30 range *warning;
31 range *critical;
32 } thresholds;
34 #define NP_STATE_FORMAT_VERSION 1
36 typedef struct state_data_struct {
37 time_t time;
38 void *data;
39 int length; /* Of binary data */
40 } state_data;
43 typedef struct state_key_struct {
44 char *name;
45 char *plugin_name;
46 int data_version;
47 char *_filename;
48 state_data *state_data;
49 } state_key;
51 typedef struct np_struct {
52 char *plugin_name;
53 state_key *state;
54 int argc;
55 char **argv;
56 } monitoring_plugin;
58 range *parse_range_string (char *);
59 int _set_thresholds(thresholds **, char *, char *);
60 void set_thresholds(thresholds **, char *, char *);
61 void print_thresholds(const char *, thresholds *);
62 int check_range(double, range *);
63 int get_status(double, thresholds *);
65 /* Handle timeouts */
66 extern unsigned int timeout_state;
67 extern unsigned int timeout_interval;
69 /* All possible characters in a threshold range */
70 #define NP_THRESHOLDS_CHARS "-0123456789.:@~"
72 char *np_escaped_string (const char *);
74 void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)));
76 /* Return codes for _set_thresholds */
77 #define NP_RANGE_UNPARSEABLE 1
78 #define NP_WARN_WITHIN_CRIT 2
80 /* a simple check to see if we're running as root.
81 * returns zero on failure, nonzero on success */
82 int np_check_if_root(void);
84 /* mp_suid() returns true if the real and effective uids differs, such as when
85 * running a suid plugin */
86 #define mp_suid() (getuid() != geteuid())
89 * Extract the value from key/value pairs, or return NULL. The value returned
90 * can be free()ed.
91 * This function can be used to parse NTP control packet data and performance
92 * data strings.
94 char *np_extract_value(const char*, const char*, char);
97 * Same as np_extract_value with separator suitable for NTP control packet
98 * payloads (comma)
100 #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',')
103 * Read a string representing a state (ok, warning... or numeric: 0, 1) and
104 * return the corresponding NP_STATE or ERROR)
106 int mp_translate_state (char *);
108 void np_enable_state(char *, int);
109 state_data *np_state_read();
110 void np_state_write_string(time_t, char *);
112 void np_init(char *, int argc, char **argv);
113 void np_set_args(int argc, char **argv);
114 void np_cleanup();
115 const char *state_text (int);
117 #endif /* _UTILS_BASE_ */