2006-09-02 16:41:18 -04:00
|
|
|
#ifndef _UTILS_BASE_
|
|
|
|
|
#define _UTILS_BASE_
|
2014-01-21 10:19:20 -05:00
|
|
|
/* Header file for Monitoring Plugins utils_base.c */
|
2006-07-13 19:58:00 -04:00
|
|
|
|
2010-06-17 05:16:43 -04:00
|
|
|
#include "sha1.h"
|
|
|
|
|
|
2006-07-13 19:58:00 -04:00
|
|
|
/* This file holds header information for thresholds - use this in preference to
|
|
|
|
|
individual plugin logic */
|
|
|
|
|
|
|
|
|
|
/* This has not been merged with utils.h because of problems with
|
|
|
|
|
timeout_interval when other utils_*.h files use utils.h */
|
|
|
|
|
|
|
|
|
|
/* Long term, add new functions to utils_base.h for common routines
|
|
|
|
|
and utils_*.h for specific to plugin routines. If routines are
|
|
|
|
|
placed in utils_*.h, then these can be tested with libtap */
|
|
|
|
|
|
|
|
|
|
#define OUTSIDE 0
|
|
|
|
|
#define INSIDE 1
|
|
|
|
|
|
|
|
|
|
typedef struct range_struct {
|
|
|
|
|
double start;
|
|
|
|
|
int start_infinity; /* FALSE (default) or TRUE */
|
|
|
|
|
double end;
|
|
|
|
|
int end_infinity;
|
|
|
|
|
int alert_on; /* OUTSIDE (default) or INSIDE */
|
2021-11-17 05:58:41 -05:00
|
|
|
char* text; /* original unparsed text input */
|
2006-07-13 19:58:00 -04:00
|
|
|
} range;
|
|
|
|
|
|
|
|
|
|
typedef struct thresholds_struct {
|
|
|
|
|
range *warning;
|
|
|
|
|
range *critical;
|
|
|
|
|
} thresholds;
|
|
|
|
|
|
2010-06-17 05:16:43 -04:00
|
|
|
#define NP_STATE_FORMAT_VERSION 1
|
|
|
|
|
|
|
|
|
|
typedef struct state_data_struct {
|
|
|
|
|
time_t time;
|
|
|
|
|
void *data;
|
|
|
|
|
int length; /* Of binary data */
|
|
|
|
|
} state_data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct state_key_struct {
|
|
|
|
|
char *name;
|
|
|
|
|
char *plugin_name;
|
|
|
|
|
int data_version;
|
|
|
|
|
char *_filename;
|
|
|
|
|
state_data *state_data;
|
|
|
|
|
} state_key;
|
|
|
|
|
|
|
|
|
|
typedef struct np_struct {
|
|
|
|
|
char *plugin_name;
|
|
|
|
|
state_key *state;
|
|
|
|
|
int argc;
|
|
|
|
|
char **argv;
|
2014-01-18 03:40:24 -05:00
|
|
|
} monitoring_plugin;
|
2010-06-17 05:16:43 -04:00
|
|
|
|
2006-07-13 19:58:00 -04:00
|
|
|
range *parse_range_string (char *);
|
|
|
|
|
int _set_thresholds(thresholds **, char *, char *);
|
|
|
|
|
void set_thresholds(thresholds **, char *, char *);
|
2007-04-20 13:45:44 -04:00
|
|
|
void print_thresholds(const char *, thresholds *);
|
2006-07-13 19:58:00 -04:00
|
|
|
int check_range(double, range *);
|
|
|
|
|
int get_status(double, thresholds *);
|
|
|
|
|
|
2019-02-15 04:36:28 -05:00
|
|
|
/* Handle timeouts */
|
|
|
|
|
extern unsigned int timeout_state;
|
|
|
|
|
extern unsigned int timeout_interval;
|
|
|
|
|
|
2009-05-27 20:52:55 -04:00
|
|
|
/* All possible characters in a threshold range */
|
2013-11-14 21:04:55 -05:00
|
|
|
#define NP_THRESHOLDS_CHARS "-0123456789.:@~"
|
2009-05-27 20:52:55 -04:00
|
|
|
|
2006-07-13 19:58:00 -04:00
|
|
|
char *np_escaped_string (const char *);
|
|
|
|
|
|
|
|
|
|
void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)));
|
2006-09-02 16:41:18 -04:00
|
|
|
|
2006-10-18 08:03:10 -04:00
|
|
|
/* Return codes for _set_thresholds */
|
|
|
|
|
#define NP_RANGE_UNPARSEABLE 1
|
|
|
|
|
#define NP_WARN_WITHIN_CRIT 2
|
|
|
|
|
|
2007-05-27 09:46:32 -04:00
|
|
|
/* a simple check to see if we're running as root.
|
|
|
|
|
* returns zero on failure, nonzero on success */
|
|
|
|
|
int np_check_if_root(void);
|
|
|
|
|
|
2014-01-29 03:20:23 -05:00
|
|
|
/* mp_suid() returns true if the real and effective uids differs, such as when
|
|
|
|
|
* running a suid plugin */
|
|
|
|
|
#define mp_suid() (getuid() != geteuid())
|
|
|
|
|
|
2009-01-19 22:14:03 -05:00
|
|
|
/*
|
|
|
|
|
* Extract the value from key/value pairs, or return NULL. The value returned
|
|
|
|
|
* can be free()ed.
|
|
|
|
|
* This function can be used to parse NTP control packet data and performance
|
|
|
|
|
* data strings.
|
|
|
|
|
*/
|
2009-01-26 02:05:21 -05:00
|
|
|
char *np_extract_value(const char*, const char*, char);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Same as np_extract_value with separator suitable for NTP control packet
|
|
|
|
|
* payloads (comma)
|
|
|
|
|
*/
|
|
|
|
|
#define np_extract_ntpvar(l, n) np_extract_value(l, n, ',')
|
2009-01-19 22:14:03 -05:00
|
|
|
|
2014-01-29 03:20:23 -05:00
|
|
|
/*
|
|
|
|
|
* Read a string representing a state (ok, warning... or numeric: 0, 1) and
|
|
|
|
|
* return the corresponding NP_STATE or ERROR)
|
|
|
|
|
*/
|
|
|
|
|
int mp_translate_state (char *);
|
2010-06-17 05:16:43 -04:00
|
|
|
|
|
|
|
|
void np_enable_state(char *, int);
|
|
|
|
|
state_data *np_state_read();
|
|
|
|
|
void np_state_write_string(time_t, char *);
|
|
|
|
|
|
|
|
|
|
void np_init(char *, int argc, char **argv);
|
|
|
|
|
void np_set_args(int argc, char **argv);
|
|
|
|
|
void np_cleanup();
|
2019-02-15 04:36:28 -05:00
|
|
|
const char *state_text (int);
|
2010-06-17 05:16:43 -04:00
|
|
|
|
2006-09-02 16:41:18 -04:00
|
|
|
#endif /* _UTILS_BASE_ */
|