summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d9e0b91)
raw | patch | inline | side by side (parent: d9e0b91)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 14 Mar 2007 08:55:51 +0000 (09:55 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 14 Mar 2007 08:55:51 +0000 (09:55 +0100) |
configure.in | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/syslog.c | [new file with mode: 0644] | patch | blob |
diff --git a/configure.in b/configure.in
index 48029d05f6a65c7dd570e93fc9bab80666673c56..39c7e98bca68115562512f41cb29c295fe770059 100644 (file)
--- a/configure.in
+++ b/configure.in
AC_COLLECTD([sensors], [disable], [module], [lm_sensors statistics])
AC_COLLECTD([serial], [disable], [module], [serial statistics])
AC_COLLECTD([swap], [disable], [module], [swap statistics])
+AC_COLLECTD([syslog], [disable], [module], [syslog log facility])
AC_COLLECTD([tape], [disable], [module], [tape statistics])
AC_COLLECTD([traffic], [disable], [module], [system traffic statistics])
AC_COLLECTD([unixsock], [disable], [module], [UNIX socket plugin])
sensors . . . . . . $enable_sensors
serial . . . . . . $enable_serial
swap . . . . . . . $enable_swap
+ syslog . . . . . . $enable_syslog
tape . . . . . . . $enable_tape
traffic . . . . . . $enable_traffic
unixsock . . . . . $enable_unixsock
diff --git a/src/Makefile.am b/src/Makefile.am
index 17eb6091349d09936b771ed588a5bc3c91ad30b5..cbc92b270da7476f13017915f5b4353742019f69 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
endif
endif
+if BUILD_MODULE_SYSLOG
+pkglib_LTLIBRARIES += syslog.la
+syslog_la_SOURCES = syslog.c
+syslog_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" syslog.la
+collectd_DEPENDENCIES += syslog.la
+endif
+
if BUILD_MODULE_TAPE
pkglib_LTLIBRARIES += tape.la
tape_la_SOURCES = tape.c
diff --git a/src/syslog.c b/src/syslog.c
--- /dev/null
+++ b/src/syslog.c
@@ -0,0 +1,97 @@
+/**
+ * collectd - src/syslog.c
+ * Copyright (C) 2007 Florian 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
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * 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
+ *
+ * Authors:
+ * Florian Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#if HAVE_SYSLOG_H
+# include <syslog.h>
+#endif
+
+static int log_level = LOG_DEBUG;
+
+static const char *config_keys[] =
+{
+ "LogLevel"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
+
+static int sl_config (const char *key, const char *value)
+{
+ if (strcasecmp (key, "LogLevel") == 0)
+ {
+ if ((strcasecmp (value, "emerg") == 0)
+ || (strcasecmp (value, "alert") == 0)
+ || (strcasecmp (value, "crit") == 0)
+ || (strcasecmp (value, "err") == 0))
+ log_level = LOG_ERR;
+ else if (strcasecmp (value, "warning") == 0)
+ log_level = LOG_WARNING;
+ else if (strcasecmp (value, "notice") == 0)
+ log_level = LOG_NOTICE;
+ else if (strcasecmp (value, "info") == 0)
+ log_level = LOG_INFO;
+#if COLLECTD_DEBUG
+ else if (strcasecmp (value, "debug") == 0)
+ log_level = LOG_DEBUG;
+#endif
+ else
+ return (1);
+ }
+ else
+ return (-1);
+
+ return (0);
+} /* int sl_config */
+
+static int sl_init (void)
+{
+ openlog ("collectd", LOG_CONS | LOG_PID, LOG_DAEMON);
+
+ return (0);
+}
+
+static void sl_log (int sevetiry, const char *msg)
+{
+ if (sevetiry > log_level)
+ return;
+
+ syslog (sevetiry, "%s", msg);
+} /* void sl_log */
+
+static int sl_shutdown (void)
+{
+ closelog ();
+
+ return (0);
+}
+
+void module_register (void)
+{
+ plugin_register_config ("syslog", sl_config, config_keys, config_keys_num);
+ plugin_register_init ("syslog", sl_init);
+ plugin_register_log ("syslog", sl_log);
+ plugin_register_shutdown ("syslog", sl_shutdown);
+
+ return;
+} /* void module_register(void) */