Back to index

nagios-plugins  1.4.16
utils_base.h
Go to the documentation of this file.
00001 #ifndef _UTILS_BASE_
00002 #define _UTILS_BASE_
00003 /* Header file for nagios plugins utils_base.c */
00004 
00005 #include "sha1.h"
00006 
00007 /* This file holds header information for thresholds - use this in preference to 
00008    individual plugin logic */
00009 
00010 /* This has not been merged with utils.h because of problems with
00011    timeout_interval when other utils_*.h files use utils.h */
00012 
00013 /* Long term, add new functions to utils_base.h for common routines
00014    and utils_*.h for specific to plugin routines. If routines are
00015    placed in utils_*.h, then these can be tested with libtap */
00016 
00017 #define OUTSIDE 0
00018 #define INSIDE  1
00019 
00020 typedef struct range_struct {
00021        double start;
00022        int    start_infinity;             /* FALSE (default) or TRUE */
00023        double end;
00024        int    end_infinity;
00025        int    alert_on;            /* OUTSIDE (default) or INSIDE */
00026        } range;
00027 
00028 typedef struct thresholds_struct {
00029        range  *warning;
00030        range  *critical;
00031        } thresholds;
00032 
00033 #define NP_STATE_FORMAT_VERSION 1
00034 
00035 typedef struct state_data_struct {
00036        time_t time;
00037        void   *data;
00038        int    length; /* Of binary data */
00039        } state_data;
00040 
00041 
00042 typedef struct state_key_struct {
00043        char       *name;
00044        char       *plugin_name;
00045        int        data_version;
00046        char       *_filename;
00047        state_data *state_data;
00048        } state_key;
00049 
00050 typedef struct np_struct {
00051        char      *plugin_name;
00052        state_key *state;
00053        int       argc;
00054        char      **argv;
00055        } nagios_plugin;
00056 
00057 range *parse_range_string (char *);
00058 int _set_thresholds(thresholds **, char *, char *);
00059 void set_thresholds(thresholds **, char *, char *);
00060 void print_thresholds(const char *, thresholds *);
00061 int check_range(double, range *);
00062 int get_status(double, thresholds *);
00063 
00064 /* All possible characters in a threshold range */
00065 #define NP_THRESHOLDS_CHARS "0123456789.:@~"
00066 
00067 char *np_escaped_string (const char *);
00068 
00069 void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)));
00070 
00071 /* Return codes for _set_thresholds */
00072 #define NP_RANGE_UNPARSEABLE 1
00073 #define NP_WARN_WITHIN_CRIT 2
00074 
00075 /* a simple check to see if we're running as root.  
00076  * returns zero on failure, nonzero on success */
00077 int np_check_if_root(void);
00078 /* and a helpful wrapper around that.  it returns the same status
00079  * code from the above function, in case it's helpful for testing */
00080 int np_warn_if_not_root(void);
00081 
00082 /*
00083  * Extract the value from key/value pairs, or return NULL. The value returned
00084  * can be free()ed.
00085  * This function can be used to parse NTP control packet data and performance
00086  * data strings.
00087  */
00088 char *np_extract_value(const char*, const char*, char);
00089 
00090 /*
00091  * Same as np_extract_value with separator suitable for NTP control packet
00092  * payloads (comma)
00093  */
00094 #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',')
00095 
00096 
00097 void np_enable_state(char *, int);
00098 state_data *np_state_read();
00099 void np_state_write_string(time_t, char *);
00100 
00101 void np_init(char *, int argc, char **argv);
00102 void np_set_args(int argc, char **argv);
00103 void np_cleanup();
00104 
00105 #endif /* _UTILS_BASE_ */