X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fwrite_riemann.c;h=201ac516e4dd5c20f851e3d8e124969e1006a8ef;hp=6db3ef58ac88349adfd274cb1d1015e7cf9f4089;hb=54619dc85fd308b21ed09a0271e5c7383c7921b9;hpb=1581f3b307554cbf8b5784729754c5d73a1192a5 diff --git a/src/write_riemann.c b/src/write_riemann.c index 6db3ef58..201ac516 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -30,8 +30,8 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" #include "utils_cache.h" #include "utils_complain.h" #include "write_riemann_threshold.h" @@ -48,11 +48,11 @@ struct riemann_host { char *name; char *event_service_prefix; pthread_mutex_t lock; - _Bool batch_mode; - _Bool notifications; - _Bool check_thresholds; - _Bool store_rates; - _Bool always_append_ds; + bool batch_mode; + bool notifications; + bool check_thresholds; + bool store_rates; + bool always_append_ds; char *node; int port; riemann_client_type_t client_type; @@ -181,9 +181,7 @@ static int wrr_send(struct riemann_host *host, riemann_message_t *msg) { return status; } -static riemann_message_t * -wrr_notification_to_message(struct riemann_host *host, /* {{{ */ - notification_t const *n) { +static riemann_message_t *wrr_notification_to_message(notification_t const *n) { riemann_message_t *msg; riemann_event_t *event; char service_buffer[6 * DATA_MAX_NAME_LEN]; @@ -271,7 +269,7 @@ wrr_notification_to_message(struct riemann_host *host, /* {{{ */ "host = \"%s\", service = \"%s\", state = \"%s\"", event->host, event->service, event->state); return msg; -} /* }}} riemann_message_t *wrr_notification_to_message */ +} static riemann_event_t * wrr_value_to_event(struct riemann_host const *host, /* {{{ */ @@ -293,17 +291,18 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */ vl->type_instance); if (host->always_append_ds || (ds->ds_num > 1)) { if (host->event_service_prefix == NULL) - snprintf(service_buffer, sizeof(service_buffer), "%s/%s", &name_buffer[1], - ds->ds[index].name); + ssnprintf(service_buffer, sizeof(service_buffer), "%s/%s", + &name_buffer[1], ds->ds[index].name); else - snprintf(service_buffer, sizeof(service_buffer), "%s%s/%s", - host->event_service_prefix, &name_buffer[1], ds->ds[index].name); + ssnprintf(service_buffer, sizeof(service_buffer), "%s%s/%s", + host->event_service_prefix, &name_buffer[1], + ds->ds[index].name); } else { if (host->event_service_prefix == NULL) sstrncpy(service_buffer, &name_buffer[1], sizeof(service_buffer)); else - snprintf(service_buffer, sizeof(service_buffer), "%s%s", - host->event_service_prefix, &name_buffer[1]); + ssnprintf(service_buffer, sizeof(service_buffer), "%s%s", + host->event_service_prefix, &name_buffer[1]); } riemann_event_set( @@ -351,8 +350,8 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */ if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL)) { char ds_type[DATA_MAX_NAME_LEN]; - snprintf(ds_type, sizeof(ds_type), "%s:rate", - DS_TYPE_TO_STRING(ds->ds[index].type)); + ssnprintf(ds_type, sizeof(ds_type), "%s:rate", + DS_TYPE_TO_STRING(ds->ds[index].type)); riemann_event_string_attribute_add(event, "ds_type", ds_type); } else { riemann_event_string_attribute_add(event, "ds_type", @@ -362,7 +361,7 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */ { char ds_index[DATA_MAX_NAME_LEN]; - snprintf(ds_index, sizeof(ds_index), "%zu", index); + ssnprintf(ds_index, sizeof(ds_index), "%" PRIsz, index); riemann_event_string_attribute_add(event, "ds_index", ds_index); } @@ -394,6 +393,23 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */ RIEMANN_EVENT_FIELD_NONE); } + if (vl->meta) { + char **toc; + int n = meta_data_toc(vl->meta, &toc); + + for (int i = 0; i < n; i++) { + char *key = toc[i]; + char *value; + + if (0 == meta_data_as_string(vl->meta, key, &value)) { + riemann_event_string_attribute_add(event, key, value); + free(value); + } + } + + free(toc); + } + DEBUG("write_riemann plugin: Successfully created message for metric: " "host = \"%s\", service = \"%s\"", event->host, event->service); @@ -546,7 +562,7 @@ static int wrr_notification(const notification_t *n, user_data_t *ud) /* {{{ */ /* * Never batch for notifications, send them ASAP */ - msg = wrr_notification_to_message(host, n); + msg = wrr_notification_to_message(n); if (msg == NULL) return -1; @@ -610,6 +626,7 @@ static void wrr_free(void *p) /* {{{ */ wrr_disconnect(host); + pthread_mutex_lock(&host->lock); pthread_mutex_destroy(&host->lock); sfree(host); } /* }}} void wrr_free */ @@ -631,11 +648,11 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */ host->reference_count = 1; host->node = NULL; host->port = 0; - host->notifications = 1; - host->check_thresholds = 0; - host->store_rates = 1; - host->always_append_ds = 0; - host->batch_mode = 1; + host->notifications = true; + host->check_thresholds = false; + host->store_rates = true; + host->always_append_ds = false; + host->batch_mode = true; host->batch_max = RIEMANN_BATCH_MAX; /* typical MSS */ host->batch_init = cdtime(); host->batch_timeout = 0; @@ -700,21 +717,13 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */ } else if (strcasecmp("Port", child->key) == 0) { host->port = cf_util_get_port_number(child); if (host->port == -1) { - ERROR("write_riemann plugin: Invalid argument " - "configured for the \"Port\" " - "option."); break; } } else if (strcasecmp("Protocol", child->key) == 0) { char tmp[16]; status = cf_util_get_string_buffer(child, tmp, sizeof(tmp)); - if (status != 0) { - ERROR("write_riemann plugin: cf_util_get_" - "string_buffer failed with " - "status %i.", - status); + if (status != 0) break; - } if (strcasecmp("UDP", tmp) == 0) host->client_type = RIEMANN_CLIENT_UDP; @@ -730,31 +739,16 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */ tmp); } else if (strcasecmp("TLSCAFile", child->key) == 0) { status = cf_util_get_string(child, &host->tls_ca_file); - if (status != 0) { - ERROR("write_riemann plugin: cf_util_get_" - "string_buffer failed with " - "status %i.", - status); + if (status != 0) break; - } } else if (strcasecmp("TLSCertFile", child->key) == 0) { status = cf_util_get_string(child, &host->tls_cert_file); - if (status != 0) { - ERROR("write_riemann plugin: cf_util_get_" - "string_buffer failed with " - "status %i.", - status); + if (status != 0) break; - } } else if (strcasecmp("TLSKeyFile", child->key) == 0) { status = cf_util_get_string(child, &host->tls_key_file); - if (status != 0) { - ERROR("write_riemann plugin: cf_util_get_" - "string_buffer failed with " - "status %i.", - status); + if (status != 0) break; - } } else if (strcasecmp("StoreRates", child->key) == 0) { status = cf_util_get_boolean(child, &host->store_rates); if (status != 0) @@ -801,8 +795,8 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */ return status; } - snprintf(callback_name, sizeof(callback_name), "write_riemann/%s", - host->name); + ssnprintf(callback_name, sizeof(callback_name), "write_riemann/%s", + host->name); user_data_t ud = {.data = host, .free_func = wrr_free};