From b15b750a5d5510ee32feb5988814be123448c791 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 20 Oct 2008 08:40:58 +0200 Subject: [PATCH] filter_ignore plugin: Add a simple plugin to ignore specific identifiers. Still needs documentation and testing. --- configure.in | 2 + src/Makefile.am | 8 +++ src/filter_ignore.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 src/filter_ignore.c diff --git a/configure.in b/configure.in index d416e696..90ac4627 100644 --- a/configure.in +++ b/configure.in @@ -2791,6 +2791,7 @@ AC_PLUGIN([email], [yes], [EMail statistics]) 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]) @@ -2961,6 +2962,7 @@ Configuration: 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 b20d7009..2196d32c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -274,6 +274,14 @@ collectd_LDADD += "-dlopen" filecount.la 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 new file mode 100644 index 00000000..19588842 --- /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 + **/ + +#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 : */ -- 2.11.0