X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fmemcachec.c;h=eefcfb73c1643d16bed6c4cf5a61aa608d7911e4;hp=c2147fd51b1f98025d26ec64bd34195495834828;hb=48efd3deb4c9139fd060ff3d289896e9031bcc7c;hpb=1ecde57a53fc7c50e6b0139ad745b868413d420c diff --git a/src/memcachec.c b/src/memcachec.c index c2147fd5..eefcfb73 100644 --- a/src/memcachec.c +++ b/src/memcachec.c @@ -23,9 +23,9 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" -#include "utils_match.h" +#include "utils/common/common.h" +#include "utils/match/match.h" #include @@ -51,6 +51,7 @@ struct web_page_s; typedef struct web_page_s web_page_t; struct web_page_s /* {{{ */ { + char *plugin_name; char *instance; char *server; @@ -67,7 +68,7 @@ struct web_page_s /* {{{ */ /* * Global variables; */ -static web_page_t *pages_g = NULL; +static web_page_t *pages_g; /* * Private functions @@ -94,6 +95,7 @@ static void cmc_web_page_free(web_page_t *wp) /* {{{ */ memcached_free(wp->memc); wp->memc = NULL; + sfree(wp->plugin_name); sfree(wp->instance); sfree(wp->server); sfree(wp->key); @@ -121,21 +123,6 @@ static int cmc_page_init_memc(web_page_t *wp) /* {{{ */ return 0; } /* }}} int cmc_page_init_memc */ -static int cmc_config_add_string(const char *name, char **dest, /* {{{ */ - oconfig_item_t *ci) { - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { - WARNING("memcachec plugin: `%s' needs exactly one string argument.", name); - return -1; - } - - sfree(*dest); - *dest = strdup(ci->values[0].value.string); - if (*dest == NULL) - return -1; - - return 0; -} /* }}} int cmc_config_add_string */ - static int cmc_config_add_match_dstype(int *dstype_ret, /* {{{ */ oconfig_item_t *ci) { int dstype; @@ -202,16 +189,15 @@ static int cmc_config_add_match(web_page_t *page, /* {{{ */ oconfig_item_t *child = ci->children + i; if (strcasecmp("Regex", child->key) == 0) - status = cmc_config_add_string("Regex", &match->regex, child); + status = cf_util_get_string(child, &match->regex); else if (strcasecmp("ExcludeRegex", child->key) == 0) - status = - cmc_config_add_string("ExcludeRegex", &match->exclude_regex, child); + status = cf_util_get_string(child, &match->exclude_regex); else if (strcasecmp("DSType", child->key) == 0) status = cmc_config_add_match_dstype(&match->dstype, child); else if (strcasecmp("Type", child->key) == 0) - status = cmc_config_add_string("Type", &match->type, child); + status = cf_util_get_string(child, &match->type); else if (strcasecmp("Instance", child->key) == 0) - status = cmc_config_add_string("Instance", &match->instance, child); + status = cf_util_get_string(child, &match->instance); else { WARNING("memcachec plugin: Option `%s' not allowed here.", child->key); status = -1; @@ -299,9 +285,11 @@ static int cmc_config_add_page(oconfig_item_t *ci) /* {{{ */ oconfig_item_t *child = ci->children + i; if (strcasecmp("Server", child->key) == 0) - status = cmc_config_add_string("Server", &page->server, child); + status = cf_util_get_string(child, &page->server); else if (strcasecmp("Key", child->key) == 0) - status = cmc_config_add_string("Key", &page->key, child); + status = cf_util_get_string(child, &page->key); + else if (strcasecmp("Plugin", child->key) == 0) + status = cf_util_get_string(child, &page->plugin_name); else if (strcasecmp("Match", child->key) == 0) /* Be liberal with failing matches => don't set `status'. */ cmc_config_add_match(page, child); @@ -407,7 +395,8 @@ static void cmc_submit(const web_page_t *wp, const web_match_t *wm, /* {{{ */ vl.values = &value; vl.values_len = 1; - sstrncpy(vl.plugin, "memcachec", sizeof(vl.plugin)); + sstrncpy(vl.plugin, (wp->plugin_name != NULL) ? wp->plugin_name : "memcachec", + sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, wp->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, wm->type, sizeof(vl.type)); sstrncpy(vl.type_instance, wm->instance, sizeof(vl.type_instance));