diff --git a/src/plugin.c b/src/plugin.c
index 248e583e4f6c3f3c9c442df1dea7461356b81ab4..6b17290f32dbe08a9a4bb6406cbc8fef35efdd01 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
#include "plugin.h"
#include "configfile.h"
#include "utils_llist.h"
+#include "utils_cache.h"
+#include "utils_threshold.h"
/*
* Private structures
static llist_t *list_shutdown;
static llist_t *list_data_set;
static llist_t *list_log;
+static llist_t *list_notification;
static char *plugindir = NULL;
const char *error = lt_dlerror ();
ERROR ("lt_dlopen failed: %s", error);
+ fprintf (stderr, "lt_dlopen failed: %s\n", error);
return (1);
}
ret = 0;
break;
}
+ else
+ {
+ fprintf (stderr, "Unable to load plugin %s.\n", type);
+ }
}
closedir (dh);
return (register_callback (&list_log, name, (void *) callback));
} /* int plugin_register_log */
+int plugin_register_notification (const char *name,
+ int (*callback) (const notification_t *notif))
+{
+ return (register_callback (&list_log, name, (void *) callback));
+} /* int plugin_register_log */
+
int plugin_unregister_config (const char *name)
{
cf_unregister (name);
return (plugin_unregister (list_log, name));
}
+int plugin_unregister_notification (const char *name)
+{
+ return (plugin_unregister (list_notification, name));
+}
+
void plugin_init_all (void)
{
int (*callback) (void);
start_threads ((num > 0) ? num : 5);
}
+ /* Init the value cache */
+ uc_init ();
+
if (list_init == NULL)
return;
ds = (data_set_t *) le->value;
- DEBUG ("plugin: plugin_dispatch_values: time = %u; host = %s; "
- "plugin = %s; plugin_instance = %s; type = %s; "
- "type_instance = %s;",
- (unsigned int) vl->time, vl->host,
+ DEBUG ("plugin: plugin_dispatch_values: time = %u; interval = %i; "
+ "host = %s; "
+ "plugin = %s; plugin_instance = %s; "
+ "type = %s; type_instance = %s;",
+ (unsigned int) vl->time, vl->interval,
+ vl->host,
vl->plugin, vl->plugin_instance,
ds->type, vl->type_instance);
escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
escape_slashes (vl->type_instance, sizeof (vl->type_instance));
+ /* Update the value cache */
+ uc_update (ds, vl);
+ ut_check_threshold (ds, vl);
+
le = llist_head (list_write);
while (le != NULL)
{
return (0);
} /* int plugin_dispatch_values */
+int plugin_dispatch_notification (const notification_t *notif)
+{
+ int (*callback) (const notification_t *);
+ 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);
+
+ le = llist_head (list_notification);
+ while (le != NULL)
+ {
+ callback = (int (*) (const notification_t *)) le->value;
+ (*callback) (notif);
+
+ le = le->next;
+ }
+
+ return (0);
+} /* int plugin_dispatch_notification */
+
void plugin_log (int level, const char *format, ...)
{
char msg[512];