Code

Merge remote-tracking branch 'github/pr/1967'
authorFlorian Forster <octo@collectd.org>
Fri, 11 Nov 2016 20:24:21 +0000 (21:24 +0100)
committerFlorian Forster <octo@collectd.org>
Fri, 11 Nov 2016 20:24:21 +0000 (21:24 +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 55e80eb11f73f9860de232a1a7be06f8546ab962..ac738f80ff813201f43fce310f24a14e6bd642b2 100644 (file)
@@ -4567,11 +4567,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 937f2a0696052bb0c3ce16422e5a8bf42097e91c..50c45e7bdb051b8bca91f920b18aa1ebd1c2e4b7 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,10 +415,12 @@ 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_list_t vl = VALUE_LIST_INIT;
+       if (isnan (value))
+               return;
 
+       value_list_t vl = VALUE_LIST_INIT;
        vl.values = &(value_t) { .gauge = value };
        vl.values_len = 1;
        sstrncpy (vl.plugin, "apcups", sizeof (vl.plugin));
@@ -427,7 +430,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);
@@ -441,33 +444,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 a7d1b582c76fb27a3007aaad27a83abc60bd0616..589ce90fd2e2b85d86714f11f0ceb87ab34b573b 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 */
@@ -472,10 +473,9 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */
   {
     /* getpeername() is used only to determine if the socket is connected, not
      * because we're really interested in the peer's IP address. */
-    status = getpeername (modbus_get_socket (host->connection),
-        (struct sockaddr *) &(struct sockaddr_storage) { 0 },
-        &(socklen_t) { sizeof (struct sockaddr_storage) });
-    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 654db0a4afef495758215844d05fbb4597060714..6018fea05502f511a1ed8794f9f11982810e1a82 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 20f2e10b91b50b4fe0165db17dec7ff9b7449ef3..92c8d0caa11b571f4bd1cc957899cd33ff5d7b5e 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 f2ba9dc8c9609c2b26961cda2698ab391e90e1b1..d393994b6a7f8820699250a4d8d9bccd6fd86026 100644 (file)
@@ -34,6 +34,8 @@
 #include "utils_threshold.h"
 #include "write_riemann_threshold.h"
 
+#include <ltdl.h>
+
 /*
  * Threshold management
  * ====================
index d3b3fe9ab8fd7dc3ae9d46a148413feb3c5ea8fd..bae2b2ac1714504f6cfabb2e0ce94ed215549a23 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 */