[nagiosplug] Added skeleton

"Ton Voon" <[email protected]>
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
 Module: nagiosplug
 Branch: ton/state
 Commit: 95b190f3dee629b1c1ee2fab5b69c08e511f51b3
 Author: Ton Voon <[email protected]>
   Date: Thu Jun 17 10:16:43 2010 +0100
    URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=95b190f

Added skeleton

---

 lib/utils_base.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/utils_base.h |   24 +++++++++++++++++++++
 2 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/lib/utils_base.c b/lib/utils_base.c
index 4303e15..c9f0912 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -310,3 +310,64 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
 	return value;
 }
 
+/*
+ * Returns a string to use as a keyname, based on an md5 hash of argv, thus
+ * hopefully a unique key per service/plugin invocation. Use the extra-opts
+ * parse of argv, so that uniqueness in parameters are reflected there.
+ */
+char *np_state_generate_key(const char **argv) {
+	return "Ahash";
+}
+
+/*
+ * Initiatializer for state routines.
+ * Sets variables. Generates filename. Returns np_state_key. die with
+ * UNKNOWN if exception
+ */
+state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_version) {
+	state_key *this_state = NULL;
+
+	this_state = (state_key *) malloc(sizeof(state_key));
+	
+	if(this_state==NULL)
+		die(STATE_UNKNOWN, _("Cannot allocate memory for state key"));
+
+	this_state->name=keyname;
+	this_state->plugin_name=plugin_name;
+	this_state->data_version=expected_data_version;
+
+	/* Calculate filename */
+	this_state->_filename="Tobedone";
+
+	return this_state;
+}
+
+/*
+ * Will return NULL if no data is available (first run). If key currently
+ * exists, read data. If state file format version is not expected, return
+ * as if no data. Get state data version number and compares to expected.
+ * If numerically lower, then return as no previous state. die with UNKNOWN
+ * if exceptional error.
+ */
+state_data *np_state_read(state_key *my_state_key) {
+	state_data *this_state_data=NULL;
+	my_state_key->state_data = this_state_data;
+	return this_state_data;
+}
+
+/*
+ * If time=NULL, use current time. Create state file, with state format 
+ * version, default text. Writes version, time, and data. Avoid locking 
+ * problems - use mv to write and then swap. Possible loss of state data if 
+ * two things writing to same key at same time. 
+ * Will die with UNKNOWN if errors
+ */
+void np_state_write_string(state_key *my_state_key, time_t data_time, char *data_string) {
+}
+
+/*
+ * Cleanup
+ */
+void np_state_cleanup(state_key *my_state_key) {
+}
+
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 49e40a6..6e1af94 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -28,6 +28,23 @@ typedef struct thresholds_struct {
 	range	*critical;
 	} thresholds;
 
+#define 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;
+
 range *parse_range_string (char *);
 int _set_thresholds(thresholds **, char *, char *);
 void set_thresholds(thresholds **, char *, char *);
@@ -67,4 +84,11 @@ char *np_extract_value(const char*, const char*, char);
  */
 #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',')
 
+
+char *np_state_generate_key(const char **);
+state_key *np_state_init(char *, char *, int);
+state_data *np_state_read(state_key *);
+void np_state_write_string(state_key *, time_t, char *);
+void np_state_cleanup(state_key *);
+
 #endif /* _UTILS_BASE_ */


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.