Merge branch 'collectd-5.5' into collectd-5.6
authorFlorian Forster <octo@collectd.org>
Mon, 7 Nov 2016 07:43:17 +0000 (08:43 +0100)
committerFlorian Forster <octo@collectd.org>
Mon, 7 Nov 2016 07:48:45 +0000 (08:48 +0100)
configure.ac
src/apcups.c
src/modbus.c
src/write_kafka.c
src/write_riemann.c
src/write_riemann_threshold.c
src/write_riemann_threshold.h

index 7aa87b3..b0373ed 100644 (file)
@@ -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"
index af5f24c..70e7fce 100644 (file)
 /*
  * 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);
index 93fd54a..473a4ee 100644 (file)
 #include "collectd.h"
 
 #include "common.h"
+#include "configfile.h"
 #include "plugin.h"
 
-#include <netdb.h>
-
 #include <modbus.h>
+#include <netdb.h>
+#include <sys/socket.h>
 
 #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;
   }
 
index 0f28ed0..6d826c2 100644 (file)
@@ -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,
index 20f2e10..92c8d0c 100644 (file)
@@ -36,7 +36,6 @@
 #include "utils_complain.h"
 #include "write_riemann_threshold.h"
 
-#include <errno.h>
 #include <riemann/riemann-client.h>
 
 #define RIEMANN_HOST "localhost"
index f2ba9dc..d393994 100644 (file)
@@ -34,6 +34,8 @@
 #include "utils_threshold.h"
 #include "write_riemann_threshold.h"
 
+#include <ltdl.h>
+
 /*
  * Threshold management
  * ====================
index d3b3fe9..bae2b2a 100644 (file)
@@ -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 <ruben at rubenkerkhof.com>
+ **/
+
 #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 */