summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4a73aa7)
raw | patch | inline | side by side (parent: 4a73aa7)
author | Peter Warasin <peter@endian.com> | |
Tue, 23 Mar 2010 20:55:54 +0000 (21:55 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Wed, 24 Mar 2010 15:39:42 +0000 (16:39 +0100) |
Hi Florian
Florian Forster wrote:
> On Fri, Mar 19, 2010 at 06:13:14PM +0100, Peter Warasin wrote:
>> I'm searching for something like "ExcludeRegExp".
>
> no, something like that doesn't exist yet. I like the idea though, so
> I've added it to the [[Roadmap]] wiki page.
Attached is a patch which implements this.
The patch is against 4.9.1
Please tell me if you want me to rebase it to current svn
kind regards,
peter
--
:: e n d i a n
:: open source - open minds
:: peter warasin
:: http://www.endian.com :: peter@endian.com
Adds ExcludeRegex to the tail-match plugin
With this keyword it is possible to exclude a line from a match.
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
Florian Forster wrote:
> On Fri, Mar 19, 2010 at 06:13:14PM +0100, Peter Warasin wrote:
>> I'm searching for something like "ExcludeRegExp".
>
> no, something like that doesn't exist yet. I like the idea though, so
> I've added it to the [[Roadmap]] wiki page.
Attached is a patch which implements this.
The patch is against 4.9.1
Please tell me if you want me to rebase it to current svn
kind regards,
peter
--
:: e n d i a n
:: open source - open minds
:: peter warasin
:: http://www.endian.com :: peter@endian.com
Adds ExcludeRegex to the tail-match plugin
With this keyword it is possible to exclude a line from a match.
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 844c83be05ba233202ccdc4069eee4838a481839..594e8574b5a6bfe4c9fb6ad8cf9cc7ba7c131fef 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
# </Match>
# <Match>
# Regex "\\<R=local_user\\>"
+# ExcludeRegex "\\<R=local_user\\>.*mail_spool defer"
# DSType "CounterInc"
# Type "counter"
# Instance "local_user"
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 2eb8d3043184c37b882a05cc50e5520d418d60cb..75681ca1915ae2bb7f40f9a738ecb7caab6284e4 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
</Match>
<Match>
Regex "\\<R=local_user\\>"
+ ExcludeRegex "\\<R=local_user\\>.*mail_spool defer"
DSType "CounterInc"
Type "counter"
Instance "local_user"
Regex "SPAM \\(Score: (-?[0-9]+\\.[0-9]+)\\)"
+=item B<ExcludeRegex> I<regex>
+
+Sets an optional regular expression to use for excluding lines from the match.
+An example which excludes all connections from localhost from the match:
+
+ ExcludeRegex "127\\.0\\.0\\.1"
+
=item B<DSType> I<Type>
Sets how the values are cumulated. I<Type> is one of:
diff --git a/src/curl.c b/src/curl.c
index bc11c28afdaf149154e1f2bf83fd333769f4c6c1..6e2811c81d2555060755ea562297f7cbedefd76f 100644 (file)
--- a/src/curl.c
+++ b/src/curl.c
if (status != 0)
return (status);
- match->match = match_create_simple (match->regex, match->dstype);
+ match->match = match_create_simple (match->regex, NULL, match->dstype);
if (match->match == NULL)
{
ERROR ("curl plugin: tail_match_add_match_simple failed.");
diff --git a/src/memcachec.c b/src/memcachec.c
index 451a853852679d44daf2b613bac8914d9ea61e21..75e642702be38d2a8d5c058249a050eab243185a 100644 (file)
--- a/src/memcachec.c
+++ b/src/memcachec.c
if (status != 0)
return (status);
- match->match = match_create_simple (match->regex, match->dstype);
+ match->match = match_create_simple (match->regex, NULL, match->dstype);
if (match->match == NULL)
{
ERROR ("memcachec plugin: tail_match_add_match_simple failed.");
diff --git a/src/tail.c b/src/tail.c
index 8becc05bc4a86cfcdda73195775ed7a1d5bdc76e..25cbcd4c1b5188df787e843c60aecb895aad5688 100644 (file)
--- a/src/tail.c
+++ b/src/tail.c
* Instance "exim"
* <Match>
* Regex "S=([1-9][0-9]*)"
+ * ExcludeRegex "U=root.*S="
* DSType "CounterAdd"
* Type "ipt_bytes"
* Instance "total"
struct ctail_config_match_s
{
char *regex;
+ char *excluderegex;
int flags;
char *type;
char *type_instance;
if (strcasecmp ("Regex", option->key) == 0)
status = ctail_config_add_string ("Regex", &cm.regex, option);
+ else if (strcasecmp ("ExcludeRegex", option->key) == 0)
+ status = ctail_config_add_string ("ExcludeRegex", &cm.excluderegex,
+ option);
else if (strcasecmp ("DSType", option->key) == 0)
status = ctail_config_add_match_dstype (&cm, option);
else if (strcasecmp ("Type", option->key) == 0)
if (status == 0)
{
- status = tail_match_add_match_simple (tm, cm.regex, cm.flags,
- "tail", plugin_instance, cm.type, cm.type_instance);
+ status = tail_match_add_match_simple (tm, cm.regex, cm.excluderegex,
+ cm.flags, "tail", plugin_instance, cm.type, cm.type_instance);
if (status != 0)
{
}
sfree (cm.regex);
+ sfree (cm.excluderegex);
sfree (cm.type);
sfree (cm.type_instance);
diff --git a/src/utils_match.c b/src/utils_match.c
index bdbad3f213155a544b8d06009aa90c7322e7522c..0f87bc0c56d7810908320296e7b6f97c2ef2b338 100644 (file)
--- a/src/utils_match.c
+++ b/src/utils_match.c
#include <regex.h>
#define UTILS_MATCH_FLAGS_FREE_USER_DATA 0x01
+#define UTILS_MATCH_FLAGS_EXCLUDE_REGEX 0x02
struct cu_match_s
{
regex_t regex;
+ regex_t excluderegex;
int flags;
int (*callback) (const char *str, char * const *matches, size_t matches_num,
/*
* Public functions
*/
-cu_match_t *match_create_callback (const char *regex,
+cu_match_t *match_create_callback (const char *regex, const char *excluderegex,
int (*callback) (const char *str,
char * const *matches, size_t matches_num, void *user_data),
void *user_data)
cu_match_t *obj;
int status;
- DEBUG ("utils_match: match_create_callback: regex = %s", regex);
+ DEBUG ("utils_match: match_create_callback: regex = %s, excluderegex = %s",
+ regex, excluderegex);
obj = (cu_match_t *) malloc (sizeof (cu_match_t));
if (obj == NULL)
return (NULL);
}
+ if (excluderegex && strcmp(excluderegex, "") != 0) {
+ status = regcomp (&obj->excluderegex, excluderegex, REG_EXTENDED);
+ if (status != 0)
+ {
+ ERROR ("Compiling the excluding regular expression \"%s\" failed.",
+ excluderegex);
+ sfree (obj);
+ return (NULL);
+ }
+ obj->flags |= UTILS_MATCH_FLAGS_EXCLUDE_REGEX;
+ }
+
obj->callback = callback;
obj->user_data = user_data;
return (obj);
} /* cu_match_t *match_create_callback */
-cu_match_t *match_create_simple (const char *regex, int match_ds_type)
+cu_match_t *match_create_simple (const char *regex,
+ const char *excluderegex, int match_ds_type)
{
cu_match_value_t *user_data;
cu_match_t *obj;
memset (user_data, '\0', sizeof (cu_match_value_t));
user_data->ds_type = match_ds_type;
- obj = match_create_callback (regex, default_callback, user_data);
+ obj = match_create_callback (regex, excluderegex,
+ default_callback, user_data);
if (obj == NULL)
{
sfree (user_data);
if ((obj == NULL) || (str == NULL))
return (-1);
+ if (obj->flags & UTILS_MATCH_FLAGS_EXCLUDE_REGEX) {
+ status = regexec (&obj->excluderegex, str,
+ STATIC_ARRAY_SIZE (re_match), re_match,
+ /* eflags = */ 0);
+ /* Regex did match, so exclude this line */
+ if (status == 0) {
+ DEBUG("ExludeRegex matched, don't count that line\n");
+ return (0);
+ }
+ }
+
status = regexec (&obj->regex, str,
STATIC_ARRAY_SIZE (re_match), re_match,
/* eflags = */ 0);
diff --git a/src/utils_match.h b/src/utils_match.h
index 5a0c0337fe6b14591a93ecfc256d61ecf81a26c5..9e47d5c52e8c8476601b9476a3ae0e66a25d7f64 100644 (file)
--- a/src/utils_match.h
+++ b/src/utils_match.h
* then only the submatch (the part in the parenthesis) will be passed to the
* callback. If there is no submatch, then the entire string is passed to the
* callback.
+ * The optional `excluderegex' allows to exclude the line from the match, if
+ * the excluderegex matches.
*/
-cu_match_t *match_create_callback (const char *regex,
+cu_match_t *match_create_callback (const char *regex, const char *excluderegex,
int (*callback) (const char *str,
char * const *matches, size_t matches_num, void *user_data),
void *user_data);
* The function will not search for anything in the string and increase
* value.counter by one.
*/
-cu_match_t *match_create_simple (const char *regex, int ds_type);
+cu_match_t *match_create_simple (const char *regex,
+ const char *excluderegex, int ds_type);
/*
* NAME
diff --git a/src/utils_tail_match.c b/src/utils_tail_match.c
index 22c7917943524ed3c3ee06415cc3159b3ab61892..8ae2208cc1e2138e9c304930e016d039c7dfb480 100644 (file)
--- a/src/utils_tail_match.c
+++ b/src/utils_tail_match.c
} /* int tail_match_add_match */
int tail_match_add_match_simple (cu_tail_match_t *obj,
- const char *regex, int ds_type,
+ const char *regex, const char *excluderegex, int ds_type,
const char *plugin, const char *plugin_instance,
const char *type, const char *type_instance)
{
cu_tail_match_simple_t *user_data;
int status;
- match = match_create_simple (regex, ds_type);
+ match = match_create_simple (regex, excluderegex, ds_type);
if (match == NULL)
return (-1);
diff --git a/src/utils_tail_match.h b/src/utils_tail_match.h
index d08c728eb4fef8b881df8aabbdb9aa6903d04b2d..765974576660449c3887707007afc1edf8a6ea1e 100644 (file)
--- a/src/utils_tail_match.h
+++ b/src/utils_tail_match.h
* The values gathered are dispatched by the tail_match module in this case. The
* passed `plugin', `plugin_instance', `type', and `type_instance' are
* directly used when submitting these values.
+ * With excluderegex it is possible to exlude lines from the match.
*
* RETURN VALUE
* Zero upon success, non-zero otherwise.
*/
int tail_match_add_match_simple (cu_tail_match_t *obj,
- const char *regex, int ds_type,
+ const char *regex, const char *excluderegex, int ds_type,
const char *plugin, const char *plugin_instance,
const char *type, const char *type_instance);