# </Match>
# <Match>
# Regex "\\<R=local_user\\>"
+# ExcludeRegex "\\<R=local_user\\>.*mail_spool defer"
# DSType "CounterInc"
# Type "counter"
# Instance "local_user"
</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:
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.");
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.");
* 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);
#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);
* 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
} /* 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);
* 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);