author | Florian Forster <octo@noris.net> | |
Tue, 1 Apr 2008 13:05:45 +0000 (15:05 +0200) | ||
committer | Florian Forster <octo@noris.net> | |
Tue, 1 Apr 2008 13:05:45 +0000 (15:05 +0200) |
Conflicts:
configure.in
src/plugin.c
configure.in
src/plugin.c
1 | 2 | |||
---|---|---|---|---|
configure.in | patch | | diff1 | | diff2 | | blob | history |
src/common.c | patch | | diff1 | | diff2 | | blob | history |
src/hddtemp.c | patch | | diff1 | | diff2 | | blob | history |
src/plugin.c | patch | | diff1 | | diff2 | | blob | history |
src/unixsock.c | patch | | diff1 | | diff2 | | blob | history |
diff --combined configure.in
index 952f5c5d12bfd1966c7ce81e17fcd77a0125f63e,db344978d38a27dff2adecdc2f06f4c281176a16..766b6d6b554118ccd9311a9c80a05b1528c824c3
--- 1/configure.in
--- 2/configure.in
+++ b/configure.in
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
+AM_PROG_CC_C_O
AM_CONDITIONAL(COMPILER_IS_GCC, test "x$GCC" = "xyes")
dnl configure libtool
AC_HEADER_SYS_WAIT
AC_HEADER_DIRENT
- AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h)
+ AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h)
# For ping library
AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
#endif
])
-AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h sys/quota.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h kvm.h)
+AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h sys/quota.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h kvm.h wordexp.h)
# For the dns plugin
AC_CHECK_HEADERS(arpa/nameser.h)
[with_libresolv="no"])
AM_CONDITIONAL(BUILD_WITH_LIBRESOLV, test "x$with_libresolv" = "xyes")
+dnl Check for HAL (hardware abstraction library)
+with_libhal="yes"
+AC_CHECK_LIB(hal,libhal_device_property_exists,
+ [AC_DEFINE(HAVE_LIBHAL, 1, [Define to 1 if you have 'hal' library])],
+ [with_libhal="no"])
+if test "x$with_libhal" = "xyes"; then
+ PKG_PROG_PKG_CONFIG
+ if test "x$PKG_CONFIG" != "x"; then
+ BUILD_WITH_LIBHAL_CFLAGS="`pkg-config --cflags hal`"
+ BUILD_WITH_LIBHAL_LIBS="`pkg-config --libs hal`"
+ AC_SUBST(BUILD_WITH_LIBHAL_CFLAGS)
+ AC_SUBST(BUILD_WITH_LIBHAL_LIBS)
+ fi
+fi
m4_divert_once([HELP_WITH], [
collectd additional packages:])
librrd_cflags="-I$withval/include"
librrd_ldflags="-L$withval/lib"
with_rrdtool="yes"
+ else
+ with_rrdtool="$withval"
fi
], [with_rrdtool="yes"])
if test "x$with_rrdtool" = "xyes"
then
with_libcurl="no ($with_curl_config failed)"
else
- SAVE_CFLAGS=$CFLAGS
- CFLAGS="$CFLAGS $with_curl_cflags"
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_curl_cflags"
AC_CHECK_HEADERS(curl/curl.h, [], [with_libcurl="no (curl/curl.h not found)"], [])
- CFLAGS="$SAVE_CFLAGS"
+ CPPFLAGS="$SAVE_CPPFLAGS"
fi
fi
if test "x$with_libcurl" = "xyes"
[
with_libiokit="yes"
collectd_libiokit=1
-],
+],
[
with_libiokit="no"
collectd_libiokit=0
LDFLAGS="$LDFLAGS -L$withval/lib"
CPPFLAGS="$CPPFLAGS -I$withval/include"
with_libstatgrab="yes"
+ else
+ with_libstatgrab="$withval"
fi
],
[
then
with_libmysql="no"
else
- SAVE_CFLAGS=$CFLAGS
- CFLAGS="$CFLAGS $with_mysql_cflags"
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_mysql_cflags"
AC_CHECK_HEADERS(mysql/mysql.h, [], [with_libmysql="no (mysql/mysql.h not found)"], [])
- CFLAGS="$SAVE_CFLAGS"
+ CPPFLAGS="$SAVE_CPPFLAGS"
fi
fi
if test "x$with_libmysql" = "xyes"
then
with_liboping="no"
with_own_liboping="no"
- fi
+ else if test "x$withval" = "xyes"
+ then
+ with_liboping="yes"
+ fi; fi
],
[
- #753
with_liboping="yes"
])
LDFLAGS="$LDFLAGS -L$withval/lib"
CPPFLAGS="$CPPFLAGS -I$withval/include"
with_libpcap="yes"
+ else
+ with_libpcap="$withval"
fi
],
[
CPPFLAGS="$CPPFLAGS -I$withval/include"
perl_interpreter="$withval/bin/perl"
with_libperl="yes"
+ else
+ with_libperl="$withval"
fi
],
[
fi
AM_CONDITIONAL(BUILD_WITH_LIBPERL, test "x$with_libperl" = "xyes")
+if test "x$with_libperl" = "xyes"
+then
+ SAVE_CFLAGS=$CFLAGS
+ SAVE_LDFLAGS=$LDFLAGS
+ CFLAGS="$CFLAGS $PERL_CFLAGS"
+ LDFLAGS="$LDFLAGS $PERL_LDFLAGS"
+
+ AC_CACHE_CHECK([if perl supports ithreads],
+ [have_perl_ithreads],
+ AC_LINK_IFELSE(
+ AC_LANG_PROGRAM(
+ [[
+#include <EXTERN.h>
+#include <perl.h>
+#include <XSUB.h>
+
+#if !defined(USE_ITHREADS)
+# error "Perl does not support ithreads!"
+#endif /* !defined(USE_ITHREADS) */
+ ]],
+ [[ ]]),
+ [have_perl_ithreads="yes"],
+ [have_perl_ithreads="no"]
+ )
+ )
+
+ if test "x$have_perl_ithreads" = "xyes"
+ then
+ AC_DEFINE(HAVE_PERL_ITHREADS, 1, [Define if Perl supports ithreads.])
+ fi
+
+ CFLAGS=$SAVE_CFLAGS
+ LDFLAGS=$SAVE_LDFLAGS
+fi
+
AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to libiptc.])],
[
if test "x$withval" != "xno" && test "x$withval" != "xyes"
LDFLAGS="$LDFLAGS -L$withval/lib"
CPPFLAGS="$CPPFLAGS -I$withval/include"
with_libiptc="yes"
+ else
+ with_libiptc="$withval"
fi
],
[
- if test "x$ac_system" = "xLinux"
+ if test "x$ac_system" = "xLinux"
then
with_libiptc="yes"
else
with_snmp_libs=""
AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Path to the Net-SNMPD library.])],
[
- if test "x$withval" = "xno"
+ if test "x$withval" = "xno"
then
with_libnetsnmp="no"
else if test "x$withval" = "xyes"
then
with_libnetsnmp="yes"
else
- if test -x "$withval"
+ if test -x "$withval"
then
with_snmp_config="$withval"
with_libnetsnmp="yes"
then
with_libnetsnmp="no ($with_snmp_config failed)"
else
- SAVE_CFLAGS=$CFLAGS
- CFLAGS="$CFLAGS $with_snmp_cflags"
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_snmp_cflags"
AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"])
- CFLAGS="$SAVE_CFLAGS"
+ CPPFLAGS="$SAVE_CPPFLAGS"
fi
fi
if test "x$with_libnetsnmp" = "xyes"
fi
if test "x$with_libupsclient" = "xyes"
then
- SAVE_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS $with_upsclient_cflags"
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_upsclient_cflags"
AC_CHECK_HEADERS(upsclient.h, [], [with_libupsclient="no (upsclient.h not found)"])
- CFLAGS="$SAVE_CFLAGS"
+ CPPFLAGS="$SAVE_CPPFLAGS"
fi
if test "x$with_libupsclient" = "xyes"
then
fi
if test "x$with_libupsclient" = "xyes"
then
- AC_CHECK_TYPES([UPSCONN_t, UPSCONN], [], [],
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_upsclient_cflags"
+
+ AC_CHECK_TYPES([UPSCONN_t, UPSCONN], [], [],
[#include <stdlib.h>
#include <stdio.h>
#include <upsclient.h>])
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
fi
AM_CONDITIONAL(BUILD_WITH_LIBUPSCLIENT, test "x$with_libupsclient" = "xyes")
fi
AM_CONDITIONAL(BUILD_WITH_LIBNETLINK, test "x$with_libnetlink" = "xyes")
+dnl Check for libvirt and libxml2 libraries.
+with_libxml2="no (pkg-config isn't available)"
+with_libxml2_cflags=""
+with_libxml2_ldflags=""
+with_libvirt="no (pkg-config isn't available)"
+with_libvirt_cflags=""
+with_libvirt_ldflags=""
+PKG_PROG_PKG_CONFIG
+if test "x$PKG_CONFIG" != "x"
+then
+ pkg-config --exists 'libxml-2.0' 2>/dev/null
+ if test "$?" = "0"
+ then
+ with_libxml2="yes"
+ else
+ with_libxml2="no (pkg-config doesn't know library)"
+ fi
+
+ pkg-config --exists libvirt 2>/dev/null
+ if test "$?" = "0"
+ then
+ with_libvirt="yes"
+ else
+ with_libvirt="no (pkg-config doesn't know library)"
+ fi
+fi
+if test "x$with_libxml2" = "xyes"
+then
+ with_libxml2_cflags="`pkg-config --cflags libxml-2.0`"
+ if test $? -ne 0
+ then
+ with_libxml2="no"
+ fi
+ with_libxml2_ldflags="`pkg-config --libs libxml-2.0`"
+ if test $? -ne 0
+ then
+ with_libxml2="no"
+ fi
+fi
+if test "x$with_libxml2" = "xyes"
+then
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libxml2_cflags"
+
+ AC_CHECK_HEADERS(libxml/parser.h, [],
+ [with_libxml2="no (libxml/parser.h not found)"])
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+if test "x$with_libxml2" = "xyes"
+then
+ SAVE_CFLAGS="$CFLAGS"
+ SAVE_LD_FLAGS="$LDFLAGS"
+
+ CFLAGS="$CFLAGS $with_libxml2_cflags"
+ LDFLAGS="$LDFLAGS $with_libxml2_ldflags"
+
+ AC_CHECK_LIB(xml2, xmlXPathEval,
+ [with_libxml2="yes"],
+ [with_libxml2="no (symbol xmlXPathEval not found)"])
+
+ CFLAGS="$SAVE_CFLAGS"
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
+dnl Add the right compiler flags and libraries.
+if test "x$with_libxml2" = "xyes"; then
+ BUILD_WITH_LIBXML2_CFLAGS="$with_libxml2_cflags"
+ BUILD_WITH_LIBXML2_LIBS="$with_libxml2_ldflags"
+ AC_SUBST(BUILD_WITH_LIBXML2_CFLAGS)
+ AC_SUBST(BUILD_WITH_LIBXML2_LIBS)
+fi
+if test "x$with_libvirt" = "xyes"
+then
+ with_libvirt_cflags="`pkg-config --cflags libvirt`"
+ if test $? -ne 0
+ then
+ with_libvirt="no"
+ fi
+ with_libvirt_ldflags="`pkg-config --libs libvirt`"
+ if test $? -ne 0
+ then
+ with_libvirt="no"
+ fi
+fi
+if test "x$with_libvirt" = "xyes"
+then
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libvirt_cflags"
+
+ AC_CHECK_HEADERS(libvirt/libvirt.h, [],
+ [with_libvirt="no (libvirt/libvirt.h not found)"])
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+if test "x$with_libvirt" = "xyes"
+then
+ SAVE_CFLAGS="$CFLAGS"
+ SAVE_LD_FLAGS="$LDFLAGS"
+
+ CFLAGS="$CFLAGS $with_libvirt_cflags"
+ LDFLAGS="$LDFLAGS $with_libvirt_ldflags"
+
+ AC_CHECK_LIB(virt, virDomainBlockStats,
+ [with_libvirt="yes"],
+ [with_libvirt="no (symbol virDomainBlockStats not found)"])
+
+ CFLAGS="$SAVE_CFLAGS"
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
+dnl Add the right compiler flags and libraries.
+if test "x$with_libvirt" = "xyes"; then
+ BUILD_WITH_LIBVIRT_CFLAGS="$with_libvirt_cflags"
+ BUILD_WITH_LIBVIRT_LIBS="$with_libvirt_ldflags"
+ AC_SUBST(BUILD_WITH_LIBVIRT_CFLAGS)
+ AC_SUBST(BUILD_WITH_LIBVIRT_LIBS)
+fi
+
+dnl End of check for libvirt and libxml2 libraries.
+
# Check for enabled/disabled features
#
plugin_interface="no"
plugin_ipvs="no"
plugin_irq="no"
+plugin_libvirt="no"
plugin_load="no"
plugin_memory="no"
plugin_multimeter="no"
plugin_nfs="no"
+plugin_perl="no"
plugin_processes="no"
plugin_serial="no"
plugin_swap="no"
plugin_interface="yes"
fi
+if test "x$with_libxml2" = "xyes" && test "x$with_libvirt" = "xyes"
+then
+ plugin_libvirt="yes"
+fi
+
if test "x$have_getloadavg" = "xyes"
then
plugin_load="yes"
fi
+if test "x$have_libperl$have_perl_ithreads" = "xyesyes"
+then
+ plugin_perl="yes"
+fi
+
# Mac OS X memory interface
if test "x$have_host_statistics" = "xyes"
then
AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters])
AC_PLUGIN([ipvs], [$plugin_ipvs], [IPVS connection statistics])
AC_PLUGIN([irq], [$plugin_irq], [IRQ statistics])
+AC_PLUGIN([libvirt], [$plugin_libvirt], [Virtual machine statistics])
AC_PLUGIN([load], [$plugin_load], [System load])
AC_PLUGIN([logfile], [yes], [File logging plugin])
AC_PLUGIN([mbmon], [yes], [Query mbmond])
AC_PLUGIN([nginx], [$with_libcurl], [nginx statistics])
AC_PLUGIN([ntpd], [yes], [NTPd statistics])
AC_PLUGIN([nut], [$with_libupsclient], [Network UPS tools statistics])
-AC_PLUGIN([perl], [$with_libperl], [Embed a Perl interpreter])
+AC_PLUGIN([perl], [$plugin_perl], [Embed a Perl interpreter])
AC_PLUGIN([ping], [$with_liboping], [Network latency statistics])
AC_PLUGIN([processes], [$plugin_processes], [Process statistics])
AC_PLUGIN([rrdtool], [$with_rrdtool], [RRDTool output plugin])
AC_PLUGIN([tcpconns], [$plugin_tcpconns], [TCP connection statistics])
AC_PLUGIN([unixsock], [yes], [Unixsock communication plugin])
AC_PLUGIN([users], [$plugin_users], [User statistics])
+AC_PLUGIN([uuid], [yes], [UUID as hostname plugin])
AC_PLUGIN([vserver], [$plugin_vserver], [Linux VServer statistics])
AC_PLUGIN([wireless], [$plugin_wireless], [Wireless statistics])
AC_PLUGIN([xmms], [$with_libxmms], [XMMS statistics])
AC_OUTPUT(Makefile src/Makefile src/collectd.conf src/liboconfig/Makefile src/liboping/Makefile bindings/Makefile)
+if test "x$with_rrdtool" = "xyes" -a "x$librrd_threadsafe" != "xyes"
+then
+ with_rrdtool="yes (warning: librrd is not thread-safe)"
+fi
+
if test "x$with_liboping" = "xyes" -a "x$with_own_liboping" = "xyes"
then
with_liboping="yes (shipped version)"
libsensors . . . . $with_lm_sensors
libstatgrab . . . . $with_libstatgrab
libupsclient . . . $with_libupsclient
+ libvirt . . . . . . $with_libvirt
+ libxml2 . . . . . . $with_libxml2
libxmms . . . . . . $with_libxmms
Features:
iptables . . . . . $enable_iptables
ipvs . . . . . . . $enable_ipvs
irq . . . . . . . . $enable_irq
+ libvirt . . . . . . $enable_libvirt
load . . . . . . . $enable_load
logfile . . . . . . $enable_logfile
mbmon . . . . . . . $enable_mbmon
tcpconns . . . . . $enable_tcpconns
unixsock . . . . . $enable_unixsock
users . . . . . . . $enable_users
+ uuid . . . . . . . $enable_uuid
vserver . . . . . . $enable_vserver
wireless . . . . . $enable_wireless
xmms . . . . . . . $enable_xmms
diff --combined src/common.c
index a2c4794d6d4642dfd2da75eef7747e87849904ca,9314d814ad4d1e02bd5e5a57e361c59d0d801eca..5c3db5ddacb53677d83e4d519f8b0c7331852449
--- 1/src/common.c
--- 2/src/common.c
+++ b/src/common.c
/**
* collectd - src/common.c
- * Copyright (C) 2005-2007 Florian octo Forster
+ * Copyright (C) 2005-2008 Florian octo Forster
*
* 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
# include "config.h"
#endif
+ #include "collectd.h"
#include "common.h"
#include "plugin.h"
static pthread_mutex_t strerror_r_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
-void sstrncpy (char *d, const char *s, int len)
+char *sstrncpy (char *dest, const char *src, size_t n)
{
- strncpy (d, s, len);
- d[len - 1] = '\0';
-}
+ strncpy (dest, src, n);
+ dest[n - 1] = '\0';
+
+ return (dest);
+} /* char *sstrncpy */
char *sstrdup (const char *s)
{
return (-1);
}
- assert (nleft >= status);
+ assert ((0 > status) || (nleft >= (size_t)status));
nleft = nleft - status;
ptr = ptr + status;
char **fields, size_t fields_num,
const char *sep)
{
- int field_len;
- int sep_len;
+ size_t field_len;
+ size_t sep_len;
int i;
memset (dst, '\0', dst_len);
if (sep != NULL)
sep_len = strlen (sep);
- for (i = 0; i < fields_num; i++)
+ for (i = 0; i < (int)fields_num; i++)
{
if ((i > 0) && (sep_len > 0))
{
unsigned long long ntohll (unsigned long long n)
{
- #if __BYTE_ORDER == __BIG_ENDIAN
+ #if BYTE_ORDER == BIG_ENDIAN
return (n);
#else
return (((unsigned long long) ntohl (n)) << 32) + ntohl (n >> 32);
unsigned long long htonll (unsigned long long n)
{
- #if __BYTE_ORDER == __BIG_ENDIAN
+ #if BYTE_ORDER == BIG_ENDIAN
return (n);
#else
return (((unsigned long long) htonl (n)) << 32) + htonl (n >> 32);
return (status);
} /* int getpwnam_r */
-#endif
+#endif /* !HAVE_GETPWNAM_R */
+
+int notification_init (notification_t *n, int severity, const char *message,
+ const char *host,
+ const char *plugin, const char *plugin_instance,
+ const char *type, const char *type_instance)
+{
+ memset (n, '\0', sizeof (notification_t));
+
+ n->severity = severity;
+
+ if (message != NULL)
+ strncpy (n->message, message, sizeof (n->message));
+ if (host != NULL)
+ strncpy (n->host, host, sizeof (n->host));
+ if (plugin != NULL)
+ strncpy (n->plugin, plugin, sizeof (n->plugin));
+ if (plugin_instance != NULL)
+ strncpy (n->plugin_instance, plugin_instance,
+ sizeof (n->plugin_instance));
+ if (type != NULL)
+ strncpy (n->type, type, sizeof (n->type));
+ if (type_instance != NULL)
+ strncpy (n->type_instance, type_instance,
+ sizeof (n->type_instance));
+
+ n->message[sizeof (n->message) - 1] = '\0';
+ n->host[sizeof (n->host) - 1] = '\0';
+ n->plugin[sizeof (n->plugin) - 1] = '\0';
+ n->plugin_instance[sizeof (n->plugin_instance) - 1] = '\0';
+ n->type[sizeof (n->type) - 1] = '\0';
+ n->type_instance[sizeof (n->type_instance) - 1] = '\0';
+
+ return (0);
+} /* int notification_init */
diff --combined src/hddtemp.c
index 651de298877a3c9848f05e17d79ea7a67e34ebaa,09f6bbe673a1b84328b3b4e95fbc18141abeea72..36ada53c4b2b673375e9a7982f3b62dd7dff383b
--- 1/src/hddtemp.c
--- 2/src/hddtemp.c
+++ b/src/hddtemp.c
{
"Host",
"Port",
- NULL
+ "TranslateDevicename"
};
-static int config_keys_num = 2;
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
typedef struct hddname
{
static hddname_t *first_hddname = NULL;
static char *hddtemp_host = NULL;
static char hddtemp_port[16];
+static int translate_devicename = 1;
/*
* NAME
if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
{
char errbuf[1024];
- ERROR ("hddtemp: getaddrinfo (%s, %s): %s",
+ ERROR ("hddtemp plugin: getaddrinfo (%s, %s): %s",
host, port,
(ai_return == EAI_SYSTEM)
? sstrerror (errno, errbuf, sizeof (errbuf))
for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
/* create our socket descriptor */
- if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0)
+ fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
+ ai_ptr->ai_protocol);
+ if (fd < 0)
{
char errbuf[1024];
- ERROR ("hddtemp: socket: %s",
+ ERROR ("hddtemp plugin: socket: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
continue;
}
/* connect to the hddtemp daemon */
- if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen))
+ if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr,
+ ai_ptr->ai_addrlen))
{
char errbuf[1024];
- INFO ("hddtemp: connect (%s, %s): %s", host, port,
+ INFO ("hddtemp plugin: connect (%s, %s) failed: %s",
+ host, port,
sstrerror (errno, errbuf, sizeof (errbuf)));
close (fd);
fd = -1;
if (fd < 0)
{
- ERROR ("hddtemp: Could not connect to daemon.");
+ ERROR ("hddtemp plugin: Could not connect to daemon.");
return (-1);
}
if ((errno == EAGAIN) || (errno == EINTR))
continue;
- ERROR ("hddtemp: Error reading from socket: %s",
+ ERROR ("hddtemp plugin: Error reading from socket: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
close (fd);
return (-1);
if (buffer_fill >= buffer_size)
{
buffer[buffer_size - 1] = '\0';
- WARNING ("hddtemp: Message from hddtemp has been truncated.");
+ WARNING ("hddtemp plugin: Message from hddtemp has been "
+ "truncated.");
}
else if (buffer_fill == 0)
{
- WARNING ("hddtemp: Peer has unexpectedly shut down the socket. "
- "Buffer: `%s'", buffer);
+ WARNING ("hddtemp plugin: Peer has unexpectedly shut down "
+ "the socket. Buffer: `%s'", buffer);
close (fd);
return (-1);
}
strncpy (hddtemp_port, value, sizeof (hddtemp_port));
hddtemp_port[sizeof (hddtemp_port) - 1] = '\0';
}
+ else if (strcasecmp (key, "TranslateDevicename") == 0)
+ {
+ if ((strcasecmp ("true", value) == 0)
+ || (strcasecmp ("yes", value) == 0)
+ || (strcasecmp ("on", value) == 0))
+ translate_devicename = 1;
+ else
+ translate_devicename = 0;
+ }
else
{
return (-1);
if ((fh = fopen ("/proc/partitions", "r")) != NULL)
{
- DEBUG ("Looking at /proc/partitions...");
+ DEBUG ("hddtemp plugin: Looking at /proc/partitions...");
while (fgets (buf, sizeof (buf), fh) != NULL)
{
/* Skip all other majors. */
default:
- DEBUG ("Skipping unknown major %i", major);
+ DEBUG ("hddtemp plugin: Skipping unknown major %i", major);
continue;
} /* switch (major) */
if ((name = strdup (fields[3])) == NULL)
{
- ERROR ("hddtemp: strdup(%s) == NULL", fields[3]);
+ ERROR ("hddtemp plugin: strdup(%s) == NULL", fields[3]);
continue;
}
if ((entry = (hddname_t *) malloc (sizeof (hddname_t))) == NULL)
{
- ERROR ("hddtemp: malloc (%u) == NULL",
+ ERROR ("hddtemp plugin: malloc (%u) == NULL",
(unsigned int) sizeof (hddname_t));
free (name);
continue;
}
- DEBUG ("Found disk: %s (%u:%u).", name, major, minor);
+ DEBUG ("hddtemp plugin: Found disk: %s (%u:%u).", name, major, minor);
entry->major = major;
entry->minor = minor;
else
{
char errbuf[1024];
- DEBUG ("Could not open /proc/partitions: %s",
+ DEBUG ("hddtemp plugin: Could not open /proc/partitions: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
}
#endif /* COLLECT_DEBUG */
} /* int hddtemp_init */
/*
- * hddtemp_get_name
+ * hddtemp_get_major_minor
*
* Description:
* Try to "cook" a bit the drive name as returned
* by the hddtemp daemon. The intend is to transform disk
* names into <major>-<minor> when possible.
*/
-static char *hddtemp_get_name (char *drive)
+static char *hddtemp_get_major_minor (char *drive)
{
hddname_t *list;
char *ret;
if (list == NULL)
{
- DEBUG ("Don't know %s, keeping name as-is.", drive);
+ DEBUG ("hddtemp plugin: Don't know %s, keeping name as-is.", drive);
return (strdup (drive));
}
for (i = 0; i < num_disks; i++)
{
- char *name, *submit_name;
+ char *name, *major_minor;
double temperature;
char *mode;
if (mode[0] == 'F')
temperature = (temperature - 32.0) * 5.0 / 9.0;
- if ((submit_name = hddtemp_get_name (name)) != NULL)
+ if (translate_devicename
+ && (major_minor = hddtemp_get_major_minor (name)) != NULL)
{
- hddtemp_submit (submit_name, temperature);
- free (submit_name);
+ hddtemp_submit (major_minor, temperature);
+ free (major_minor);
}
else
{
diff --combined src/plugin.c
index 0570f0ee0dc37269ce66fb724fe7f6abd64ac7dc,7d2bb57f09e01c0b6746d0e1608e307839b4aae5..8b2803dfa49b345b95d4da9f586740e6105af69a
--- 1/src/plugin.c
--- 2/src/plugin.c
+++ b/src/plugin.c
#include "common.h"
#include "plugin.h"
#include "configfile.h"
+#include "utils_avltree.h"
#include "utils_llist.h"
+#include "utils_cache.h"
+#include "utils_threshold.h"
/*
* Private structures
static llist_t *list_read;
static llist_t *list_write;
static llist_t *list_shutdown;
-static llist_t *list_data_set;
static llist_t *list_log;
+static llist_t *list_notification;
+
+static c_avl_tree_t *data_sets;
static char *plugindir = NULL;
static int register_callback (llist_t **list, const char *name, void *callback)
{
llentry_t *le;
+ char *key;
if ((*list == NULL)
&& ((*list = llist_create ()) == NULL))
le = llist_search (*list, name);
if (le == NULL)
{
- le = llentry_create (name, callback);
+ key = strdup (name);
+ if (key == NULL)
+ return (-1);
+
+ le = llentry_create (key, callback);
if (le == NULL)
+ {
+ free (key);
return (-1);
+ }
llist_append (*list, le);
}
return (-1);
llist_remove (list, e);
+ free (e->key);
llentry_destroy (e);
return (0);
pthread_mutex_unlock (&read_lock);
pthread_exit (NULL);
+ return ((void *) 0);
} /* void *plugin_read_thread */
static void start_threads (int num)
{
DIR *dh;
const char *dir;
- char filename[BUFSIZE];
+ char filename[BUFSIZE] = "";
char typename[BUFSIZE];
int typename_len;
int ret;
closedir (dh);
+ if (filename[0] == '\0')
+ fprintf (stderr, "Could not find plugin %s.\n", type);
+
return (ret);
}
data_set_t *ds_copy;
int i;
- if ((list_data_set != NULL)
- && (llist_search (list_data_set, ds->type) != NULL))
+ if ((data_sets != NULL)
+ && (c_avl_get (data_sets, ds->type, NULL) == 0))
{
NOTICE ("Replacing DS `%s' with another version.", ds->type);
plugin_unregister_data_set (ds->type);
}
+ else if (data_sets == NULL)
+ {
+ data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
+ if (data_sets == NULL)
+ return (-1);
+ }
ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
if (ds_copy == NULL)
for (i = 0; i < ds->ds_num; i++)
memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
- return (register_callback (&list_data_set, ds->type, (void *) ds_copy));
+ return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
} /* int plugin_register_data_set */
int plugin_register_log (char *name,
return (register_callback (&list_log, name, (void *) callback));
} /* int plugin_register_log */
+int plugin_register_notification (const char *name,
+ int (*callback) (const notification_t *notif))
+{
+ return (register_callback (&list_notification, name, (void *) callback));
+} /* int plugin_register_log */
+
int plugin_unregister_config (const char *name)
{
cf_unregister (name);
llist_remove (list_read, e);
free (e->value);
+ free (e->key);
llentry_destroy (e);
return (0);
int plugin_unregister_data_set (const char *name)
{
- llentry_t *e;
data_set_t *ds;
- if (list_data_set == NULL)
+ if (data_sets == NULL)
return (-1);
- e = llist_search (list_data_set, name);
-
- if (e == NULL)
+ if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
return (-1);
- llist_remove (list_data_set, e);
- ds = (data_set_t *) e->value;
- llentry_destroy (e);
-
sfree (ds->ds);
sfree (ds);
return (plugin_unregister (list_log, name));
}
+int plugin_unregister_notification (const char *name)
+{
+ return (plugin_unregister (list_notification, name));
+}
+
void plugin_init_all (void)
{
int (*callback) (void);
start_threads ((num > 0) ? num : 5);
}
+ /* Init the value cache */
+ uc_init ();
+
if (list_init == NULL)
return;
}
} /* void plugin_init_all */
-void plugin_read_all (const int *loop)
+void plugin_read_all (void)
{
llentry_t *le;
read_func_t *rf;
+ uc_check_timeout ();
+
if (list_read == NULL)
return;
data_set_t *ds;
llentry_t *le;
- if ((list_write == NULL) || (data_sets == NULL))
+ if (list_write == NULL)
+ {
+ ERROR ("plugin_dispatch_values: No write callback has been "
+ "registered. Please load at least one plugin "
+ "that provides a write function.");
+ return (-1);
+ }
+
- if (list_data_set == NULL)
++ if (data_sets == NULL)
+ {
+ ERROR ("plugin_dispatch_values: No data sets registered. "
+ "Could the types database be read? Check "
+ "your `TypesDB' setting!");
return (-1);
+ }
- le = llist_search (list_data_set, name);
- if (le == NULL)
+ if (c_avl_get (data_sets, name, (void *) &ds) != 0)
{
- DEBUG ("No such dataset registered: %s", name);
+ INFO ("plugin_dispatch_values: Dataset not found: %s", name);
return (-1);
}
- DEBUG ("plugin: plugin_dispatch_values: time = %u; interval = %i; "
- ds = (data_set_t *) le->value;
-
+ DEBUG ("plugin_dispatch_values: time = %u; interval = %i; "
"host = %s; "
"plugin = %s; plugin_instance = %s; "
"type = %s; type_instance = %s;",
#else
if (ds->ds_num != vl->values_len)
{
- ERROR ("plugin: ds->type = %s: (ds->ds_num = %i) != "
+ ERROR ("plugin_dispatch_values: ds->type = %s: "
+ "(ds->ds_num = %i) != "
"(vl->values_len = %i)",
ds->type, ds->ds_num, vl->values_len);
return (-1);
escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
escape_slashes (vl->type_instance, sizeof (vl->type_instance));
+ /* Update the value cache */
+ uc_update (ds, vl);
+ ut_check_threshold (ds, vl);
+
le = llist_head (list_write);
while (le != NULL)
{
return (0);
} /* int plugin_dispatch_values */
+int plugin_dispatch_notification (const notification_t *notif)
+{
+ int (*callback) (const notification_t *);
+ llentry_t *le;
+ /* Possible TODO: Add flap detection here */
+
+ DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
+ "time = %u; host = %s;",
+ notif->severity, notif->message,
+ (unsigned int) notif->time, notif->host);
+
+ /* Nobody cares for notifications */
+ if (list_notification == NULL)
+ return (-1);
+
+ le = llist_head (list_notification);
+ while (le != NULL)
+ {
+ callback = (int (*) (const notification_t *)) le->value;
+ (*callback) (notif);
+
+ le = le->next;
+ }
+
+ return (0);
+} /* int plugin_dispatch_notification */
+
void plugin_log (int level, const char *format, ...)
{
char msg[512];
}
} /* void plugin_log */
-void plugin_complain (int level, complain_t *c, const char *format, ...)
-{
- char message[512];
- va_list ap;
-
- if (c->delay > 0)
- {
- c->delay--;
- return;
- }
-
- if (c->interval < interval_g)
- c->interval = interval_g;
- else
- c->interval *= 2;
-
- if (c->interval > 86400)
- c->interval = 86400;
-
- c->delay = c->interval / interval_g;
-
- va_start (ap, format);
- vsnprintf (message, 512, format, ap);
- message[511] = '\0';
- va_end (ap);
-
- plugin_log (level, message);
-}
-
-void plugin_relief (int level, complain_t *c, const char *format, ...)
-{
- char message[512];
- va_list ap;
-
- if (c->interval == 0)
- return;
-
- c->interval = 0;
-
- va_start (ap, format);
- vsnprintf (message, 512, format, ap);
- message[511] = '\0';
- va_end (ap);
-
- plugin_log (level, message);
-}
-
const data_set_t *plugin_get_ds (const char *name)
{
data_set_t *ds;
- llentry_t *le;
- le = llist_search (list_data_set, name);
- if (le == NULL)
+ if (c_avl_get (data_sets, name, (void *) &ds) != 0)
{
DEBUG ("No such dataset registered: %s", name);
return (NULL);
}
- ds = (data_set_t *) le->value;
-
return (ds);
} /* data_set_t *plugin_get_ds */
diff --combined src/unixsock.c
index 9fa0259685c39c90799b9963fde732dd57783605,f8c9fbfd579e7013a9d1d700d5a595872b83492c..45ed9c699b783fa9e9e10a4dfd482a594e59d1a4
--- 1/src/unixsock.c
--- 2/src/unixsock.c
+++ b/src/unixsock.c
/**
* collectd - src/unixsock.c
- * Copyright (C) 2007 Florian octo Forster
+ * Copyright (C) 2007,2008 Florian octo Forster
*
* 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
#include "common.h"
#include "plugin.h"
#include "configfile.h"
+
#include "utils_cmd_putval.h"
+#include "utils_cmd_putnotif.h"
/* Folks without pthread will need to disable this plugin. */
#include <pthread.h>
/* Linked list and auxilliary variables for saving values */
static value_cache_t *cache_head = NULL;
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
-static unsigned int cache_oldest = UINT_MAX;
+static time_t cache_oldest = -1;
/*
* Functions
cache_head = vc;
vc->time = vl->time;
- if (vc->time < cache_oldest)
+ if ((vc->time < cache_oldest) || (-1 == cache_oldest))
cache_oldest = vc->time;
pthread_mutex_unlock (&cache_lock);
vc->ds = ds;
vc->time = vl->time;
- if (vc->time < cache_oldest)
+ if ((vc->time < cache_oldest) || (-1 == cache_oldest))
cache_oldest = vc->time;
pthread_mutex_unlock (&cache_lock);
{
us_handle_listval (fhout, fields, fields_num);
}
+ else if (strcasecmp (fields[0], "putnotif") == 0)
+ {
+ handle_putnotif (fhout, fields, fields_num);
+ }
else
{
fprintf (fhout, "-1 Unknown command: %s\n", fields[0]);
fclose (fhout);
pthread_exit ((void *) 0);
+ return ((void *) 0);
} /* void *us_handle_client */
static void *us_server_thread (void *arg)
}
plugin_unregister_init ("unixsock");
- plugin_unregister_write ("unixsock");
plugin_unregister_shutdown ("unixsock");
return (0);