diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | doc/property_replacer.html | 5 | ||||
-rw-r--r-- | runtime/msg.c | 2 | ||||
-rw-r--r-- | template.c | 8 | ||||
-rw-r--r-- | template.h | 3 |
5 files changed, 17 insertions, 5 deletions
@@ -1,5 +1,9 @@ --------------------------------------------------------------------------- Version 3.20.1 [v3-stable] (rgerhards), 2008-11-?? +- enhance: regex nomatch option "ZERO" has been added + This allows to return the string 0 if a regular expression is + not found. This is probably useful for storing numerical values into + database columns. - doc update: documented how to specify multiple property replacer options + link to new online regex generator tool added - improved debug output for regular expressions inside property replacer diff --git a/doc/property_replacer.html b/doc/property_replacer.html index 0b4f1a01..2748dc89 100644 --- a/doc/property_replacer.html +++ b/doc/property_replacer.html @@ -219,10 +219,11 @@ that the first match is number 0, the second 1 and so on. Up to 10 matches (up to number 9) are supported. Please note that it would be more natural to have the match-number in front of submatch, but this would break backward-compatibility. So the match-number must be specified after "nomatch". -<p>nomatch is either "DFLT", "BLANK" or "FIELD" (all upper case!). It tells +<p>nomatch is either "DFLT", "BLANK", ZERO or "FIELD" (all upper case!). It tells what to use if no match is found. With "DFLT", the strig "**NO MATCH**" is used. This was the only supported value up to rsyslog 3.19.5. With "BLANK" -a blank text is used (""). Finally, "FIELD" uses the full property text +a blank text is used (""). With "ZERO", "0" is used. +Finally, "FIELD" uses the full property text instead of the expression. Some folks have requested that, so it seems to be useful. <p>The following is a sample of an ERE expression that takes the first diff --git a/runtime/msg.c b/runtime/msg.c index fcd4a6d3..c8dbf2c2 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -1936,6 +1936,8 @@ char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, } if(pTpe->data.field.nomatchAction == TPL_REGEX_NOMATCH_USE_DFLTSTR) return "**NO MATCH**"; + else if(pTpe->data.field.nomatchAction == TPL_REGEX_NOMATCH_USE_ZERO) + return "0"; else return ""; } @@ -558,13 +558,17 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl) pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_DFLTSTR; p += 4; /* eat indicator sequence */ } else if(p[0] == 'B' && p[1] == 'L' && p[2] == 'A' && p[3] == 'N' && p[4] == 'K' - && (p[5] == ',' || p[5] == ':')) { + && (p[5] == ',' || p[5] == ':')) { pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_BLANK; p += 5; /* eat indicator sequence */ } else if(p[0] == 'F' && p[1] == 'I' && p[2] == 'E' && p[3] == 'L' && p[4] == 'D' - && (p[5] == ',' || p[5] == ':')) { + && (p[5] == ',' || p[5] == ':')) { pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_WHOLE_FIELD; p += 5; /* eat indicator sequence */ + } else if(p[0] == 'Z' && p[1] == 'E' && p[2] == 'R' && p[3] == 'O' + && (p[4] == ',' || p[4] == ':')) { + pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_ZERO; + p += 4; /* eat indicator sequence */ } else if(p[0] == ',') { /* empty, use default */ pTpe->data.field.nomatchAction = TPL_REGEX_NOMATCH_USE_DFLTSTR; /* do NOT eat indicator sequence, as this was already eaten - the @@ -78,7 +78,8 @@ struct templateEntry { enum { TPL_REGEX_NOMATCH_USE_DFLTSTR = 0, /* use the (old style) default "**NO MATCH**" string */ TPL_REGEX_NOMATCH_USE_BLANK = 1, /* use a blank string */ - TPL_REGEX_NOMATCH_USE_WHOLE_FIELD = 2 /* use the full field contents that we were searching in*/ + TPL_REGEX_NOMATCH_USE_WHOLE_FIELD = 2, /* use the full field contents that we were searching in*/ + TPL_REGEX_NOMATCH_USE_ZERO = 3 /* use 0 (useful for numerical values) */ } nomatchAction; /**< what to do if we do not have a match? */ #endif |