X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_riemann.c;h=73d202c42fe8f228aaea46279dd12827a16d0371;hb=7c702e464f9faf954c320ec5b87c4755083d82bd;hp=a09c72361f910ac8615a219fd9187da36e77a819;hpb=81a5fd5046c6a39f580a8fc1a3af837fd5f5aa5c;p=collectd.git diff --git a/src/write_riemann.c b/src/write_riemann.c index a09c7236..73d202c4 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -33,7 +33,6 @@ #include "utils_cache.h" #include "riemann.pb-c.h" -#include #include #include #include @@ -365,7 +364,7 @@ static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ * char service_buffer[6 * DATA_MAX_NAME_LEN]; char const *severity; notification_meta_t *meta; - int i; + size_t i; msg = malloc (sizeof (*msg)); if (msg == NULL) @@ -474,7 +473,7 @@ static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ char name_buffer[5 * DATA_MAX_NAME_LEN]; char service_buffer[6 * DATA_MAX_NAME_LEN]; double ttl; - int i; + size_t i; event = malloc (sizeof (*event)); if (event == NULL) @@ -619,7 +618,7 @@ static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* msg__init (msg); /* Set up events. First, the list of pointers. */ - msg->n_events = (size_t) vl->values_len; + msg->n_events = vl->values_len; msg->events = calloc (msg->n_events, sizeof (*msg->events)); if (msg->events == NULL) { @@ -744,8 +743,8 @@ static int riemann_batch_add_value_list (struct riemann_host *host, /* {{{ */ len = msg__get_packed_size(host->batch_msg); ret = 0; - if (len >= host->batch_max) { - ret = riemann_batch_flush_nolock(0, host); + if ((host->batch_max < 0) || (((size_t) host->batch_max) <= len)) { + ret = riemann_batch_flush_nolock(0, host); } pthread_mutex_unlock(&host->lock); @@ -778,35 +777,35 @@ static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ } /* }}} int riemann_notification */ static int riemann_write(const data_set_t *ds, /* {{{ */ - const value_list_t *vl, - user_data_t *ud) + const value_list_t *vl, + user_data_t *ud) { int status = 0; int statuses[vl->values_len]; struct riemann_host *host = ud->data; - Msg *msg; - - if (host->check_thresholds) - write_riemann_threshold_check(ds, vl, statuses); - - if (host->use_tcp == 1 && host->batch_mode) { - - riemann_batch_add_value_list (host, ds, vl, statuses); + if (host->check_thresholds) { + status = write_riemann_threshold_check(ds, vl, statuses); + if (status != 0) + return status; + } else { + memset (statuses, 0, sizeof (statuses)); + } - } else { + if (host->use_tcp == 1 && host->batch_mode) { + riemann_batch_add_value_list (host, ds, vl, statuses); + } else { + Msg *msg = riemann_value_list_to_protobuf (host, ds, vl, statuses); + if (msg == NULL) + return (-1); - msg = riemann_value_list_to_protobuf (host, ds, vl, statuses); - if (msg == NULL) - return (-1); + status = riemann_send (host, msg); + if (status != 0) + ERROR ("write_riemann plugin: riemann_send failed with status %i", status); - status = riemann_send (host, msg); - if (status != 0) - ERROR ("write_riemann plugin: riemann_send failed with status %i", - status); + riemann_msg_protobuf_free (msg); + } - riemann_msg_protobuf_free (msg); - } return status; } /* }}} int riemann_write */