Merge branch 'collectd-4.5'
[collectd.git] / src / plugin.c
index 4d503f7..4ad7366 100644 (file)
@@ -36,6 +36,7 @@
 #include "utils_llist.h"
 #include "utils_cache.h"
 #include "utils_threshold.h"
+#include "filter_chain.h"
 
 /*
  * Private structures
@@ -677,6 +678,73 @@ void plugin_read_all (void)
        pthread_mutex_unlock (&read_lock);
 } /* void plugin_read_all */
 
+int plugin_write (const char *plugin, /* {{{ */
+               const data_set_t *ds, const value_list_t *vl)
+{
+  int (*callback) (const data_set_t *ds, const value_list_t *vl);
+  llentry_t *le;
+  int status;
+
+  if (vl == NULL)
+    return (EINVAL);
+
+  if (list_write == NULL)
+    return (ENOENT);
+
+  if (ds == NULL)
+  {
+    ds = plugin_get_ds (vl->type);
+    if (ds == NULL)
+    {
+      ERROR ("plugin_write: Unable to lookup type `%s'.", vl->type);
+      return (ENOENT);
+    }
+  }
+
+  if (plugin == NULL)
+  {
+    int success = 0;
+    int failure = 0;
+
+    le = llist_head (list_write);
+    while (le != NULL)
+    {
+      callback = le->value;
+      status = (*callback) (ds, vl);
+      if (status != 0)
+        failure++;
+      else
+        success++;
+
+      le = le->next;
+    }
+
+    if ((success == 0) && (failure != 0))
+      status = -1;
+    else
+      status = 0;
+  }
+  else /* plugin != NULL */
+  {
+    le = llist_head (list_write);
+    while (le != NULL)
+    {
+      if (strcasecmp (plugin, le->key) == 0)
+        break;
+
+      le = le->next;
+    }
+
+    if (le == NULL)
+      return (ENOENT);
+
+    callback = le->value;
+    status = (*callback) (ds, vl);
+  }
+
+  return (status);
+} /* }}} int plugin_write */
+
 int plugin_flush (const char *plugin, int timeout, const char *identifier)
 {
   int (*callback) (int timeout, const char *identifier);
@@ -733,9 +801,6 @@ int plugin_dispatch_values (value_list_t *vl)
        static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
 
        data_set_t *ds;
-       llentry_t *le;
-
-       int filter = 0;
 
        if ((vl == NULL) || (*vl->type == '\0')) {
                ERROR ("plugin_dispatch_values: Invalid value list.");
@@ -798,39 +863,10 @@ int plugin_dispatch_values (value_list_t *vl)
        escape_slashes (vl->type, sizeof (vl->type));
        escape_slashes (vl->type_instance, sizeof (vl->type_instance));
 
-       le = llist_head (list_filter);
-       while (le != NULL)
-       {
-               int (*filter_callback) (const data_set_t *, value_list_t *) =
-                               (int (*) (const data_set_t *, value_list_t *)) le->value;
-
-               filter |= (*filter_callback) (ds, vl);
-
-               if (filter == FILTER_IGNORE)
-                       return (-1);
-
-               le = le->next;
-       }
-
        /* Update the value cache */
        uc_update (ds, vl);
 
-       if ((filter & FILTER_NOTHRESHOLD_CHECK) == 0)
-               ut_check_threshold (ds, vl);
-
-       if (filter & FILTER_NOWRITE)
-               return (0);
-
-       le = llist_head (list_write);
-       while (le != NULL)
-       {
-               int (*write_callback) (const data_set_t *, const value_list_t *) =
-                               (int (*) (const data_set_t *, const value_list_t *)) le->value;
-
-               (*write_callback) (ds, vl);
-
-               le = le->next;
-       }
+       fc_process (ds, vl);
 
        return (0);
 } /* int plugin_dispatch_values */
@@ -935,8 +971,8 @@ static int plugin_notification_meta_add (notification_t *n,
   {
     case NM_TYPE_STRING:
     {
-      meta->value_string = strdup ((const char *) value);
-      if (meta->value_string == NULL)
+      meta->nm_value.nm_string = strdup ((const char *) value);
+      if (meta->nm_value.nm_string == NULL)
       {
         ERROR ("plugin_notification_meta_add: strdup failed.");
         sfree (meta);
@@ -946,22 +982,22 @@ static int plugin_notification_meta_add (notification_t *n,
     }
     case NM_TYPE_SIGNED_INT:
     {
-      meta->value_signed_int = *((int64_t *) value);
+      meta->nm_value.nm_signed_int = *((int64_t *) value);
       break;
     }
     case NM_TYPE_UNSIGNED_INT:
     {
-      meta->value_unsigned_int = *((uint64_t *) value);
+      meta->nm_value.nm_unsigned_int = *((uint64_t *) value);
       break;
     }
     case NM_TYPE_DOUBLE:
     {
-      meta->value_double = *((double *) value);
+      meta->nm_value.nm_double = *((double *) value);
       break;
     }
     case NM_TYPE_BOOLEAN:
     {
-      meta->value_boolean = *((bool *) value);
+      meta->nm_value.nm_boolean = *((bool *) value);
       break;
     }
     default:
@@ -1034,19 +1070,19 @@ int plugin_notification_meta_copy (notification_t *dst,
   {
     if (meta->type == NM_TYPE_STRING)
       plugin_notification_meta_add_string (dst, meta->name,
-          meta->value_string);
+          meta->nm_value.nm_string);
     else if (meta->type == NM_TYPE_SIGNED_INT)
       plugin_notification_meta_add_signed_int (dst, meta->name,
-          meta->value_signed_int);
+          meta->nm_value.nm_signed_int);
     else if (meta->type == NM_TYPE_UNSIGNED_INT)
       plugin_notification_meta_add_unsigned_int (dst, meta->name,
-          meta->value_unsigned_int);
+          meta->nm_value.nm_unsigned_int);
     else if (meta->type == NM_TYPE_DOUBLE)
       plugin_notification_meta_add_double (dst, meta->name,
-          meta->value_double);
+          meta->nm_value.nm_double);
     else if (meta->type == NM_TYPE_BOOLEAN)
       plugin_notification_meta_add_boolean (dst, meta->name,
-          meta->value_boolean);
+          meta->nm_value.nm_boolean);
   }
 
   return (0);
@@ -1071,8 +1107,8 @@ int plugin_notification_meta_free (notification_t *n)
 
     if (this->type == NM_TYPE_STRING)
     {
-      free ((char *)this->value_string);
-      this->value_string = NULL;
+      free ((char *)this->nm_value.nm_string);
+      this->nm_value.nm_string = NULL;
     }
     sfree (this);