From 23128c9c41d00cd2e5e3f529f1792a261affd0a4 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Thu, 25 Feb 2016 21:31:46 +0700 Subject: [PATCH] curl_json: Add ability to set custom plugin name in collected data. --- src/collectd.conf.pod | 5 +++++ src/curl_json.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index fdbe1956..b497e1d4 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1815,6 +1815,11 @@ The following options are valid within B blocks: Use I as the host name when submitting values. Defaults to the global host name setting. +=item B I + +Use I as the plugin name when submitting values. +Defaults to 'curl_json'. + =item B I Sets the plugin instance to I. diff --git a/src/curl_json.c b/src/curl_json.c index 35b11c02..756f24f3 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -82,6 +82,7 @@ typedef struct { struct cj_s /* {{{ */ { char *instance; + char *plugin_name; char *host; char *sock; @@ -396,6 +397,7 @@ static void cj_free(void *arg) /* {{{ */ db->tree = NULL; sfree(db->instance); + sfree(db->plugin_name); sfree(db->host); sfree(db->sock); @@ -672,6 +674,8 @@ static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */ if (strcasecmp("Instance", child->key) == 0) status = cf_util_get_string(child, &db->instance); + else if (strcasecmp("Plugin", child->key) == 0) + status = cf_util_get_string(child, &db->plugin_name); else if (strcasecmp("Host", child->key) == 0) status = cf_util_get_string(child, &db->host); else if (db->url && strcasecmp("User", child->key) == 0) @@ -805,7 +809,8 @@ static void cj_submit_impl(cj_t *db, cj_key_t *key, value_t *value) /* {{{ */ sstrncpy(vl.type_instance, key->instance, sizeof(vl.type_instance)); sstrncpy(vl.host, cj_host(db), sizeof(vl.host)); - sstrncpy(vl.plugin, "curl_json", sizeof(vl.plugin)); + sstrncpy(vl.plugin, (db->plugin_name != NULL) ? db->plugin_name : "curl_json", + sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, key->type, sizeof(vl.type)); -- 2.11.0