From: Florian Forster Date: Mon, 7 Nov 2016 07:43:17 +0000 (+0100) Subject: Merge branch 'collectd-5.5' into collectd-5.6 X-Git-Tag: collectd-5.6.2~10 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=1326af38b3ef25c41c994cd76c043202636b3d70;hp=4979d8dcd6f097eb8fd4661086e28accd31ff905;p=collectd.git Merge branch 'collectd-5.5' into collectd-5.6 --- diff --git a/configure.ac b/configure.ac index 7aa87b36..b0373ed0 100644 --- a/configure.ac +++ b/configure.ac @@ -4379,11 +4379,10 @@ then if test "x$with_librdkafka_log_cb" = "xyes" then AC_DEFINE(HAVE_LIBRDKAFKA_LOG_CB, 1, [Define if librdkafka log facility is present and usable.]) - fi - if test "x$with_librdkafka_logger" = "xyes" + else if test "x$with_librdkafka_logger" = "xyes" then AC_DEFINE(HAVE_LIBRDKAFKA_LOGGER, 1, [Define if librdkafka log facility is present and usable.]) - fi + fi; fi fi CPPFLAGS="$SAVE_CPPFLAGS" LDFLAGS="$SAVE_LDFLAGS" diff --git a/src/apcups.c b/src/apcups.c index af5f24c7..70e7fcea 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -55,17 +55,17 @@ /* * Private data types */ -struct apc_detail_s +typedef struct { - double linev; - double loadpct; - double bcharge; - double timeleft; - double outputv; - double itemp; - double battv; - double linefreq; -}; + gauge_t linev; + gauge_t loadpct; + gauge_t bcharge; + gauge_t timeleft; + gauge_t outputv; + gauge_t itemp; + gauge_t battv; + gauge_t linefreq; +} apc_detail_t; /* * Private variables @@ -253,14 +253,12 @@ static int net_send (int *sockfd, const char *buff, int len) /* Get and print status from apcupsd NIS server */ static int apc_query_server (char const *node, char const *service, - struct apc_detail_s *apcups_detail) + apc_detail_t *apcups_detail) { int n; char recvline[1024]; char *tokptr; char *toksaveptr; - char *key; - double value; _Bool retry = 1; int status; @@ -329,10 +327,13 @@ static int apc_query_server (char const *node, char const *service, tokptr = strtok_r (recvline, " :\t", &toksaveptr); while (tokptr != NULL) { - key = tokptr; + char *key = tokptr; if ((tokptr = strtok_r (NULL, " :\t", &toksaveptr)) == NULL) continue; - value = atof (tokptr); + + gauge_t value; + if (strtogauge (tokptr, &value) != 0) + continue; PRINT_VALUE (key, value); @@ -414,11 +415,14 @@ static int apcups_config (oconfig_item_t *ci) return (0); } /* int apcups_config */ -static void apc_submit_generic (const char *type, const char *type_inst, double value) +static void apc_submit_generic (const char *type, const char *type_inst, gauge_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; + if (isnan (value)) + return; + values[0].gauge = value; vl.values = values; @@ -432,7 +436,7 @@ static void apc_submit_generic (const char *type, const char *type_inst, double plugin_dispatch_values (&vl); } -static void apc_submit (struct apc_detail_s *apcups_detail) +static void apc_submit (apc_detail_t const *apcups_detail) { apc_submit_generic ("voltage", "input", apcups_detail->linev); apc_submit_generic ("voltage", "output", apcups_detail->outputv); @@ -446,33 +450,27 @@ static void apc_submit (struct apc_detail_s *apcups_detail) static int apcups_read (void) { - struct apc_detail_s apcups_detail; - int status; + apc_detail_t apcups_detail = { + .linev = NAN, + .outputv = NAN, + .battv = NAN, + .loadpct = NAN, + .bcharge = NAN, + .timeleft = NAN, + .itemp = NAN, + .linefreq = NAN, + }; - apcups_detail.linev = -1.0; - apcups_detail.outputv = -1.0; - apcups_detail.battv = -1.0; - apcups_detail.loadpct = -1.0; - apcups_detail.bcharge = -1.0; - apcups_detail.timeleft = NAN; - apcups_detail.itemp = -300.0; - apcups_detail.linefreq = -1.0; - - status = apc_query_server ((conf_node == NULL) ? APCUPS_DEFAULT_NODE : conf_node, - (conf_service == NULL) ? APCUPS_DEFAULT_SERVICE : conf_service, - &apcups_detail); - - /* - * if we did not connect then do not bother submitting - * zeros. We want rrd files to have NAN. - */ + int status = apc_query_server (conf_node == NULL + ? APCUPS_DEFAULT_NODE + : conf_node, + conf_service, &apcups_detail); if (status != 0) { - DEBUG ("apcups plugin: apc_query_server (%s, %s) = %i", - (conf_node == NULL) ? APCUPS_DEFAULT_NODE : conf_node, - (conf_service == NULL) ? APCUPS_DEFAULT_SERVICE : conf_service, - status); - return (-1); + DEBUG ("apcups plugin: apc_query_server (\"%s\", \"%s\") = %d", + conf_node == NULL ? APCUPS_DEFAULT_NODE : conf_node, + conf_service, status); + return (status); } apc_submit (&apcups_detail); diff --git a/src/modbus.c b/src/modbus.c index 93fd54a5..473a4ee4 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -23,11 +23,12 @@ #include "collectd.h" #include "common.h" +#include "configfile.h" #include "plugin.h" -#include - #include +#include +#include #ifndef LIBMODBUS_VERSION_CHECK /* Assume version 2.0.3 */ @@ -470,12 +471,9 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ } else if (host->conntype == MBCONN_TCP) { - struct sockaddr sockaddr; - socklen_t saddrlen = sizeof (sockaddr); - - status = getpeername (modbus_get_socket (host->connection), - &sockaddr, &saddrlen); - if (status != 0) + if (getpeername (modbus_get_socket (host->connection), + (void *) &(struct sockaddr_storage) {0}, + &(socklen_t) {sizeof(struct sockaddr_storage)}) != 0) status = errno; } diff --git a/src/write_kafka.c b/src/write_kafka.c index 0f28ed0d..6d826c25 100644 --- a/src/write_kafka.c +++ b/src/write_kafka.c @@ -60,7 +60,14 @@ static int kafka_write(const data_set_t *, const value_list_t *, user_data_t *); static int32_t kafka_partition(const rd_kafka_topic_t *, const void *, size_t, int32_t, void *, void *); -#if defined HAVE_LIBRDKAFKA_LOGGER || defined HAVE_LIBRDKAFKA_LOG_CB +/* Version 0.9.0 of librdkafka deprecates rd_kafka_set_logger() in favor of + * rd_kafka_conf_set_log_cb(). This is to make sure we're not using the + * deprecated function. */ +#ifdef HAVE_LIBRDKAFKA_LOG_CB +# undef HAVE_LIBRDKAFKA_LOGGER +#endif + +#if defined(HAVE_LIBRDKAFKA_LOGGER) || defined(HAVE_LIBRDKAFKA_LOG_CB) static void kafka_log(const rd_kafka_t *, int, const char *, const char *); static void kafka_log(const rd_kafka_t *rkt, int level, diff --git a/src/write_riemann.c b/src/write_riemann.c index 20f2e10b..92c8d0ca 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -36,7 +36,6 @@ #include "utils_complain.h" #include "write_riemann_threshold.h" -#include #include #define RIEMANN_HOST "localhost" diff --git a/src/write_riemann_threshold.c b/src/write_riemann_threshold.c index f2ba9dc8..d393994b 100644 --- a/src/write_riemann_threshold.c +++ b/src/write_riemann_threshold.c @@ -34,6 +34,8 @@ #include "utils_threshold.h" #include "write_riemann_threshold.h" +#include + /* * Threshold management * ==================== diff --git a/src/write_riemann_threshold.h b/src/write_riemann_threshold.h index d3b3fe9a..bae2b2ac 100644 --- a/src/write_riemann_threshold.h +++ b/src/write_riemann_threshold.h @@ -1,6 +1,36 @@ +/** + * collectd - src/write_riemann_threshold.h + * Copyright (C) 2016 Ruben Kerkhof + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Ruben Kerkhof + **/ + #ifndef WRITE_RIEMANN_THRESHOLD_H #define WRITE_RIEMANN_THRESHOLD_H -int write_riemann_threshold_check(const data_set_t *, const value_list_t *, int *); +#include "plugin.h" + +/* write_riemann_threshold_check tests all matching thresholds and returns the + * worst result for each data source in "statuses". "statuses" must point to + * ds->ds_num integers to which the result is written. + * + * Returns zero on success and if no threshold has been configured. Returns + * less than zero on failure. */ +int write_riemann_threshold_check(const data_set_t *ds, const value_list_t *vl, + int *statuses); -#endif +#endif /* WRITE_RIEMANN_THRESHOLD_H */