projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
virt plugin: Skip 'last_update' reporting as that is not memory but timestamp
[collectd.git]
/
src
/
write_sensu.c
diff --git
a/src/write_sensu.c
b/src/write_sensu.c
index
a34f0cf
..
7d08fb5
100644
(file)
--- a/
src/write_sensu.c
+++ b/
src/write_sensu.c
@@
-28,8
+28,8
@@
#include "collectd.h"
#include "collectd.h"
-#include "common.h"
#include "plugin.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include "utils_cache.h"
#include <arpa/inet.h>
#include <errno.h>
#include "utils_cache.h"
#include <arpa/inet.h>
#include <errno.h>
@@
-107,10
+107,10
@@
struct sensu_host {
#define F_READY 0x01
uint8_t flags;
pthread_mutex_t lock;
#define F_READY 0x01
uint8_t flags;
pthread_mutex_t lock;
-
_B
ool notifications;
-
_B
ool metrics;
-
_B
ool store_rates;
-
_B
ool always_append_ds;
+
b
ool notifications;
+
b
ool metrics;
+
b
ool store_rates;
+
b
ool always_append_ds;
char *separator;
char *node;
char *service;
char *separator;
char *node;
char *service;
@@
-119,8
+119,8
@@
struct sensu_host {
int reference_count;
};
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,
static size_t sensu_attrs_num;
static int add_str_to_list(struct str_list *strs,
@@
-309,8
+309,8
@@
static int sensu_format_name2(char *ret, int ret_len, const char *hostname,
static void in_place_replace_sensu_name_reserved(char *orig_name) /* {{{ */
{
static void in_place_replace_sensu_name_reserved(char *orig_name) /* {{{ */
{
-
in
t len = strlen(orig_name);
- for (
in
t i = 0; i < len; i++) {
+
size_
t len = strlen(orig_name);
+ for (
size_
t i = 0; i < len; i++) {
// some plugins like ipmi generate special characters in metric name
switch (orig_name[i]) {
case '(':
// some plugins like ipmi generate special characters in metric name
switch (orig_name[i]) {
case '(':
@@
-337,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,
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;
char name_buffer[5 * DATA_MAX_NAME_LEN];
char service_buffer[6 * DATA_MAX_NAME_LEN];
char *ret_str;
@@
-454,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];
// 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);
res = my_asprintf(&temp_str, "%s, \"collectd_data_source_index\": %s",
ret_str, ds_index);
free(ret_str);
@@
-519,7
+518,8
@@
static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */
return NULL;
}
} else {
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");
if (res == -1) {
free(ret_str);
ERROR("write_sensu plugin: Unable to alloc memory");
@@
-626,7
+626,7
@@
static char *replace_str(const char *str, const char *old, /* {{{ */
r += newlen;
p = q + oldlen;
}
r += newlen;
p = q + oldlen;
}
- s
trncpy(r, p, strlen(p)
);
+ s
strncpy(r, p, retlen + 1
);
return ret;
} /* }}} char *replace_str */
return ret;
} /* }}} char *replace_str */
@@
-925,7
+925,7
@@
static int sensu_write(const data_set_t *ds, /* {{{ */
}
}
for (size_t i = 0; i < vl->values_len; i++) {
}
}
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);
if (msg == NULL) {
sfree(rates);
pthread_mutex_unlock(&host->lock);
@@
-996,7
+996,10
@@
static void sensu_free(void *p) /* {{{ */
sfree(host->separator);
free_str_list(&(host->metric_handlers));
free_str_list(&(host->notification_handlers));
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);
pthread_mutex_destroy(&host->lock);
+
sfree(host);
} /* }}} void sensu_free */
sfree(host);
} /* }}} void sensu_free */
@@
-1015,10
+1018,10
@@
static int sensu_config_node(oconfig_item_t *ci) /* {{{ */
host->reference_count = 1;
host->node = NULL;
host->service = NULL;
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;
host->metric_handlers.nb_strs = 0;
host->metric_handlers.strs = NULL;
host->notification_handlers.nb_strs = 0;
@@
-1081,12
+1084,8
@@
static int sensu_config_node(oconfig_item_t *ci) /* {{{ */
break;
} else if (strcasecmp("Port", child->key) == 0) {
status = cf_util_get_service(child, &host->service);
break;
} else if (strcasecmp("Port", child->key) == 0) {
status = cf_util_get_service(child, &host->service);
- if (status != 0) {
- ERROR("write_sensu plugin: Invalid argument "
- "configured for the \"Port\" "
- "option.");
+ if (status != 0)
break;
break;
- }
} else if (strcasecmp("StoreRates", child->key) == 0) {
status = cf_util_get_boolean(child, &host->store_rates);
if (status != 0)
} else if (strcasecmp("StoreRates", child->key) == 0) {
status = cf_util_get_boolean(child, &host->store_rates);
if (status != 0)
@@
-1120,16
+1119,17
@@
static int sensu_config_node(oconfig_item_t *ci) /* {{{ */
return -1;
}
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;
}
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");
WARNING("write_sensu plugin: MetricHandler given so forcing metrics to be "
"enabled");
- host->metrics =
1
;
+ host->metrics =
true
;
}
if (!(host->notifications || host->metrics)) {
}
if (!(host->notifications || host->metrics)) {
@@
-1221,10
+1221,10
@@
static int sensu_config(oconfig_item_t *ci) /* {{{ */
continue;
status = add_str_to_list(&sensu_tags_arr, tmp);
continue;
status = add_str_to_list(&sensu_tags_arr, tmp);
+ DEBUG("write_sensu plugin: Got tag: %s", tmp);
sfree(tmp);
if (status != 0)
continue;
sfree(tmp);
if (status != 0)
continue;
- DEBUG("write_sensu plugin: Got tag: %s", tmp);
} else {
WARNING("write_sensu plugin: Ignoring unknown "
"configuration option \"%s\" at top level.",
} else {
WARNING("write_sensu plugin: Ignoring unknown "
"configuration option \"%s\" at top level.",