From 75f6e826ccd930ac9834c55a208be2a194e38911 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Wed, 24 Feb 2016 20:20:27 +0700 Subject: [PATCH] curl_xml: Add ability to set custom plugin name in collected data. --- src/curl_xml.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/curl_xml.c b/src/curl_xml.c index e83de73e..074a2d19 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -71,6 +71,7 @@ typedef struct cx_namespace_s cx_namespace_t; struct cx_s /* {{{ */ { char *instance; + char *plugin_name; char *host; char *url; @@ -188,6 +189,7 @@ static void cx_free(void *arg) /* {{{ */ sfree(db->buffer); sfree(db->instance); + sfree(db->plugin_name); sfree(db->host); sfree(db->url); @@ -208,7 +210,7 @@ static void cx_free(void *arg) /* {{{ */ sfree(db); } /* }}} void cx_free */ -static const char *cx_host(cx_t *db) /* {{{ */ +static const char *cx_host(const cx_t *db) /* {{{ */ { if (db->host == NULL) return hostname_g; @@ -464,8 +466,8 @@ static int cx_handle_instance_xpath(xmlXPathContextPtr xpath_ctx, /* {{{ */ return 0; } /* }}} int cx_handle_instance_xpath */ -static int cx_handle_base_xpath(char const *plugin_instance, /* {{{ */ - char const *host, xmlXPathContextPtr xpath_ctx, +static int cx_handle_base_xpath(const cx_t *db, /* {{{ */ + xmlXPathContextPtr xpath_ctx, const data_set_t *ds, char *base_xpath, cx_xpath_t *xpath) { int total_nodes; @@ -505,10 +507,11 @@ static int cx_handle_base_xpath(char const *plugin_instance, /* {{{ */ /* set the values for the value_list */ vl.values_len = ds->ds_num; sstrncpy(vl.type, xpath->type, sizeof(vl.type)); - sstrncpy(vl.plugin, "curl_xml", sizeof(vl.plugin)); - sstrncpy(vl.host, host, sizeof(vl.host)); - if (plugin_instance != NULL) - sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); + sstrncpy(vl.plugin, (db->plugin_name != NULL) ? db->plugin_name : "curl_xml", + sizeof(vl.plugin)); + sstrncpy(vl.host, cx_host(db), sizeof(vl.host)); + if (db->instance != NULL) + sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance)); for (int i = 0; i < total_nodes; i++) { int status; @@ -545,8 +548,7 @@ static int cx_handle_parsed_xml(xmlDocPtr doc, /* {{{ */ ds = plugin_get_ds(xpath->type); if ((cx_check_type(ds, xpath) == 0) && - (cx_handle_base_xpath(db->instance, cx_host(db), xpath_ctx, ds, le->key, - xpath) == 0)) + (cx_handle_base_xpath(db, xpath_ctx, ds, le->key, xpath) == 0)) status = 0; /* we got atleast one success */ le = le->next; @@ -908,6 +910,8 @@ static int cx_config_add_url(oconfig_item_t *ci) /* {{{ */ if (strcasecmp("Instance", child->key) == 0) status = cf_util_get_string(child, &db->instance); + else if (strcasecmp("PluginName", 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 (strcasecmp("User", child->key) == 0) -- 2.11.0