#include "utils_avltree.h"
#include "utils_cache.h"
#include "utils_threshold.h"
+#include "utils_subst.h"
#include "meta_data.h"
#include <assert.h>
* (for purding old entries) */
int interval;
int state;
+ int hits;
/*
* +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
sfree (ce);
} /* void cache_free */
+/* Send out notifications for "missing" values. */
static int uc_send_notification (const char *name)
{
cache_entry_t *ce = NULL;
char *plugin_instance;
char *type;
char *type_instance;
+ threshold_t th;
notification_t n;
+ data_set_t ds;
+ value_list_t vl;
+
name_copy = strdup (name);
if (name_copy == NULL)
{
return (-1);
}
+ memset (&ds, 0, sizeof (ds));
+ memset (&vl, 0, sizeof (vl));
+
+ sstrncpy (vl.host, host, sizeof (vl.host));
+ sstrncpy (vl.plugin, plugin, sizeof (vl.plugin));
+ if (plugin_instance != NULL)
+ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (ds.type, type, sizeof (ds.type));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ if (type_instance != NULL)
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+
/* Copy the associative members */
notification_init (&n, NOTIF_FAILURE, /* host = */ NULL,
host, plugin, plugin_instance, type, type_instance);
sfree (name_copy);
name_copy = host = plugin = plugin_instance = type = type_instance = NULL;
+
pthread_mutex_lock (&cache_lock);
/*
return (-1);
}
- /* Check if the entry has been updated in the meantime */
+ /* Check if the entry has been updated since we marked it as "missing" in
+ * uc_check_timeout() */
if ((n.time - ce->last_update) < (2 * ce->interval))
{
ce->state = STATE_OKAY;
return (-1);
}
- ssnprintf (n.message, sizeof (n.message),
- "%s has not been updated for %i seconds.", name,
- (int) (n.time - ce->last_update));
+ /* if the associated threshold has a missing message, then use custom
+ * message. FIXME: we do a threshold_search here and in uc_check_timeout
+ * (calling ut_check_interesting, but we really need to do this once */
+ if ( !ut_search_threshold(&vl, &th) &&
+ (th.missing_message != NULL) )
+ {
+ char msg[NOTIF_MAX_MSG_LEN];
+ char temp[NOTIF_MAX_MSG_LEN];
+
+ sstrncpy (msg, th.missing_message, sizeof (msg));
+ (void) ut_build_message (msg, NOTIF_MAX_MSG_LEN, th.missing_message,
+ &ds, 0, &vl, ce->values_gauge,
+ &n, &th);
+
+#define REPLACE_FIELD(t,v) \
+ if (subst_string (temp, sizeof (temp), msg, t, v) != NULL) \
+ sstrncpy (msg, temp, sizeof (msg));
+
+ char itoa_temp[NOTIF_MAX_MSG_LEN];
+#define ITOA(string,i) \
+ memset(string,0x00,sizeof(string)); \
+ snprintf(string, sizeof(string), "%i", i);
+
+ ITOA(itoa_temp, (int)(n.time - ce->last_update))
+ REPLACE_FIELD("%{missing}", itoa_temp)
+
+ (void) ssnprintf (n.message, sizeof (n.message),
+ "%s", msg);
+ }
+ else
+ {
+ ssnprintf (n.message, sizeof (n.message),
+ "%s has not been updated for %i seconds.", name,
+ (int) (n.time - ce->last_update));
+ }
pthread_mutex_unlock (&cache_lock);
while (c_avl_iterator_next (iter, (void *) &key, (void *) &ce) == 0)
{
/* If entry has not been updated, add to `keys' array */
- if ((now - ce->last_update) >= (2 * ce->interval))
+ if ((now - ce->last_update) >= (timeout_g * ce->interval))
{
char **tmp;
return (uc_get_history_by_name (name, ret_history, num_steps, num_ds));
} /* int uc_get_history */
+int uc_get_hits (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) != 0)
+ {
+ ERROR ("uc_get_state: FORMAT_VL failed.");
+ return (STATE_ERROR);
+ }
+
+ pthread_mutex_lock (&cache_lock);
+
+ if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
+ {
+ assert (ce != NULL);
+ ret = ce->hits;
+ }
+
+ pthread_mutex_unlock (&cache_lock);
+
+ return (ret);
+} /* int uc_get_hits */
+
+int uc_set_hits (const data_set_t *ds, const value_list_t *vl, int hits)
+{
+ char name[6 * DATA_MAX_NAME_LEN];
+ cache_entry_t *ce = NULL;
+ int ret = -1;
+
+ if (FORMAT_VL (name, sizeof (name), vl) != 0)
+ {
+ ERROR ("uc_get_state: FORMAT_VL failed.");
+ return (STATE_ERROR);
+ }
+
+ pthread_mutex_lock (&cache_lock);
+
+ if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
+ {
+ assert (ce != NULL);
+ ret = ce->hits;
+ ce->hits = hits;
+ }
+
+ pthread_mutex_unlock (&cache_lock);
+
+ return (ret);
+} /* int uc_set_hits */
+
+int uc_inc_hits (const data_set_t *ds, const value_list_t *vl, int step)
+{
+ char name[6 * DATA_MAX_NAME_LEN];
+ cache_entry_t *ce = NULL;
+ int ret = -1;
+
+ if (FORMAT_VL (name, sizeof (name), vl) != 0)
+ {
+ ERROR ("uc_get_state: FORMAT_VL failed.");
+ return (STATE_ERROR);
+ }
+
+ pthread_mutex_lock (&cache_lock);
+
+ if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
+ {
+ assert (ce != NULL);
+ ret = ce->hits;
+ ce->hits = ret + step;
+ }
+
+ pthread_mutex_unlock (&cache_lock);
+
+ return (ret);
+} /* int uc_inc_hits */
+
/*
* Meta data interface
*/
if (ce->meta == NULL)
ce->meta = meta_data_create ();
+ if (ce->meta == NULL)
+ pthread_mutex_unlock (&cache_lock);
+
return (ce->meta);
} /* }}} meta_data_t *uc_get_meta */