X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_http.c;h=097101f4c954c369aa35bdec76f88e4babb3b23d;hb=a6f29de68fe19614b0aa90e920e99d72cb0f4468;hp=c33ab542b8d23cf59b47f691e6839b5502c011c3;hpb=c7c89cc9618ef25cc9b0861ac2782cb1a5d6782d;p=collectd.git diff --git a/src/write_http.c b/src/write_http.c index c33ab542..097101f4 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -78,9 +78,14 @@ struct wh_callback_s { cdtime_t send_buffer_init_time; pthread_mutex_t send_lock; + + int data_ttl; }; 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; @@ -468,9 +473,10 @@ static int wh_write_kairosdb(const data_set_t *ds, } } - 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, + cb->data_ttl); if (status == -ENOMEM) { status = wh_flush_nolock(/* timeout = */ 0, cb); if (status != 0) { @@ -479,9 +485,10 @@ static int wh_write_kairosdb(const data_set_t *ds, 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, + cb->data_ttl); } if (status != 0) { pthread_mutex_unlock(&cb->send_lock); @@ -621,6 +628,7 @@ static int wh_config_node(oconfig_item_t *ci) /* {{{ */ cb->headers = NULL; cb->send_metrics = 1; cb->send_notifications = 0; + cb->data_ttl = 0; pthread_mutex_init(&cb->send_lock, /* attr = */ NULL); @@ -703,7 +711,36 @@ static int wh_config_node(oconfig_item_t *ci) /* {{{ */ 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 plugin: 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 plugin: 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 plugin: got attribute: %s => %s", key, val); + sfree(key); + sfree(val); + } else if (strcasecmp("TTL", child->key) == 0) { + status = cf_util_get_int(child, &cb->data_ttl); + } else { ERROR("write_http plugin: Invalid configuration " "option: %s.", child->key);