diff --git a/src/plugin.c b/src/plugin.c
index 495e1693b91827bd9f50fc6adf5b5ad15367b308..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);
- DEBUG ("lt_dlopen failed: %s", error);
+ fprintf (stderr, "lt_dlopen failed: %s\n", error);
return (1);
}
rf->wait_time = 86400;
NOTICE ("read-function of plugin `%s' "
- "failed. Will syspend it for %i "
+ "failed. Will suspend it for %i "
"seconds.", le->key, rf->wait_left);
}
else
ret = 0;
break;
}
+ else
+ {
+ fprintf (stderr, "Unable to load plugin %s.\n", type);
+ }
}
closedir (dh);
return (0);
} /* int plugin_register_config */
+int plugin_register_complex_config (const char *type,
+ int (*callback) (oconfig_item_t *))
+{
+ return (cf_register_complex (type, callback));
+} /* int plugin_register_complex_config */
+
int plugin_register_init (const char *name,
int (*callback) (void))
{
int plugin_register_data_set (const data_set_t *ds)
{
- return (register_callback (&list_data_set, ds->type, (void *) ds));
+ data_set_t *ds_copy;
+ int i;
+
+ if ((list_data_set != NULL)
+ && (llist_search (list_data_set, ds->type) != NULL))
+ {
+ NOTICE ("Replacing DS `%s' with another version.", ds->type);
+ plugin_unregister_data_set (ds->type);
+ }
+
+ ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
+ if (ds_copy == NULL)
+ return (-1);
+ memcpy(ds_copy, ds, sizeof (data_set_t));
+
+ ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
+ * ds->ds_num);
+ if (ds_copy->ds == NULL)
+ {
+ free (ds_copy);
+ return (-1);
+ }
+
+ for (i = 0; i < ds->ds_num; i++)
+ memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
+
+ return (register_callback (&list_data_set, ds->type, (void *) ds_copy));
} /* int plugin_register_data_set */
int plugin_register_log (char *name,
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 (0);
} /* int plugin_unregister_config */
+int plugin_unregister_complex_config (const char *name)
+{
+ cf_unregister_complex (name);
+ return (0);
+} /* int plugin_unregister_complex_config */
+
int plugin_unregister_init (const char *name)
{
return (plugin_unregister (list_init, name));
int plugin_unregister_data_set (const char *name)
{
- return (plugin_unregister (list_data_set, name));
-}
+ llentry_t *e;
+ data_set_t *ds;
+
+ if (list_data_set == NULL)
+ return (-1);
+
+ e = llist_search (list_data_set, name);
+
+ if (e == NULL)
+ return (-1);
+
+ llist_remove (list_data_set, e);
+ ds = (data_set_t *) e->value;
+ llentry_destroy (e);
+
+ sfree (ds->ds);
+ sfree (ds);
+
+ return (0);
+} /* int plugin_unregister_data_set */
int plugin_unregister_log (const char *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;
while (le != NULL)
{
callback = (int (*) (void)) le->value;
- (*callback) ();
+ /* Advance the pointer before calling the callback allows
+ * shutdown functions to unregister themselves. If done the
+ * other way around the memory `le' points to will be freed
+ * after callback returns. */
le = le->next;
+
+ (*callback) ();
}
} /* void plugin_shutdown_all */
-int plugin_dispatch_values (const char *name, const value_list_t *vl)
+int plugin_dispatch_values (const char *name, value_list_t *vl)
{
int (*callback) (const data_set_t *, const value_list_t *);
data_set_t *ds;
llentry_t *le;
- if (list_write == NULL)
+ if ((list_write == NULL) || (list_data_set == NULL))
return (-1);
le = llist_search (list_data_set, name);
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);
+#if COLLECT_DEBUG
+ assert (ds->ds_num == vl->values_len);
+#else
+ if (ds->ds_num != vl->values_len)
+ {
+ ERROR ("plugin: ds->type = %s: (ds->ds_num = %i) != "
+ "(vl->values_len = %i)",
+ ds->type, ds->ds_num, vl->values_len);
+ return (-1);
+ }
+#endif
+
+ escape_slashes (vl->host, sizeof (vl->host));
+ escape_slashes (vl->plugin, sizeof (vl->plugin));
+ 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, ...)
{