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"
/*
* 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
/* 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;
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);
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));
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);
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);
#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 */
{
/* 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;
}
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,
#include "utils_complain.h"
#include "write_riemann_threshold.h"
-#include <errno.h>
#include <riemann/riemann-client.h>
#define RIEMANN_HOST "localhost"
#include "utils_threshold.h"
#include "write_riemann_threshold.h"
+#include <ltdl.h>
+
/*
* Threshold management
* ====================
+/**
+ * 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 */