X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fwrite_sensu.c;h=bda3327834cdf169945061fdf9709ac38c6e29e1;hp=bd7a56d010eaa5af144b27b3aff672901b816e25;hb=06a86a60a7dabc685bdbd81ce3d36ea5f7e2c2d4;hpb=d5456237d0de8f9905ea7a32f2bbae52b5e3ea73 diff --git a/src/write_sensu.c b/src/write_sensu.c index bd7a56d0..bda33278 100644 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@ -31,7 +31,6 @@ #include "common.h" #include "plugin.h" #include "utils_cache.h" - #include #include #include @@ -108,10 +107,10 @@ struct sensu_host { #define F_READY 0x01 uint8_t flags; pthread_mutex_t lock; - _Bool notifications; - _Bool metrics; - _Bool store_rates; - _Bool always_append_ds; + bool notifications; + bool metrics; + bool store_rates; + bool always_append_ds; char *separator; char *node; char *service; @@ -120,8 +119,8 @@ struct sensu_host { int reference_count; }; -static char *sensu_tags = NULL; -static char **sensu_attrs = NULL; +static char *sensu_tags; +static char **sensu_attrs; static size_t sensu_attrs_num; static int add_str_to_list(struct str_list *strs, @@ -338,8 +337,7 @@ static void in_place_replace_sensu_name_reserved(char *orig_name) /* {{{ */ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */ data_set_t const *ds, value_list_t const *vl, - size_t index, gauge_t const *rates, - int status) { + size_t index, gauge_t const *rates) { char name_buffer[5 * DATA_MAX_NAME_LEN]; char service_buffer[6 * DATA_MAX_NAME_LEN]; char *ret_str; @@ -455,7 +453,7 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */ // incorporate the data source index { char ds_index[DATA_MAX_NAME_LEN]; - snprintf(ds_index, sizeof(ds_index), "%zu", index); + snprintf(ds_index, sizeof(ds_index), "%" PRIsz, index); res = my_asprintf(&temp_str, "%s, \"collectd_data_source_index\": %s", ret_str, ds_index); free(ret_str); @@ -520,7 +518,8 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */ return NULL; } } else { - res = my_asprintf(&value_str, "%llu", vl->values[index].counter); + res = my_asprintf(&value_str, "%" PRIu64, + (uint64_t)vl->values[index].counter); if (res == -1) { free(ret_str); ERROR("write_sensu plugin: Unable to alloc memory"); @@ -627,7 +626,7 @@ static char *replace_str(const char *str, const char *old, /* {{{ */ r += newlen; p = q + oldlen; } - strncpy(r, p, strlen(p)); + sstrncpy(r, p, retlen + 1); return ret; } /* }}} char *replace_str */ @@ -880,11 +879,9 @@ static int sensu_send_msg(struct sensu_host *host, const char *msg) /* {{{ */ sensu_close_socket(host); if (status != 0) { - char errbuf[1024]; ERROR("write_sensu plugin: Sending to Sensu at %s:%s failed: %s", (host->node != NULL) ? host->node : SENSU_HOST, - (host->service != NULL) ? host->service : SENSU_PORT, - sstrerror(errno, errbuf, sizeof(errbuf))); + (host->service != NULL) ? host->service : SENSU_PORT, STRERRNO); return -1; } @@ -928,7 +925,7 @@ static int sensu_write(const data_set_t *ds, /* {{{ */ } } for (size_t i = 0; i < vl->values_len; i++) { - msg = sensu_value_to_json(host, ds, vl, (int)i, rates, statuses[i]); + msg = sensu_value_to_json(host, ds, vl, (int)i, rates); if (msg == NULL) { sfree(rates); pthread_mutex_unlock(&host->lock); @@ -1021,10 +1018,10 @@ static int sensu_config_node(oconfig_item_t *ci) /* {{{ */ host->reference_count = 1; host->node = NULL; host->service = NULL; - host->notifications = 0; - host->metrics = 0; - host->store_rates = 1; - host->always_append_ds = 0; + host->notifications = false; + host->metrics = false; + host->store_rates = true; + host->always_append_ds = false; host->metric_handlers.nb_strs = 0; host->metric_handlers.strs = NULL; host->notification_handlers.nb_strs = 0; @@ -1126,16 +1123,17 @@ static int sensu_config_node(oconfig_item_t *ci) /* {{{ */ return -1; } - if ((host->notification_handlers.nb_strs > 0) && (host->notifications == 0)) { + if ((host->notification_handlers.nb_strs > 0) && + (host->notifications == false)) { WARNING("write_sensu plugin: NotificationHandler given so forcing " "notifications to be enabled"); host->notifications = 1; } - if ((host->metric_handlers.nb_strs > 0) && (host->metrics == 0)) { + if ((host->metric_handlers.nb_strs > 0) && (host->metrics == false)) { WARNING("write_sensu plugin: MetricHandler given so forcing metrics to be " "enabled"); - host->metrics = 1; + host->metrics = true; } if (!(host->notifications || host->metrics)) {