The syslog-ng application can rewrite parts of log messages: it can search and replace text, and also set a specific field to a specified value. Rewriting messages is often used in conjunction with message parsing Section 8.6, “Message parsers”.
To create replace a part of the log message, define the string or regular expression to replace, the string to replace the original text (macros can be used as well), and the field of the message that the rewrite rule should process. Substitution rules can operate on any value available via macros, e.g., HOST, MESSAGE, PROGRAM, or any user-defined macros created using parsers (see Section 8.6, “Message parsers” for details).
As of syslog-ng 3.1, it is also possible to rewrite the structured-data fields of messages complying to the RFC5424 (IETF-syslog) message format. Substitution rules use the following syntax:
Declaration:
rewrite <name_of_the_rule>
{subst("<string or regular expression to find>", "<replacement string>", value(<field name>) type() flags());};
The type() and flags() options are
optional. The type() specifies the type of regular expression to
use; while the flags() are the flags of the regular expressions
(see Section 8.8, “Regular expressions” for details):
| Name | Description |
|---|---|
| posix | Use POSIX regular expressions. If the type()
parameter is not specified, syslog-ng uses POSIX regular expressions by
default. |
| pcre | Use PCRE regular expressions. This is available only if syslog-ng was
compiled with the --enable-pcre option. Execute
the syslog-ng -V command to list the options
supported by your binary. PCRE support is currently disabled in syslog-ng Premium Edition. |
| string | Match the strings literally, without regular expression support. By
default, only identical strings are matched. For partial matches, use
the flags("prefix") or the
flags("substring") flags. |
Table 8.22. Rewrite rule types
To set a field of the message to a specific value, define the string to include in the message, and the field where it should be included. Setting a field can operate on any value available via macros, e.g., HOST, MESSAGE, PROGRAM, or any user-defined macros created using parsers (see Section 8.6, “Message parsers” for details.). Note that this operation completely replaces any previous value of that field. Use the following syntax:
Declaration:
rewrite <name_of_the_rule>
{set("<string to include>", value(<field name>) flags());};
© 2007-2010 BalaBit IT Security
Please send your comments or documentation bugs to: documentation@balabit.com