static int value_list_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */
const data_set_t *ds, const value_list_t *vl,
- int store_rates) {
+ int store_rates,
+ char const *const *http_attrs,
+ const int http_attrs_num) {
char temp[512];
size_t offset = 0;
int status;
BUFFER_ADD(", \"tags\":\{");
BUFFER_ADD("\"host\": \"%s\"", vl->host);
+ for (int j = 0; j < http_attrs_num; j += 2) {
+ BUFFER_ADD(", \"%s\":", http_attrs[j]);
+ BUFFER_ADD(" \"%s\"", http_attrs[j + 1]);
+ }
+
if (strlen(vl->plugin_instance))
BUFFER_ADD_KEYVAL("plugin_instance", vl->plugin_instance);
BUFFER_ADD_KEYVAL("type", vl->type);
static int format_kairosdb_value_list_nocheck(
char *buffer, /* {{{ */
size_t *ret_buffer_fill, size_t *ret_buffer_free, const data_set_t *ds,
- const value_list_t *vl, int store_rates, size_t temp_size) {
+ const value_list_t *vl, int store_rates, size_t temp_size,
+ char const *const *http_attrs, const int http_attrs_num) {
char temp[temp_size];
int status;
- status = value_list_to_kairosdb(temp, sizeof(temp), ds, vl, store_rates);
+ status = value_list_to_kairosdb(temp, sizeof(temp), ds, vl, store_rates,
+ http_attrs, http_attrs_num);
if (status != 0)
return (status);
temp_size = strlen(temp);
int format_kairosdb_value_list(char *buffer, /* {{{ */
size_t *ret_buffer_fill, size_t *ret_buffer_free,
const data_set_t *ds, const value_list_t *vl,
- int store_rates) {
+ int store_rates, char const *const *http_attrs,
+ const int http_attrs_num) {
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL) || (ds == NULL) || (vl == NULL))
return (-EINVAL);
return (format_kairosdb_value_list_nocheck(
buffer, ret_buffer_fill, ret_buffer_free, ds, vl, store_rates,
- (*ret_buffer_free) - 2));
+ (*ret_buffer_free) - 2, http_attrs, http_attrs_num));
} /* }}} int format_kairosdb_value_list */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
#define JSON_GAUGE_FORMAT GAUGE_FORMAT
#endif
+
int format_kairosdb_initialize(char *buffer, size_t *ret_buffer_fill,
size_t *ret_buffer_free);
int format_kairosdb_value_list(char *buffer, size_t *ret_buffer_fill,
size_t *ret_buffer_free, const data_set_t *ds,
- const value_list_t *vl, int store_rates);
+ const value_list_t *vl, int store_rates,
+ char const *const *http_attrs,
+ const int http_attrs_num);
int format_kairosdb_finalize(char *buffer, size_t *ret_buffer_fill,
size_t *ret_buffer_free);
};
typedef struct wh_callback_s wh_callback_t;
+static char **http_attrs;
+static size_t http_attrs_num;
+
static void wh_log_http_error(wh_callback_t *cb) {
if (!cb->log_http_error)
return;
}
}
- status = format_kairosdb_value_list(cb->send_buffer, &cb->send_buffer_fill,
- &cb->send_buffer_free, ds, vl,
- cb->store_rates);
+ status = format_kairosdb_value_list(
+ cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, ds, vl,
+ cb->store_rates, (char const *const *)http_attrs, http_attrs_num);
if (status == -ENOMEM) {
status = wh_flush_nolock(/* timeout = */ 0, cb);
if (status != 0) {
return (status);
}
- status = format_kairosdb_value_list(cb->send_buffer, &cb->send_buffer_fill,
- &cb->send_buffer_free, ds, vl,
- cb->store_rates);
+ status = format_kairosdb_value_list(
+ cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, ds, vl,
+ cb->store_rates, (char const *const *)http_attrs, http_attrs_num);
}
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
status = cf_util_get_boolean(child, &cb->log_http_error);
else if (strcasecmp("Header", child->key) == 0)
status = wh_config_append_string("Header", &cb->headers, child);
- else {
+ else if (strcasecmp("Attribute", child->key) == 0) {
+ char *key = NULL;
+ char *val = NULL;
+
+ if (child->values_num != 2) {
+ WARNING("write_http plugins: Attribute need both a key and a value.");
+ break;
+ }
+ if (child->values[0].type != OCONFIG_TYPE_STRING ||
+ child->values[1].type != OCONFIG_TYPE_STRING) {
+ WARNING("write_http plugins: Attribute needs string arguments.");
+ break;
+ }
+ if ((key = strdup(child->values[0].value.string)) == NULL) {
+ WARNING("cannot allocate memory for attribute key.");
+ break;
+ }
+ if ((val = strdup(child->values[1].value.string)) == NULL) {
+ WARNING("cannot allocate memory for attribute value.");
+ sfree(key);
+ break;
+ }
+ strarray_add(&http_attrs, &http_attrs_num, key);
+ strarray_add(&http_attrs, &http_attrs_num, val);
+ DEBUG("write_http plugins: got attribute: %s => %s", key, val);
+ sfree(key);
+ sfree(val);
+ } else {
ERROR("write_http plugin: Invalid configuration "
"option: %s.",
child->key);