-static int wg_format_values (char *ret, size_t ret_len,
- int ds_num, const data_set_t *ds, const value_list_t *vl,
- _Bool store_rates)
-{
- size_t offset = 0;
- int status;
- gauge_t *rates = NULL;
-
- assert (0 == strcmp (ds->type, vl->type));
-
- memset (ret, 0, ret_len);
-
-#define BUFFER_ADD(...) do { \
- status = ssnprintf (ret + offset, ret_len - offset, \
- __VA_ARGS__); \
- if (status < 1) \
- { \
- sfree (rates); \
- return (-1); \
- } \
- else if (((size_t) status) >= (ret_len - offset)) \
- { \
- sfree (rates); \
- return (-1); \
- } \
- else \
- offset += ((size_t) status); \
-} while (0)
-
- if (ds->ds[ds_num].type == DS_TYPE_GAUGE)
- BUFFER_ADD ("%f", vl->values[ds_num].gauge);
- else if (store_rates)
- {
- if (rates == NULL)
- rates = uc_get_rate (ds, vl);
- if (rates == NULL)
- {
- WARNING ("format_values: "
- "uc_get_rate failed.");
- return (-1);
- }
- BUFFER_ADD ("%g", rates[ds_num]);
- }
- else if (ds->ds[ds_num].type == DS_TYPE_COUNTER)
- BUFFER_ADD ("%llu", vl->values[ds_num].counter);
- else if (ds->ds[ds_num].type == DS_TYPE_DERIVE)
- BUFFER_ADD ("%"PRIi64, vl->values[ds_num].derive);
- else if (ds->ds[ds_num].type == DS_TYPE_ABSOLUTE)
- BUFFER_ADD ("%"PRIu64, vl->values[ds_num].absolute);
- else
- {
- ERROR ("format_values plugin: Unknown data source type: %i",
- ds->ds[ds_num].type);
- sfree (rates);
- return (-1);
- }
-
-#undef BUFFER_ADD
-
- sfree (rates);
- return (0);
-}
-
-static void swap_chars (char *dst, const char *src,
- const char from, const char to)
-{
- size_t i;
-
- for (i = 0; i < strlen(src) ; i++)
- {
- if (src[i] == from)
- dst[i] = to;
- else
- dst[i] = src[i];
- }
- dst[i] = '\0';
-}
-
-static int wg_format_name (char *ret, int ret_len,
- const char *hostname,
- const char *plugin, const char *plugin_instance,
- const char *type, const char *type_instance,
- const char *prefix, const char *postfix,
- const char *ds_name, const char dotchar)
-{
- int status;
- char *n_hostname = NULL;
- char *n_plugin = NULL;
- char *n_plugin_instance = NULL;
- char *n_type = NULL;
- char *n_type_instance = NULL;
-
- assert (plugin != NULL);
- assert (type != NULL);
-
- if (prefix == NULL)
- prefix = "";
-
- if (postfix == NULL)
- postfix = "";
-
- if ((n_hostname = malloc(strlen(hostname)+1)) == NULL)
- {
- ERROR ("Unable to allocate memory for normalized hostname buffer");
- return (-1);
- }
-
- if ((n_plugin = malloc(strlen(plugin)+1)) == NULL)
- {
- ERROR ("Unable to allocate memory for normalized plugin buffer");
- return (-1);
- }
-
- if ((n_type = malloc(strlen(type)+1)) == NULL)
- {
- ERROR ("Unable to allocate memory for normalized type buffer");
- return (-1);
- }
-
- swap_chars(n_hostname, hostname, '.', dotchar);
- swap_chars(n_plugin, plugin, ' ', '_');
- swap_chars(n_type, type, ' ', '_');
-
- if (type_instance != NULL && type_instance[0] != '\0')
- {
- if ((n_type_instance = malloc(strlen(type_instance)+1)) == NULL)
- {
- ERROR ("Unable to allocate memory for normalized datasource name buffer");
- return (-1);
- }
- swap_chars(n_type_instance, type_instance, '.', dotchar);
- swap_chars(n_type_instance, type_instance, ' ', '_');
- }
-
- if (plugin_instance != NULL && plugin_instance[0] != '\0')
- {
- if ((n_plugin_instance = malloc(strlen(plugin_instance)+1)) == NULL)
- {
- ERROR ("Unable to allocate memory for normalized plugin instance buffer");
- return (-1);
- }
- swap_chars(n_plugin_instance, plugin_instance, ' ', '_');
- }
-
- if ((n_plugin_instance == NULL) || (n_plugin_instance[0] == '\0'))
- {
- 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",
- prefix, n_hostname, postfix, n_plugin, n_type);
- else
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s",
- prefix, n_hostname, postfix, n_plugin, n_type, ds_name);
- }
- else
- {
- if ((ds_name == NULL) || (ds_name[0] == '\0'))
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s",
- prefix, n_hostname, postfix, n_plugin, n_type,
- n_type_instance);
- else
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s.%s",
- prefix, n_hostname, postfix, n_plugin, n_type,
- n_type_instance, ds_name);
- }
- }
- else
- {
- 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",
- prefix, n_hostname, postfix, n_plugin,
- n_plugin_instance, n_type);
- else
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s.%s",
- prefix, n_hostname, postfix, n_plugin,
- n_plugin_instance, n_type, ds_name);
- }
- else
- {
- if ((ds_name == NULL) || (ds_name[0] == '\0'))
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s",
- prefix, n_hostname, postfix, n_plugin,
- n_plugin_instance, n_type, n_type_instance);
- else
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s.%s",
- prefix, n_hostname, postfix, n_plugin,
- n_plugin_instance, n_type, n_type_instance, ds_name);
- }
- }
-
- sfree(n_hostname);
- sfree(n_type_instance);
- sfree(n_type);
- sfree(n_plugin);
- sfree(n_plugin_instance);
-
- if ((status < 1) || (status >= ret_len))
- return (-1);
- return (0);
-}
-
-static int wg_send_message (const char* key, const char* value,
- cdtime_t time, struct wg_callback *cb)