summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d46f48f)
raw | patch | inline | side by side (parent: d46f48f)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 20 Dec 2007 21:37:39 +0000 (22:37 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 20 Dec 2007 21:37:39 +0000 (22:37 +0100) |
This is most likely very buggy. The intention is that this is used in the
threshold module to decide wether or not so send a notification, i. e. if the
problem existed before or not.
threshold module to decide wether or not so send a notification, i. e. if the
problem existed before or not.
src/utils_cache.c | patch | blob | history | |
src/utils_cache.h | patch | blob | history |
diff --git a/src/utils_cache.c b/src/utils_cache.c
index b936ace6fb1650dd9067b0a49b7f11740c831de1..560365b75a1dd079b9036f5103d24e522a83fc41 100644 (file)
--- a/src/utils_cache.c
+++ b/src/utils_cache.c
#include "common.h"
#include "plugin.h"
#include "utils_avltree.h"
+#include "utils_cache.h"
#include "utils_threshold.h"
#include <assert.h>
/* Interval in which the data is collected
* (for purding old entries) */
int interval;
+ int state;
} cache_entry_t;
static avl_tree_t *cache_tree = NULL;
/* Check if the entry has been updated in the meantime */
if ((n.time - ce->last_update) < (2 * ce->interval))
{
+ ce->state = STATE_OKAY;
pthread_mutex_unlock (&cache_lock);
sfree (name_copy);
return (-1);
* will send out notifications. There's nothing else to do here.
*/
DEBUG ("uc_check_timeout: %s is missing and ``interesting''", keys[i]);
+ ce->state = STATE_ERROR;
}
} /* for (keys[i]) */
/* TODO: Implement a `real' okay notification. Watch out for locking
* issues, though! */
NOTICE ("uc_insert: Okay notification for %s", name);
+ ce->state = STATE_OKAY;
}
for (i = 0; i < ds->ds_num; i++)
ce->last_time = vl->time;
ce->last_update = time (NULL);
ce->interval = vl->interval;
+ ce->state = STATE_OKAY;
if (avl_insert (cache_tree, key, ce) != 0)
{
return (ret);
} /* gauge_t *uc_get_rate */
+int uc_get_state (const data_set_t *ds, const value_list_t *vl)
+{
+ char name[6 * DATA_MAX_NAME_LEN];
+ cache_entry_t *ce = NULL;
+ int ret = STATE_ERROR;
+
+ if (FORMAT_VL (name, sizeof (name), vl, ds) != 0)
+ {
+ ERROR ("uc_get_state: FORMAT_VL failed.");
+ return (STATE_ERROR);
+ }
+
+ pthread_mutex_lock (&cache_lock);
+
+ if (avl_get (cache_tree, name, (void *) &ce) == 0)
+ {
+ assert (ce != NULL);
+ ret = ce->state;
+ }
+
+ pthread_mutex_unlock (&cache_lock);
+
+ return (ret);
+} /* int uc_get_state */
+
+int uc_set_state (const data_set_t *ds, const value_list_t *vl, int state)
+{
+ char name[6 * DATA_MAX_NAME_LEN];
+ cache_entry_t *ce = NULL;
+ int ret = -1;
+
+ if (state < STATE_OKAY)
+ state = STATE_OKAY;
+ if (state > STATE_ERROR)
+ state = STATE_ERROR;
+
+ if (FORMAT_VL (name, sizeof (name), vl, ds) != 0)
+ {
+ ERROR ("uc_get_state: FORMAT_VL failed.");
+ return (STATE_ERROR);
+ }
+
+ pthread_mutex_lock (&cache_lock);
+
+ if (avl_get (cache_tree, name, (void *) &ce) == 0)
+ {
+ assert (ce != NULL);
+ ret = ce->state;
+ ce->state = state;
+ }
+
+ pthread_mutex_unlock (&cache_lock);
+
+ return (ret);
+} /* int uc_set_state */
/* vim: set sw=2 ts=8 sts=2 tw=78 : */
diff --git a/src/utils_cache.h b/src/utils_cache.h
index 2983d9ac29a9cc650280faf9dca95f973531920b..d6a56ab4659a2e7a5205f2ac0f1243537975f59b 100644 (file)
--- a/src/utils_cache.h
+++ b/src/utils_cache.h
#include "plugin.h"
+#define STATE_OKAY 0
+#define STATE_WARNING 1
+#define STATE_ERROR 2
+
int uc_init (void);
int uc_check_timeout (void);
int uc_update (const data_set_t *ds, const value_list_t *vl);
gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl);
+int uc_get_state (const data_set_t *ds, const value_list_t *vl);
+int uc_set_state (const data_set_t *ds, const value_list_t *vl, int state);
+
+/* vim: set shiftwidth=2 softtabstop=2 tabstop=8 : */
#endif /* !UTILS_CACHE_H */