[collectd] [PATCH] stderr plugin: Added "stderr" plugin to log to stderr.

Sebastian Harl sh<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>tokkee.org
Sun Mar 25 23:40:02 CEST 2007


This plugin is heavily based on Florian's syslog plugin.

Signed-off-by: Sebastian Harl <sh.trailing-username(a)leading-domain.tokkee.org>
---
 configure.in    |    2 +
 src/Makefile.am |    8 +++++
 src/stderr.c    |   83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/syslog.c    |    2 +-
 4 files changed, 94 insertions(+), 1 deletions(-)

diff --git a/configure.in b/configure.in
index ff12f68..a155d16 100644
--- a/configure.in
+++ b/configure.in
@@ -1217,6 +1217,7 @@ AC_COLLECTD([ping],      [disable], [module], [ping statistics])
 AC_COLLECTD([processes], [disable], [module], [processes statistics])
 AC_COLLECTD([sensors],   [disable], [module], [lm_sensors statistics])
 AC_COLLECTD([serial],    [disable], [module], [serial statistics])
+AC_COLLECTD([stderr],    [disable], [module], [stderr log facility])
 AC_COLLECTD([swap],      [disable], [module], [swap statistics])
 AC_COLLECTD([syslog],    [disable], [module], [syslog log facility])
 AC_COLLECTD([tape],      [disable], [module], [tape statistics])
@@ -1279,6 +1280,7 @@ Configuration:
     processes . . . . . $enable_processes
     sensors . . . . . . $enable_sensors
     serial  . . . . . . $enable_serial
+    stderr  . . . . . . $enable_stderr
     swap  . . . . . . . $enable_swap
     syslog  . . . . . . $enable_syslog
     tape  . . . . . . . $enable_tape
diff --git a/src/Makefile.am b/src/Makefile.am
index adf83da..707969a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -432,6 +432,14 @@ swap_la_LDFLAGS += -lstatgrab
 endif
 endif
 
+if BUILD_MODULE_STDERR
+pkglib_LTLIBRARIES += stderr.la
+stderr_la_SOURCES = stderr.c
+stderr_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" stderr.la
+collectd_DEPENDENCIES += stderr.la
+endif
+
 if BUILD_MODULE_SYSLOG
 pkglib_LTLIBRARIES += syslog.la
 syslog_la_SOURCES = syslog.c
diff --git a/src/stderr.c b/src/stderr.c
new file mode 100644
index 0000000..30e50d9
--- /dev/null
+++ b/src/stderr.c
@@ -0,0 +1,83 @@
+/**
+ * collectd - src/stderr.c
+ * Copyright (C) 2007  Sebastian Harl
+ *
+ * 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
+ *
+ * Authors:
+ *   Sebastian Harl <sh at tokkee.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#if COLLECT_DEBUG
+static int log_level = LOG_DEBUG;
+#else
+static int log_level = LOG_INFO;
+#endif /* COLLECT_DEBUG */
+
+static const char *config_keys[] =
+{
+	"LogLevel"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static int stderr_config (const char *key, const char *value)
+{
+	if (0 == strcasecmp (key, "LogLevel")) {
+		if ((0 == strcasecmp (value, "emerg"))
+				|| (0 == strcasecmp (value, "alert"))
+				|| (0 == strcasecmp (value, "crit"))
+				|| (0 == strcasecmp (value, "err")))
+			log_level = LOG_ERR;
+		else if (0 == strcasecmp (value, "warning"))
+			log_level = LOG_WARNING;
+		else if (0 == strcasecmp (value, "notice"))
+			log_level = LOG_NOTICE;
+		else if (0 == strcasecmp (value, "info"))
+			log_level = LOG_INFO;
+#if COLLECT_DEBUG
+		else if (0 == strcasecmp (value, "debug"))
+			log_level = LOG_DEBUG;
+#endif /* COLLECT_DEBUG */
+		else
+			return 1;
+	}
+	else {
+		return -1;
+	}
+	return 0;
+} /* int stderr_config (const char *, const char *) */
+
+static void stderr_log (int severity, const char *msg)
+{
+	if (severity > log_level)
+		return;
+
+	fprintf (stderr, "%s\n", msg);
+	return;
+} /* void stderr_log (int, const char *) */
+
+void module_register (void)
+{
+	plugin_register_config ("stderr", stderr_config,
+			config_keys, config_keys_num);
+	plugin_register_log ("stderr", stderr_log);
+	return;
+} /* void module_register (void) */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+
diff --git a/src/syslog.c b/src/syslog.c
index bcf873e..9ad2608 100644
--- a/src/syslog.c
+++ b/src/syslog.c
@@ -51,7 +51,7 @@ static int sl_config (const char *key, const char *value)
 			log_level = LOG_NOTICE;
 		else if (strcasecmp (value, "info") == 0)
 			log_level = LOG_INFO;
-#if COLLECTD_DEBUG
+#if COLLECT_DEBUG
 		else if (strcasecmp (value, "debug") == 0)
 			log_level = LOG_DEBUG;
 #endif
-- 
1.4.4.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20070325/4bc20021/attachment.pgp


More information about the collectd mailing list