summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2f712e8)
raw | patch | inline | side by side (parent: 2f712e8)
author | Florian Forster <octo@huhu.verplant.org> | |
Mon, 20 Oct 2008 06:40:58 +0000 (08:40 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Mon, 20 Oct 2008 06:40:58 +0000 (08:40 +0200) |
Still needs documentation and testing.
configure.in | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/filter_ignore.c | [new file with mode: 0644] | patch | blob |
diff --git a/configure.in b/configure.in
index d416e696eeee7c990416cfcddd82cab317dd5ebe..90ac4627fc7731338ee6e12be2ac441991e91f6c 100644 (file)
--- a/configure.in
+++ b/configure.in
AC_PLUGIN([entropy], [$plugin_entropy], [Entropy statistics])
AC_PLUGIN([exec], [yes], [Execution of external programs])
AC_PLUGIN([filecount], [yes], [Count files in directories])
+AC_PLUGIN([filter_ignore], [yes], [Ignore specific values])
AC_PLUGIN([hddtemp], [yes], [Query hddtempd])
AC_PLUGIN([interface], [$plugin_interface], [Interface traffic statistics])
AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters])
entropy . . . . . . . $enable_entropy
exec . . . . . . . . $enable_exec
filecount . . . . . . $enable_filecount
+ filter_ignore . . . . $enable_filter_ignore
hddtemp . . . . . . . $enable_hddtemp
interface . . . . . . $enable_interface
iptables . . . . . . $enable_iptables
diff --git a/src/Makefile.am b/src/Makefile.am
index b20d7009391aa26ae178f109f08062f8b8e266b1..2196d32c87614d928291a99e911a0a8f33e417a4 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
collectd_DEPENDENCIES += filecount.la
endif
+if BUILD_PLUGIN_FILTER_IGNORE
+pkglib_LTLIBRARIES += filter_ignore.la
+filter_ignore_la_SOURCES = filter_ignore.c
+filter_ignore_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" filter_ignore.la
+collectd_DEPENDENCIES += filter_ignore.la
+endif
+
if BUILD_PLUGIN_HDDTEMP
pkglib_LTLIBRARIES += hddtemp.la
hddtemp_la_SOURCES = hddtemp.c
diff --git a/src/filter_ignore.c b/src/filter_ignore.c
--- /dev/null
+++ b/src/filter_ignore.c
@@ -0,0 +1,147 @@
+/**
+ * collectd - src/entropy.c
+ * Copyright (C) 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
+ * 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:
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+#include "utils_ignorelist.h"
+
+/*
+ * Variables
+ */
+static ignorelist_t *il_host = NULL;
+static ignorelist_t *il_plugin = NULL;
+static ignorelist_t *il_type = NULL;
+
+static const char *config_keys[] =
+{
+ "IgnoreHost",
+ "IgnorePlugin",
+ "IgnoreType"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+/*
+ * Functions
+ */
+static int ignorelist_add_create (ignorelist_t **il_ptr, const char *entry)
+{
+ ignorelist_t *il;
+ int status;
+
+ il = *il_ptr;
+
+ if (il == NULL)
+ {
+ il = ignorelist_create (/* ignore = */ 0);
+ if (il == NULL)
+ {
+ ERROR ("filter_ignore plugin: ignorelist_create failed.");
+ return (-1);
+ }
+ *il_ptr = il;
+ }
+
+ status = ignorelist_add (il, entry);
+ if (status != 0)
+ {
+ ERROR ("filter_ignore plugin: ignorelist_add failed with error %i.",
+ status);
+ return (status);
+ }
+
+ return (0);
+} /* int ignorelist_add_create */
+
+static int fi_config (const char *key, const char *value)
+{
+ int status;
+
+ status = 0;
+
+ if (strcasecmp ("IgnoreHost", key) == 0)
+ status = ignorelist_add_create (&il_host, value);
+ else if (strcasecmp ("IgnorePlugin", key) == 0)
+ status = ignorelist_add_create (&il_plugin, value);
+ else if (strcasecmp ("IgnoreType", key) == 0)
+ status = ignorelist_add_create (&il_type, value);
+ else
+ return (-1);
+
+ if (status < 0)
+ status = status * (-1);
+
+ return (status);
+} /* int fi_config */
+
+static int fi_filter (const data_set_t *ds, value_list_t *vl)
+{
+ int status;
+
+ if (il_host != NULL)
+ {
+ status = ignorelist_match (il_host, vl->host);
+ if (status != 0)
+ return (FILTER_IGNORE);
+ }
+
+ if (il_plugin != NULL)
+ {
+ char buffer[2 * DATA_MAX_NAME_LEN];
+
+ if (vl->plugin_instance[0] == 0)
+ sstrncpy (buffer, vl->plugin, sizeof (buffer));
+ else
+ ssnprintf (buffer, sizeof (buffer), "%s-%s",
+ vl->plugin, vl->plugin_instance);
+
+ status = ignorelist_match (il_plugin, buffer);
+ if (status != 0)
+ return (FILTER_IGNORE);
+ }
+
+ if (il_type != NULL)
+ {
+ char buffer[2 * DATA_MAX_NAME_LEN];
+
+ if (vl->type_instance[0] == 0)
+ sstrncpy (buffer, vl->type, sizeof (buffer));
+ else
+ ssnprintf (buffer, sizeof (buffer), "%s-%s",
+ vl->type, vl->type_instance);
+
+ status = ignorelist_match (il_type, buffer);
+ if (status != 0)
+ return (FILTER_IGNORE);
+ }
+
+ return (0);
+} /* int fi_filter */
+
+void module_register (void)
+{
+ plugin_register_config ("filter_ignore", fi_config,
+ config_keys, config_keys_num);
+ plugin_register_filter ("filter_ignore", fi_filter);
+} /* void module_register */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */