Code

syslog plugin: Added plugin to log to syslog.
authorSebastian Harl <sh@tokkee.org>
Wed, 10 Jul 2013 14:55:16 +0000 (16:55 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 10 Jul 2013 14:55:16 +0000 (16:55 +0200)
configure.ac
src/Makefile.am
src/daemon/sysdbd.conf.sample
src/plugins/syslog.c [new file with mode: 0644]

index e967867e68c6baadc6faf4bf42f8841a4c0d488b..6847c08c9da269681eddfcc3c269bb110314e10d 100644 (file)
@@ -244,6 +244,8 @@ AC_SDB_PLUGIN([mk-livestatus], [yes],
                [backend accessing Nagios/Icinga/Shinken using MK Livestatus])
 AC_SDB_PLUGIN([puppet-storeconfigs], [$puppet_storeconfigs_default],
                [backend accessing the Puppet stored configuration database])
                [backend accessing Nagios/Icinga/Shinken using MK Livestatus])
 AC_SDB_PLUGIN([puppet-storeconfigs], [$puppet_storeconfigs_default],
                [backend accessing the Puppet stored configuration database])
+AC_SDB_PLUGIN([syslog], [yes],
+               [plugin logging to syslog])
 
 AM_CONDITIONAL([BUILD_DOCUMENTATION], test "x$build_documentation" = "xyes")
 
 
 AM_CONDITIONAL([BUILD_DOCUMENTATION], test "x$build_documentation" = "xyes")
 
index 35ac77d7f4db9634d8c811f4427ff85ac256aed8..09b81b72727d33e625dad9cd65fc4ed30cb7dfbb 100644 (file)
@@ -55,6 +55,7 @@ pkgbackendlibdir = $(pkglibdir)/backend
 pkgbackendcollectdlibdir = $(pkgbackendlibdir)/collectd
 pkgbackendpuppetlibdir = $(pkgbackendlibdir)/puppet
 
 pkgbackendcollectdlibdir = $(pkgbackendlibdir)/collectd
 pkgbackendpuppetlibdir = $(pkgbackendlibdir)/puppet
 
+pkglib_LTLIBRARIES =
 pkgbackendlib_LTLIBRARIES =
 pkgbackendcollectdlib_LTLIBRARIES =
 pkgbackendpuppetlib_LTLIBRARIES =
 pkgbackendlib_LTLIBRARIES =
 pkgbackendcollectdlib_LTLIBRARIES =
 pkgbackendpuppetlib_LTLIBRARIES =
@@ -83,6 +84,14 @@ libsysdb_la_LIBADD += -dlopen backend/puppet/store-configs.la
 libsysdb_la_DEPENDENCIES += backend/puppet/store-configs.la
 endif
 
 libsysdb_la_DEPENDENCIES += backend/puppet/store-configs.la
 endif
 
+if BUILD_PLUGIN_SYSLOG
+pkglib_LTLIBRARIES += plugins/syslog.la
+plugins_syslog_la_SOURCE = plugins/syslog.c
+plugins_syslog_la_LDFLAGS = -module -avoid-version
+libsysdb_la_LIBADD += -dlopen plugins/syslog.la
+libsysdb_la_DEPENDENCIES += plugins/syslog.la
+endif
+
 include/sysdb.h: include/sysdb.h.in ../version
        source ../version; sed \
            -e "s/@SDB_VERSION_MAJOR@/$$VERSION_MAJOR/g" \
 include/sysdb.h: include/sysdb.h.in ../version
        source ../version; sed \
            -e "s/@SDB_VERSION_MAJOR@/$$VERSION_MAJOR/g" \
index 304b0bb4c9feb33d75671904417526a4c007c9cb..40210fad05d70403e7ddc7cab50e67565b0e0595 100644 (file)
 # default interval used for actively polling plugins
 Interval 300
 
 # default interval used for actively polling plugins
 Interval 300
 
+#----------------------------------------------------------------------------#
+# Logging settings:                                                          #
+# These plugins should be loaded first. Else, any log messages will be       #
+# written to the standard error channel which is closed after the daemon has #
+# started.                                                                   #
+#----------------------------------------------------------------------------#
+LoadPlugin "syslog"
+
 #----------------------------------------------------------------------------#
 # Plugins:                                                                   #
 # Plugins are the working horses of SysDB. Load any of the following plugins #
 #----------------------------------------------------------------------------#
 # Plugins:                                                                   #
 # Plugins are the working horses of SysDB. Load any of the following plugins #
diff --git a/src/plugins/syslog.c b/src/plugins/syslog.c
new file mode 100644 (file)
index 0000000..b548988
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * SysDB - src/plugins/syslog.c
+ * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "sysdb.h"
+#include "core/plugin.h"
+#include "core/error.h"
+
+#include <assert.h>
+#include <syslog.h>
+
+SDB_PLUGIN_MAGIC;
+
+#if (SDB_LOG_EMERG != LOG_EMERG) \
+               || (SDB_LOG_ERR != LOG_ERR) \
+               || (SDB_LOG_WARNING != LOG_WARNING) \
+               || (SDB_LOG_NOTICE != LOG_NOTICE) \
+               || (SDB_LOG_INFO != LOG_INFO) \
+               || (SDB_LOG_DEBUG != LOG_DEBUG)
+#      define SDB_LOG_PRIO_TO_SYSLOG(prio) \
+               (((prio) == SDB_LOG_EMERG) ? LOG_EMERG \
+                       : ((prio) == SDB_LOG_ERR) ? LOG_ERR \
+                       : ((prio) == SDB_LOG_WARNING) ? LOG_WARNING \
+                       : ((prio) == SDB_LOG_NOTICE) ? LOG_NOTICE \
+                       : ((prio) == SDB_LOG_INFO) ? LOG_INFO \
+                       : ((prio) == SDB_LOG_DEBUG) ? LOG_DEBUG : LOG_ERR)
+#else
+#      define SDB_LOG_PRIO_TO_SYSLOG(prio) (prio)
+#endif
+
+/*
+ * plugin API
+ */
+
+static int
+sdb_syslog_init(sdb_object_t __attribute__((unused)) *user_data)
+{
+       openlog("sysdbd", LOG_NDELAY | LOG_NOWAIT | LOG_PID, LOG_DAEMON);
+       return 0;
+} /* sdb_syslog_init */
+
+static int
+sdb_syslog_log(int prio, const char *msg,
+               sdb_object_t __attribute__((unused)) *user_data)
+{
+       syslog(SDB_LOG_PRIO_TO_SYSLOG(prio), "%s", msg);
+       return 0;
+} /* sdb_syslog_log */
+
+static int
+sdb_syslog_shutdown(sdb_object_t __attribute__((unused)) *user_data)
+{
+       closelog();
+       return 0;
+} /* sdb_syslog_shutdown */
+
+int
+sdb_module_init(sdb_plugin_info_t *info)
+{
+       sdb_plugin_set_info(info, SDB_PLUGIN_INFO_NAME, "syslog");
+       sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC,
+                       "log messages to the system logger");
+       sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT,
+                       "Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>");
+       sdb_plugin_set_info(info, SDB_PLUGIN_INFO_LICENSE, "BSD");
+       sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION);
+       sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
+
+       sdb_plugin_register_init("syslog", sdb_syslog_init, NULL);
+       sdb_plugin_register_log("syslog", sdb_syslog_log, NULL);
+       sdb_plugin_register_shutdown("syslog", sdb_syslog_shutdown, NULL);
+       return 0;
+} /* sdb_module_init */
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+