Copy MetaData to Riemann events
authorRomain Tartière <romain@blogreen.org>
Fri, 17 May 2019 18:43:25 +0000 (08:43 -1000)
committerRomain Tartière <romain@blogreen.org>
Fri, 17 May 2019 18:54:19 +0000 (08:54 -1000)
Make it possible to capture information using filters in collectd and
use this information in Riemann for deciding what to do with the event.

ChangeLog: write_riemann plugin: MetaData is copied to Riemann events

src/write_riemann.c

index 62ddc67..8056993 100644 (file)
@@ -392,6 +392,23 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */
                       RIEMANN_EVENT_FIELD_NONE);
   }
 
                       RIEMANN_EVENT_FIELD_NONE);
   }
 
+  if (vl->meta) {
+    char **toc;
+    int n = meta_data_toc(vl->meta, &toc);
+
+    for (int i = 0; i < n; i++) {
+      char *key = toc[i];
+      char *value;
+
+      if (0 == meta_data_as_string(vl->meta, key, &value)) {
+        riemann_event_string_attribute_add(event, key, value);
+        free(value);
+      }
+    }
+
+    free(toc);
+  }
+
   DEBUG("write_riemann plugin: Successfully created message for metric: "
         "host = \"%s\", service = \"%s\"",
         event->host, event->service);
   DEBUG("write_riemann plugin: Successfully created message for metric: "
         "host = \"%s\", service = \"%s\"",
         event->host, event->service);