check_snmp: Make use of standard threshold functions
[monitoring-plugins.git] / lib / utils_base.h
blob49e40a63b4d6747b672ce0e0b02ff4a1b0d8d26d
1 #ifndef _UTILS_BASE_
2 #define _UTILS_BASE_
3 /* Header file for nagios plugins utils_base.c */
5 /* This file holds header information for thresholds - use this in preference to
6 individual plugin logic */
8 /* This has not been merged with utils.h because of problems with
9 timeout_interval when other utils_*.h files use utils.h */
11 /* Long term, add new functions to utils_base.h for common routines
12 and utils_*.h for specific to plugin routines. If routines are
13 placed in utils_*.h, then these can be tested with libtap */
15 #define OUTSIDE 0
16 #define INSIDE 1
18 typedef struct range_struct {
19 double start;
20 int start_infinity; /* FALSE (default) or TRUE */
21 double end;
22 int end_infinity;
23 int alert_on; /* OUTSIDE (default) or INSIDE */
24 } range;
26 typedef struct thresholds_struct {
27 range *warning;
28 range *critical;
29 } thresholds;
31 range *parse_range_string (char *);
32 int _set_thresholds(thresholds **, char *, char *);
33 void set_thresholds(thresholds **, char *, char *);
34 void print_thresholds(const char *, thresholds *);
35 int check_range(double, range *);
36 int get_status(double, thresholds *);
38 /* All possible characters in a threshold range */
39 #define NP_THRESHOLDS_CHARS "0123456789.:@~"
41 char *np_escaped_string (const char *);
43 void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)));
45 /* Return codes for _set_thresholds */
46 #define NP_RANGE_UNPARSEABLE 1
47 #define NP_WARN_WITHIN_CRIT 2
49 /* a simple check to see if we're running as root.
50 * returns zero on failure, nonzero on success */
51 int np_check_if_root(void);
52 /* and a helpful wrapper around that. it returns the same status
53 * code from the above function, in case it's helpful for testing */
54 int np_warn_if_not_root(void);
57 * Extract the value from key/value pairs, or return NULL. The value returned
58 * can be free()ed.
59 * This function can be used to parse NTP control packet data and performance
60 * data strings.
62 char *np_extract_value(const char*, const char*, char);
65 * Same as np_extract_value with separator suitable for NTP control packet
66 * payloads (comma)
68 #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',')
70 #endif /* _UTILS_BASE_ */