From: Scott Sanders Date: Sun, 9 Oct 2011 23:08:27 +0000 (-0400) Subject: Prefix is no longer a required directive X-Git-Tag: collectd-5.1.0~35^2~25^2~4 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1ff2894d084f8bcc87ab3a04e890cfc99113a431;p=collectd.git Prefix is no longer a required directive While useful, the user should not be required to provide a prefix. Having the hosts as the top level containers may make sense in some environments. The current format is "${prefix}${hostname}${postfix}" so be careful to add dots where needed. Also updated docs to reflect this change. --- diff --git a/src/write_graphite.c b/src/write_graphite.c index 4fc38fb3..57933e8d 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -378,20 +378,20 @@ static int wg_format_name (char *ret, int ret_len, if ((n_type_instance == NULL) || (n_type_instance[0] == '\0')) { if ((ds_name == NULL) || (ds_name[0] == '\0')) - status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s", prefix, n_hostname, postfix, plugin, type); else - status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s", prefix, n_hostname, postfix, plugin, type, ds_name); } else { if ((ds_name == NULL) || (ds_name[0] == '\0')) - status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s-%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s", prefix, n_hostname, postfix, plugin, type, n_type_instance); else - status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s-%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s.%s", prefix, n_hostname, postfix, plugin, type, n_type_instance, ds_name); } @@ -401,22 +401,22 @@ static int wg_format_name (char *ret, int ret_len, if ((n_type_instance == NULL) || (n_type_instance[0] == '\0')) { if ((ds_name == NULL) || (ds_name[0] == '\0')) - status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s", prefix, n_hostname, postfix, plugin, plugin_instance, type); else - status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s.%s", prefix, n_hostname, postfix, plugin, plugin_instance, type, ds_name); } else { if ((ds_name == NULL) || (ds_name[0] == '\0')) - status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s-%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s", prefix, n_hostname, postfix, plugin, plugin_instance, type, n_type_instance); else - status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s-%s.%s", + status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s.%s", prefix, n_hostname, postfix, plugin, plugin_instance, type, n_type_instance, ds_name); } @@ -692,10 +692,19 @@ static int wg_config_carbon (oconfig_item_t *ci) } } + if (cb->prefix == NULL) { + if ((cb->prefix = malloc((int)sizeof(char))) == NULL) + { + ERROR ("Unable to allocate memory for hostname prefix buffer"); + return (-1); + } + cb->postfix[0] = '\0'; + } + if (cb->postfix == NULL) { if ((cb->postfix = malloc((int)sizeof(char))) == NULL) { - ERROR ("Unable to allocate memory for normalized hostname buffer"); + ERROR ("Unable to allocate memory for hostname postfix buffer"); return (-1); } cb->postfix[0] = '\0';