Code

Added state retention APIs. Implemented for check_snmp with --rate option.
[nagiosplug.git] / lib / utils_base.h
index c34f0445c9f515b314711eee37fb857ea50ea1a5..0cb371fd4970195a1018570e3708ea8c2ae401d5 100644 (file)
@@ -2,6 +2,8 @@
 #define _UTILS_BASE_
 /* Header file for nagios plugins utils_base.c */
 
+#include "sha1.h"
+
 /* This file holds header information for thresholds - use this in preference to 
    individual plugin logic */
 
@@ -28,6 +30,30 @@ typedef struct thresholds_struct {
        range   *critical;
        } thresholds;
 
+#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;
+       } nagios_plugin;
+
 range *parse_range_string (char *);
 int _set_thresholds(thresholds **, char *, char *);
 void set_thresholds(thresholds **, char *, char *);
@@ -35,6 +61,9 @@ void print_thresholds(const char *, thresholds *);
 int check_range(double, range *);
 int get_status(double, thresholds *);
 
+/* All possible characters in a threshold range */
+#define NP_THRESHOLDS_CHARS "0123456789.:@~"
+
 char *np_escaped_string (const char *);
 
 void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)));
@@ -56,6 +85,21 @@ int np_warn_if_not_root(void);
  * This function can be used to parse NTP control packet data and performance
  * data strings.
  */
-char *np_extract_value(const char*, const char*);
+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, ',')
+
+
+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();
 
 #endif /* _UTILS_BASE_ */