X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_cache.c;h=2e33ab08deb3f23d68b6b8ce26487779f83f9242;hb=ba4b24567e4dc5a5e3182a187912aaa3e8d10b54;hp=69ea864b99dbf1ddb2f35f8e82ae4078b0c8e9e6;hpb=58217009d8028d2e5d654c8b76562f59e28c9c30;p=collectd.git diff --git a/src/utils_cache.c b/src/utils_cache.c index 69ea864b..2e33ab08 100644 --- a/src/utils_cache.c +++ b/src/utils_cache.c @@ -25,6 +25,7 @@ #include "utils_avltree.h" #include "utils_cache.h" #include "utils_threshold.h" +#include "utils_subst.h" #include "meta_data.h" #include @@ -131,9 +132,13 @@ static int uc_send_notification (const char *name) 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) { @@ -150,6 +155,18 @@ static int uc_send_notification (const char *name) 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); @@ -157,6 +174,7 @@ static int uc_send_notification (const char *name) sfree (name_copy); name_copy = host = plugin = plugin_instance = type = type_instance = NULL; + pthread_mutex_lock (&cache_lock); /* @@ -183,9 +201,41 @@ static int uc_send_notification (const char *name) 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);