summaryrefslogtreecommitdiffstats
path: root/lib/utils_base.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils_base.h')
-rw-r--r--lib/utils_base.h74
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
22typedef 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
31typedef struct thresholds_struct {
32 range *warning;
33 range *critical;
34 } thresholds;
35
36#define NP_STATE_FORMAT_VERSION 1
37
38typedef struct state_data_struct {
39 time_t time;
40 void *data;
41 int length; /* Of binary data */
42 } state_data;
43
44
45typedef 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
53typedef struct np_struct { 29typedef 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
60range *parse_range_string (char *); 35range *parse_range_string(char *);
61int _set_thresholds(thresholds **, char *, char *); 36int _set_thresholds(thresholds **, char *, char *);
62void set_thresholds(thresholds **, char *, char *); 37void set_thresholds(thresholds **, char *, char *);
63void print_thresholds(const char *, thresholds *); 38void print_thresholds(const char *, thresholds *);
64bool check_range(double, range *); 39bool check_range(double, range *);
65int get_status(double, thresholds *); 40bool mp_check_range(mp_perfdata_value, mp_range);
41mp_state_enum get_status(double, thresholds *);
66 42
67/* Handle timeouts */ 43/* Handle timeouts */
68extern int timeout_state; 44extern mp_state_enum timeout_state;
69extern unsigned int timeout_interval; 45extern 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
74char *np_escaped_string (const char *); 50char *np_escaped_string(const char *);
75 51
76void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3))); 52void 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 */
96char *np_extract_value(const char*, const char*, char); 72char *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 */
108int mp_translate_state (char *); 84int mp_translate_state(char *);
109
110void np_enable_state(char *, int);
111state_data *np_state_read();
112void np_state_write_string(time_t, char *);
113 85
114void np_init(char *, int argc, char **argv); 86void np_init(char *, int argc, char **argv);
115void np_set_args(int argc, char **argv); 87void np_set_args(int argc, char **argv);
116void np_cleanup(); 88void np_cleanup(void);
117const char *state_text (int); 89const char *state_text(mp_state_enum);
118 90
119#endif /* _UTILS_BASE_ */ 91#endif /* _UTILS_BASE_ */