X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fwrite_riemann.c;h=8191ae256d61caec939dacd322c82fab8ca49fba;hb=8361c1e963f9184c3c4d87197fd6996d667cdb3f;hp=5c59c92e4c50341c27fcb380188363685783d5d6;hpb=40aabf444e124f40603021821e98bcc40c4aaa0e;p=collectd.git diff --git a/src/write_riemann.c b/src/write_riemann.c index 5c59c92e..8191ae25 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -26,26 +26,25 @@ * Florian octo Forster */ +#include +#include +#include +#include +#include + #include "collectd.h" #include "plugin.h" #include "common.h" #include "configfile.h" #include "utils_cache.h" #include "riemann.pb-c.h" - -#include -#include -#include -#include -#include +#include "write_riemann_threshold.h" #define RIEMANN_HOST "localhost" #define RIEMANN_PORT "5555" #define RIEMANN_TTL_FACTOR 2.0 #define RIEMANN_BATCH_MAX 8192 -int write_riemann_threshold_check(const data_set_t *, const value_list_t *, int *); - struct riemann_host { char *name; char *event_service_prefix; @@ -206,12 +205,11 @@ static int riemann_send_msg (struct riemann_host *host, const Msg *msg) /* {{{ * if (host->use_tcp) buffer_len += 4; - buffer = malloc (buffer_len); + buffer = calloc (1, buffer_len); if (buffer == NULL) { - ERROR ("write_riemann plugin: malloc failed."); + ERROR ("write_riemann plugin: calloc failed."); return ENOMEM; } - memset (buffer, 0, buffer_len); if (host->use_tcp) { @@ -366,13 +364,12 @@ static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ * notification_meta_t *meta; size_t i; - msg = malloc (sizeof (*msg)); + msg = calloc (1, sizeof (*msg)); if (msg == NULL) { - ERROR ("write_riemann plugin: malloc failed."); + ERROR ("write_riemann plugin: calloc failed."); return (NULL); } - memset (msg, 0, sizeof (*msg)); msg__init (msg); msg->events = malloc (sizeof (*msg->events)); @@ -383,15 +380,14 @@ static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ * return (NULL); } - event = malloc (sizeof (*event)); + event = calloc (1, sizeof (*event)); if (event == NULL) { - ERROR ("write_riemann plugin: malloc failed."); + ERROR ("write_riemann plugin: calloc failed."); sfree (msg->events); sfree (msg); return (NULL); } - memset (event, 0, sizeof (*event)); event__init (event); msg->events[0] = event; @@ -475,13 +471,12 @@ static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ double ttl; size_t i; - event = malloc (sizeof (*event)); + event = calloc (1, sizeof (*event)); if (event == NULL) { - ERROR ("write_riemann plugin: malloc failed."); + ERROR ("write_riemann plugin: calloc failed."); return (NULL); } - memset (event, 0, sizeof (*event)); event__init (event); event->host = strdup (vl->host); @@ -608,13 +603,12 @@ static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* gauge_t *rates = NULL; /* Initialize the Msg structure. */ - msg = malloc (sizeof (*msg)); + msg = calloc (1, sizeof (*msg)); if (msg == NULL) { - ERROR ("write_riemann plugin: malloc failed."); + ERROR ("write_riemann plugin: calloc failed."); return (NULL); } - memset (msg, 0, sizeof (*msg)); msg__init (msg); /* Set up events. First, the list of pointers. */