summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 329e2d4)
raw | patch | inline | side by side (parent: 329e2d4)
author | jaroug <jaroug@gmail.com> | |
Wed, 1 Mar 2017 17:48:47 +0000 (18:48 +0100) | ||
committer | jaroug <jaroug@gmail.com> | |
Wed, 1 Mar 2017 17:48:47 +0000 (18:48 +0100) |
src/utils_format_kairosdb.c | patch | blob | history | |
src/utils_format_kairosdb.h | patch | blob | history | |
src/write_http.c | patch | blob | history |
index 1e54b97c32d0135537032ffd7325774762719ae3..a5d36990baffc9f69d0c20c9608779a232f3e78d 100644 (file)
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 : */
index 9174318dd3f843a0abb8b1ac1428e7cba063958d..5dbcb3964ff22fce6989f80013a1e7de3cc64238 100644 (file)
#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);
diff --git a/src/write_http.c b/src/write_http.c
index c33ab542b8d23cf59b47f691e6839b5502c011c3..7fbc534e92d2e7b4165a759d2aef7f8843ada583 100644 (file)
--- a/src/write_http.c
+++ b/src/write_http.c
};
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);