summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTon Voon <ton.voon@opsera.com>2010-06-17 10:16:43 +0100
committerTon Voon <ton.voon@opsera.com>2010-06-17 10:16:43 +0100
commit95b190f3dee629b1c1ee2fab5b69c08e511f51b3 (patch)
tree253572d6a2465b287d44f93e7731fc71b4c99e41
parent4b42d5aff4c929ccb7bb7c752d2b25149cee79a5 (diff)
downloadmonitoring-plugins-95b190f3dee629b1c1ee2fab5b69c08e511f51b3.tar.gz
Added skeleton
-rw-r--r--lib/utils_base.c61
-rw-r--r--lib/utils_base.h24
2 files changed, 85 insertions, 0 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c
index 4303e159..c9f0912a 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) {
310 return value; 310 return value;
311} 311}
312 312
313/*
314 * Returns a string to use as a keyname, based on an md5 hash of argv, thus
315 * hopefully a unique key per service/plugin invocation. Use the extra-opts
316 * parse of argv, so that uniqueness in parameters are reflected there.
317 */
318char *np_state_generate_key(const char **argv) {
319 return "Ahash";
320}
321
322/*
323 * Initiatializer for state routines.
324 * Sets variables. Generates filename. Returns np_state_key. die with
325 * UNKNOWN if exception
326 */
327state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_version) {
328 state_key *this_state = NULL;
329
330 this_state = (state_key *) malloc(sizeof(state_key));
331
332 if(this_state==NULL)
333 die(STATE_UNKNOWN, _("Cannot allocate memory for state key"));
334
335 this_state->name=keyname;
336 this_state->plugin_name=plugin_name;
337 this_state->data_version=expected_data_version;
338
339 /* Calculate filename */
340 this_state->_filename="Tobedone";
341
342 return this_state;
343}
344
345/*
346 * Will return NULL if no data is available (first run). If key currently
347 * exists, read data. If state file format version is not expected, return
348 * as if no data. Get state data version number and compares to expected.
349 * If numerically lower, then return as no previous state. die with UNKNOWN
350 * if exceptional error.
351 */
352state_data *np_state_read(state_key *my_state_key) {
353 state_data *this_state_data=NULL;
354 my_state_key->state_data = this_state_data;
355 return this_state_data;
356}
357
358/*
359 * If time=NULL, use current time. Create state file, with state format
360 * version, default text. Writes version, time, and data. Avoid locking
361 * problems - use mv to write and then swap. Possible loss of state data if
362 * two things writing to same key at same time.
363 * Will die with UNKNOWN if errors
364 */
365void np_state_write_string(state_key *my_state_key, time_t data_time, char *data_string) {
366}
367
368/*
369 * Cleanup
370 */
371void np_state_cleanup(state_key *my_state_key) {
372}
373
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 49e40a63..6e1af94a 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -28,6 +28,23 @@ typedef struct thresholds_struct {
28 range *critical; 28 range *critical;
29 } thresholds; 29 } thresholds;
30 30
31#define STATE_FORMAT_VERSION "1"
32
33typedef struct state_data_struct {
34 time_t time;
35 void *data;
36 int length; /* Of binary data */
37 } state_data;
38
39
40typedef struct state_key_struct {
41 char *name;
42 char *plugin_name;
43 int data_version;
44 char *_filename;
45 state_data *state_data;
46 } state_key;
47
31range *parse_range_string (char *); 48range *parse_range_string (char *);
32int _set_thresholds(thresholds **, char *, char *); 49int _set_thresholds(thresholds **, char *, char *);
33void set_thresholds(thresholds **, char *, char *); 50void set_thresholds(thresholds **, char *, char *);
@@ -67,4 +84,11 @@ char *np_extract_value(const char*, const char*, char);
67 */ 84 */
68#define np_extract_ntpvar(l, n) np_extract_value(l, n, ',') 85#define np_extract_ntpvar(l, n) np_extract_value(l, n, ',')
69 86
87
88char *np_state_generate_key(const char **);
89state_key *np_state_init(char *, char *, int);
90state_data *np_state_read(state_key *);
91void np_state_write_string(state_key *, time_t, char *);
92void np_state_cleanup(state_key *);
93
70#endif /* _UTILS_BASE_ */ 94#endif /* _UTILS_BASE_ */