From 302974149068eeca34e747bed1233d2bb8948a5d Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 1 Nov 2007 12:27:56 +0100 Subject: [PATCH] src/utils_threshold.c: Added creation of a notification. --- src/plugin.c | 5 ++++ src/plugin.h | 2 +- src/utils_threshold.c | 57 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index 84b7e0be..6b17290f 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -717,6 +717,11 @@ int plugin_dispatch_notification (const notification_t *notif) llentry_t *le; /* Possible TODO: Add flap detection here */ + DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; " + "time = %u; host = %s;", + notif->severity, notif->message, + (unsigned int) notif->time, notif->host); + /* Nobody cares for notifications */ if (list_notification == NULL) return (-1); diff --git a/src/plugin.h b/src/plugin.h index f1a985f6..96eb0cb5 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -45,7 +45,7 @@ # define LOG_DEBUG 7 #endif -#define NOTIF_MAX_MSG_LEN 128 +#define NOTIF_MAX_MSG_LEN 256 #define NOTIF_FAILURE 1 #define NOTIF_WARNING 2 diff --git a/src/utils_threshold.c b/src/utils_threshold.c index 91407e0c..1c9ccdd1 100644 --- a/src/utils_threshold.c +++ b/src/utils_threshold.c @@ -480,9 +480,60 @@ int ut_check_threshold (const data_set_t *ds, const value_list_t *vl) for (i = 0; i < ds->ds_num; i++) { if ((th->min > values[i]) || (th->max < values[i])) - WARNING ("ut_check_threshold: ds%i: %lf <= !%lf <= %lf", - i, th->min, values[i], th->max); - } + { + notification_t n; + char *buf; + size_t bufsize; + int status; + + WARNING ("ut_check_threshold: ds[%s]: %lf <= !%lf <= %lf", + ds->ds[i].name, th->min, values[i], th->max); + + buf = n.message; + bufsize = sizeof (n.message); + + status = snprintf (buf, bufsize, "Host %s, plugin %s", + vl->host, vl->plugin); + buf += status; + bufsize -= status; + + if (vl->plugin_instance[0] != '\0') + { + status = snprintf (buf, bufsize, " (instance %s)", + vl->plugin_instance); + buf += status; + bufsize -= status; + } + + status = snprintf (buf, bufsize, " type %s", ds->type); + buf += status; + bufsize -= status; + + if (vl->type_instance[0] != '\0') + { + status = snprintf (buf, bufsize, " (instance %s)", + vl->type_instance); + buf += status; + bufsize -= status; + } + + status = snprintf (buf, bufsize, ": Data source \"%s\" is currently " + "%lf. That is %s the configured threshold of %lf.", + ds->ds[i].name, values[i], + (values[i] < th->min) ? "below" : "above", + (values[i] < th->min) ? th->min : th->max); + buf += status; + bufsize -= status; + + n.severity = NOTIF_FAILURE; + n.time = vl->time; + + strncpy (n.host, vl->host, sizeof (n.host)); + n.host[sizeof (n.host) - 1] = '\0'; + + plugin_dispatch_notification (&n); + } + } /* for (i = 0; i < ds->ds_num; i++) */ sfree (values); -- 2.30.2