2 * collectd - src/entropy.c
3 * Copyright (C) 2008 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
25 #include "configfile.h"
26 #include "utils_ignorelist.h"
31 static ignorelist_t *il_host = NULL;
32 static ignorelist_t *il_plugin = NULL;
33 static ignorelist_t *il_type = NULL;
35 static const char *config_keys[] =
41 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
46 static int ignorelist_add_create (ignorelist_t **il_ptr, const char *entry)
55 il = ignorelist_create (/* ignore = */ 0);
58 ERROR ("filter_ignore plugin: ignorelist_create failed.");
64 status = ignorelist_add (il, entry);
67 ERROR ("filter_ignore plugin: ignorelist_add failed with error %i.",
73 } /* int ignorelist_add_create */
75 static int fi_config (const char *key, const char *value)
81 if (strcasecmp ("IgnoreHost", key) == 0)
82 status = ignorelist_add_create (&il_host, value);
83 else if (strcasecmp ("IgnorePlugin", key) == 0)
84 status = ignorelist_add_create (&il_plugin, value);
85 else if (strcasecmp ("IgnoreType", key) == 0)
86 status = ignorelist_add_create (&il_type, value);
91 status = status * (-1);
96 static int fi_filter (const data_set_t *ds, value_list_t *vl)
102 status = ignorelist_match (il_host, vl->host);
104 return (FILTER_IGNORE);
107 if (il_plugin != NULL)
109 char buffer[2 * DATA_MAX_NAME_LEN];
111 if (vl->plugin_instance[0] == 0)
112 sstrncpy (buffer, vl->plugin, sizeof (buffer));
114 ssnprintf (buffer, sizeof (buffer), "%s-%s",
115 vl->plugin, vl->plugin_instance);
117 status = ignorelist_match (il_plugin, buffer);
119 return (FILTER_IGNORE);
124 char buffer[2 * DATA_MAX_NAME_LEN];
126 if (vl->type_instance[0] == 0)
127 sstrncpy (buffer, vl->type, sizeof (buffer));
129 ssnprintf (buffer, sizeof (buffer), "%s-%s",
130 vl->type, vl->type_instance);
132 status = ignorelist_match (il_type, buffer);
134 return (FILTER_IGNORE);
138 } /* int fi_filter */
140 void module_register (void)
142 plugin_register_config ("filter_ignore", fi_config,
143 config_keys, config_keys_num);
144 plugin_register_filter ("filter_ignore", fi_filter);
145 } /* void module_register */
147 /* vim: set sw=2 sts=2 et fdm=marker : */