* Marc Fournier <marc.fournier at camptocamp.com>
**/
+#include "collectd.h"
#include "common.h"
#include "plugin.h"
#include "utils_time.h"
-#include "collectd.h"
#define CGPS_TRUE 1
#define CGPS_FALSE 0
int ret = !cgps_thread_shutdown;
- pthread_mutex_lock(&cgps_thread_lock);
+ pthread_mutex_unlock(&cgps_thread_lock);
return ret;
}
} /* tbl_config_append_array_s */
static int tbl_config_result(tbl_t *tbl, oconfig_item_t *ci) {
- tbl_result_t *res;
-
- int status = 0;
-
if (0 != ci->values_num) {
log_err("<Result> does not expect any arguments.");
return 1;
}
- res = realloc(tbl->results, (tbl->results_num + 1) * sizeof(*tbl->results));
+ tbl_result_t *res =
+ realloc(tbl->results, (tbl->results_num + 1) * sizeof(*tbl->results));
if (res == NULL) {
char errbuf[1024];
log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf)));
}
tbl->results = res;
- ++tbl->results_num;
- res = tbl->results + tbl->results_num - 1;
+ res = tbl->results + tbl->results_num;
tbl_result_setup(res);
for (int i = 0; i < ci->children_num; ++i) {
c->key);
}
+ int status = 0;
if (NULL == res->type) {
- log_err("No \"Type\" option specified for <Result> "
- "in table \"%s\".",
+ log_err("No \"Type\" option specified for <Result> in table \"%s\".",
tbl->file);
status = 1;
}
if (NULL == res->values) {
- log_err("No \"ValuesFrom\" option specified for <Result> "
- "in table \"%s\".",
+ log_err("No \"ValuesFrom\" option specified for <Result> in table \"%s\".",
tbl->file);
status = 1;
}
if (0 != status) {
tbl_result_clear(res);
- --tbl->results_num;
return status;
}
+
+ tbl->results_num++;
return 0;
} /* tbl_config_result */
static int tbl_config_table(oconfig_item_t *ci) {
- tbl_t *tbl;
-
- int status = 0;
-
if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
log_err("<Table> expects a single string argument.");
return 1;
}
- tbl = realloc(tables, (tables_num + 1) * sizeof(*tables));
+ tbl_t *tbl = realloc(tables, (tables_num + 1) * sizeof(*tables));
if (NULL == tbl) {
char errbuf[1024];
log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf)));
}
tables = tbl;
- ++tables_num;
- tbl = tables + tables_num - 1;
+ tbl = tables + tables_num;
tbl_setup(tbl, ci->values[0].value.string);
for (size_t i = 0; i < ((size_t)ci->children_num); ++i) {
c->key, tbl->file);
}
+ int status = 0;
if (NULL == tbl->sep) {
log_err("Table \"%s\" does not specify any separator.", tbl->file);
status = 1;
}
if (NULL == tbl->results) {
+ assert(tbl->results_num == 0);
log_err("Table \"%s\" does not specify any (valid) results.", tbl->file);
status = 1;
}
if (0 != status) {
tbl_clear(tbl);
- --tables_num;
return status;
}
if (res->values[j] > tbl->max_colnum)
tbl->max_colnum = res->values[j];
}
+
+ tables_num++;
return 0;
} /* tbl_config_table */
if (vl->meta != NULL) {
char **meta_toc = NULL;
- int meta_entries = meta_data_toc(vl->meta, &meta_toc);
- if (meta_entries <= 0)
+ int status = meta_data_toc(vl->meta, &meta_toc);
+ if (status <= 0)
return;
+ size_t meta_entries = (size_t)status;
- for (int i = 0; i < meta_entries; i++) {
+ for (size_t i = 0; i < meta_entries; i++) {
char meta_name[DATA_MAX_NAME_LEN];
char *value_str;
const char *key = meta_toc[i];
if (data->meta != NULL) {
char temp[DATA_MAX_NAME_LEN * 2];
- int meta_entries;
char **meta_toc;
if ((new_meta = meta_data_create()) == NULL) {
return -ENOMEM;
}
- meta_entries = meta_data_toc(data->meta, &meta_toc);
- for (int i = 0; i < meta_entries; i++) {
+ int status = meta_data_toc(data->meta, &meta_toc);
+ if (status < 0) {
+ ERROR("Target `set': meta_data_toc failed with status %d.", status);
+ return status;
+ }
+ size_t meta_entries = (size_t)status;
+
+ for (size_t i = 0; i < meta_entries; i++) {
const char *key = meta_toc[i];
char *string;
int status;
if (status) {
ERROR("Target `set': Unable to get replacement metadata value `%s'.",
key);
- strarray_free(meta_toc, (size_t)meta_entries);
+ strarray_free(meta_toc, meta_entries);
meta_data_destroy(new_meta);
return status;
}
status = meta_data_add_string(new_meta, key, temp);
if (status) {
ERROR("Target `set': Unable to set metadata value `%s'.", key);
- strarray_free(meta_toc, (size_t)meta_entries);
+ strarray_free(meta_toc, meta_entries);
meta_data_destroy(new_meta);
return status;
}
}
- strarray_free(meta_toc, (size_t)meta_entries);
+ strarray_free(meta_toc, meta_entries);
}
#define SUBST_FIELD(f) \
} \
} while (0)
+#define CHECK_SUCCESS(cmd) \
+ do { \
+ yajl_gen_status s = (cmd); \
+ if (s != yajl_gen_status_ok) { \
+ return (int)s; \
+ } \
+ } while (0)
+
static int format_json_meta(yajl_gen g, notification_meta_t *meta) /* {{{ */
{
if (meta == NULL)
default:
ERROR("format_json_meta: unknown meta data type %d (name \"%s\")",
meta->type, meta->name);
- yajl_gen_null(g);
+ CHECK_SUCCESS(yajl_gen_null(g));
}
return format_json_meta(g, meta->next);
static int format_alert(yajl_gen g, notification_t const *n) /* {{{ */
{
- yajl_gen_array_open(g);
- yajl_gen_map_open(g); /* BEGIN alert */
+ CHECK_SUCCESS(yajl_gen_array_open(g)); /* BEGIN array */
+ CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN alert */
/*
* labels
*/
JSON_ADD(g, "labels");
- yajl_gen_map_open(g); /* BEGIN labels */
+ CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN labels */
JSON_ADD(g, "alertname");
if (strncmp(n->plugin, n->type, strlen(n->plugin)) == 0)
JSON_ADD(g, "service");
JSON_ADD(g, "collectd");
- yajl_gen_map_close(g); /* END labels */
+ CHECK_SUCCESS(yajl_gen_map_close(g)); /* END labels */
/*
* annotations
*/
JSON_ADD(g, "annotations");
- yajl_gen_map_open(g); /* BEGIN annotations */
+ CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN annotations */
JSON_ADD(g, "summary");
JSON_ADD(g, n->message);
- if (format_json_meta(g, n->meta) != 0)
+ if (format_json_meta(g, n->meta) != 0) {
return -1;
+ }
- yajl_gen_map_close(g); /* END annotations */
+ CHECK_SUCCESS(yajl_gen_map_close(g)); /* END annotations */
JSON_ADD(g, "startsAt");
- format_time(g, n->time);
+ if (format_time(g, n->time) != 0) {
+ return -1;
+ }
- yajl_gen_map_close(g); /* END alert */
- yajl_gen_array_close(g);
+ CHECK_SUCCESS(yajl_gen_map_close(g)); /* END alert */
+ CHECK_SUCCESS(yajl_gen_array_close(g)); /* END array */
return 0;
} /* }}} format_alert */
}
/* copy to output buffer */
- yajl_gen_get_buf(g, &out, &unused_out_len);
+ if (yajl_gen_get_buf(g, &out, &unused_out_len) != yajl_gen_status_ok) {
+ yajl_gen_clear(g);
+ yajl_gen_free(g);
+ return -1;
+ }
sstrncpy(buffer, (void *)out, buffer_size);
yajl_gen_clear(g);
sfree(cb->prefix);
sfree(cb->postfix);
+ pthread_mutex_unlock(&cb->send_lock);
pthread_mutex_destroy(&cb->send_lock);
sfree(cb);
#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "utils_cache.h"
+
#include <arpa/inet.h>
#include <errno.h>
#include <inttypes.h>
#include <netdb.h>
#include <stddef.h>
-#include "common.h"
-#include "plugin.h"
-#include "utils_cache.h"
#include <stdlib.h>
#define SENSU_HOST "localhost"
sfree(host->separator);
free_str_list(&(host->metric_handlers));
free_str_list(&(host->notification_handlers));
+
+ pthread_mutex_unlock(&host->lock);
pthread_mutex_destroy(&host->lock);
+
sfree(host);
} /* }}} void sensu_free */
sfree(cb->service);
sfree(cb->host_tags);
+ pthread_mutex_unlock(&cb->send_lock);
pthread_mutex_destroy(&cb->send_lock);
sfree(cb);