3 /* Header file for nagios plugins utils_base.c */
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 */
20 typedef struct range_struct
{
22 int start_infinity
; /* FALSE (default) or TRUE */
25 int alert_on
; /* OUTSIDE (default) or INSIDE */
28 typedef struct thresholds_struct
{
33 #define NP_STATE_FORMAT_VERSION 1
35 typedef struct state_data_struct
{
38 int length
; /* Of binary data */
42 typedef struct state_key_struct
{
47 state_data
*state_data
;
50 typedef struct np_struct
{
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
*);
64 /* All possible characters in a threshold range */
65 #define NP_THRESHOLDS_CHARS "0123456789.:@~"
67 char *np_escaped_string (const char *);
69 void die (int, const char *, ...) __attribute__((noreturn
,format(printf
, 2, 3)));
71 /* Return codes for _set_thresholds */
72 #define NP_RANGE_UNPARSEABLE 1
73 #define NP_WARN_WITHIN_CRIT 2
75 /* a simple check to see if we're running as root.
76 * returns zero on failure, nonzero on success */
77 int np_check_if_root(void);
78 /* and a helpful wrapper around that. it returns the same status
79 * code from the above function, in case it's helpful for testing */
80 int np_warn_if_not_root(void);
83 * Extract the value from key/value pairs, or return NULL. The value returned
85 * This function can be used to parse NTP control packet data and performance
88 char *np_extract_value(const char*, const char*, char);
91 * Same as np_extract_value with separator suitable for NTP control packet
94 #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',')
97 void np_enable_state(char *, int);
98 state_data
*np_state_read();
99 void np_state_write_string(time_t, char *);
101 void np_init(char *, int argc
, char **argv
);
102 void np_set_args(int argc
, char **argv
);
105 #endif /* _UTILS_BASE_ */