]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
write_sensu: add the IncludeSource option 3398/head
authorMärt Bakhoff <mbakhoff@perforce.com>
Tue, 3 Mar 2020 19:28:08 +0000 (21:28 +0200)
committerMärt Bakhoff <mbakhoff@perforce.com>
Fri, 13 Mar 2020 09:00:47 +0000 (11:00 +0200)
src/collectd.conf.in
src/collectd.conf.pod
src/write_sensu.c

index c09a0c1f52808e397e59f401885684cd2539d51f..6292ddc2337a57f5c5bccd0e5d6492adf6b6c53e 100644 (file)
 #              Port 3030
 #              StoreRates true
 #              AlwaysAppendDS false
+#              IncludeSource false
 #              Notifications true
 #              Metrics true
 #              EventServicePrefix ""
index 09ea15fc2b2e3c3cb0ec5d84999d9f98a8a2adf1..7fa48ee5928007526f0d40fa2cd8429d62ebd69e 100644 (file)
@@ -11316,10 +11316,6 @@ The I<write_sensu plugin> will send values to I<Sensu>, a powerful stream
 aggregation and monitoring system. The plugin sends I<JSON> encoded data to
 a local I<Sensu> client using a TCP socket.
 
-At the moment, the I<write_sensu plugin> does not send over a collectd_host
-parameter so it is not possible to use one collectd instance as a gateway for
-others. Each collectd host must pair with one I<Sensu> client.
-
 Synopsis:
 
  <Plugin "write_sensu">
@@ -11328,6 +11324,7 @@ Synopsis:
      Port "3030"
      StoreRates true
      AlwaysAppendDS false
+     IncludeSource false
      MetricHandler "influx"
      MetricHandler "default"
      NotificationHandler "flapjack"
@@ -11418,6 +11415,15 @@ I<Sensu>.
 Consider the two given strings to be the key and value of an additional
 attribute for each metric being sent out to I<Sensu>.
 
+=item B<IncludeSource> B<false>|B<true>
+
+If set to B<true>, then the source host of the metrics/notification is passed
+on to sensu using the source attribute. This may register the host as a proxy
+client in sensu.
+
+If set to B<false> (the default), then the hostname is discarded, making it appear
+as if the event originated from the connected sensu agent.
+
 =back
 
 =head2 Plugin C<write_stackdriver>
index 7d08fb5f6eaa311aa56d337bacf27ff232fa3bc0..03e633be408e8525f71f2a4529a025db672d9a67 100644 (file)
@@ -111,6 +111,7 @@ struct sensu_host {
   bool metrics;
   bool store_rates;
   bool always_append_ds;
+  bool include_source;
   char *separator;
   char *node;
   char *service;
@@ -371,6 +372,16 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */
     }
   }
 
+  if (host->include_source) {
+    res = my_asprintf(&temp_str, "%s, \"source\": \"%s\"", ret_str, vl->host);
+    free(ret_str);
+    if (res == -1) {
+      ERROR("write_sensu plugin: Unable to alloc memory");
+      return NULL;
+    }
+    ret_str = temp_str;
+  }
+
   // incorporate the plugin name information
   res = my_asprintf(&temp_str, "%s, \"collectd_plugin\": \"%s\"", ret_str,
                     vl->plugin);
@@ -697,6 +708,16 @@ static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */
   }
   ret_str = temp_str;
 
+  if (host->include_source) {
+    res = my_asprintf(&temp_str, "%s, \"source\": \"%s\"", ret_str, n->host);
+    free(ret_str);
+    if (res == -1) {
+      ERROR("write_sensu plugin: Unable to alloc memory");
+      return NULL;
+    }
+    ret_str = temp_str;
+  }
+
   char *handlers_str =
       build_json_str_list("handlers", &(host->notification_handlers));
   if (handlers_str == NULL) {
@@ -1022,6 +1043,7 @@ static int sensu_config_node(oconfig_item_t *ci) /* {{{ */
   host->metrics = false;
   host->store_rates = true;
   host->always_append_ds = false;
+  host->include_source = false;
   host->metric_handlers.nb_strs = 0;
   host->metric_handlers.strs = NULL;
   host->notification_handlers.nb_strs = 0;
@@ -1094,6 +1116,10 @@ static int sensu_config_node(oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_boolean(child, &host->always_append_ds);
       if (status != 0)
         break;
+    } else if (strcasecmp("IncludeSource", child->key) == 0) {
+      status = cf_util_get_boolean(child, &host->include_source);
+      if (status != 0)
+        break;
     } else {
       WARNING("write_sensu plugin: ignoring unknown config "
               "option: \"%s\"",