Pattern parsers attempt to parse a part of the message using rules specific to the type of the parser. Parsers are enclosed between @ characters. The syntax of parsers is the following:
a beginning @ character;
the type of the parser written in capitals;
optionally a name;
parameters of the parser, if any;
a closing @ character.
![]() |
Example 8.31. Pattern parser syntax |
|---|---|
|
A simple parser: @STRING@ A named parser: @STRING:myparser_name@ A named parser with a parameter: @STRING:myparser_name:*@ A parser with a parameter, but without a name: @STRING::*@ |
The following parsers are available:
@ANYSTRING@: Parses everything to the end of the message;
you can use it to collect everything that is not parsed specifically to a single
macro. In that sense its behavior is similar to the
greedy() option of the CSV parser.
@DOUBLE@: An obsolete alias of the
@FLOAT@ parser.
@ESTRING@: This parser has a required parameter that acts
as the stopcharacter: the parser parses everything until it finds the
stopcharacter. For example to stop by the next " (double
quote) character, use @ESTRING::"@. As of syslog-ng 3.1,
it is possible to specify a stopstring instead of a single character, e.g.,
@ESTRING::stop_here.@.
@FLOAT@: A floating-point number that may contain a dot
(.) character. (Up to syslog-ng 3.1, the name of this parser was
@DOUBLE@.)
@IPv4@: Parses an IPv4 IP address (numbers separated with a maximum of 3 dots).
@IPv6@: Parses any valid IPv6 IP address.
@IPvANY@: Parses any IP address.
@NUMBER@: A sequence of decimal (0-9) numbers (e.g., 1, 0687, etc.). Note that if the number starts with the 0x characters, it is parsed as a hexadecimal number, but only if at least one valid character follows 0x.
@QSTRING@: Parse a string between the quote characters
specified as parameter. Note that the quote character can be different at the
beginning and the end of the quote, e.g.: @QSTRING::"@
parses everything between two quotation marks ("), while
@QSTRING:<>@ parses from an opening
bracket to the closing bracket.
@STRING@: A sequence of alphanumeric characters (0-9,
A-z), not including any whitespace. Optionally, other accepted characters can be
listed as parameters (e.g., to parse a complete sentence, add the whitespace as
parameter, like: @STRING:: @). Note that the
@ character cannot be a parameter, nor can line-breaks or
tabs.
Patterns and literals can be mixed together. For example, to parse a message that
begins with the Host: string followed by an IP address (e.g.,
Host: 192.168.1.1), the following pattern can be used:
Host:@IPv4@.
![]() |
Note |
|---|---|
Note that using parsers is a CPU-intensive operation. Use the ESTRING and QSTRING parsers whenever possible, as these can be processed much faster than the other parsers. |
![]() |
Example 8.32. Using the STRING and ESTRING parsers |
|---|---|
|
For example, if the message is Of course, usually it is better to parse the different values separately, like
this: If the username or the group may contain non-alphanumeric characters, you can
either include these in the second parameter of the parser (as shown at the
beginning of this example), or use an ESTRING parser to parse the message till the
next whitespace: |
The results of message classification and parsing can be used in custom
filters and file and database templates as well. There are two built-in macros
in syslog-ng that allow you to use the results of the classification: the
.classifier.class macro contains the class assigned
to the message (e.g., violation, security, or unknown), while the
.classifier.rule_id macro contains the identifier of
the message pattern that matched the message.
The message-segments parsed by the pattern parsers can also be used as macros as well. To accomplish this, you have to add a name to the parser, and then you can use this name as a macro that refers to the parsed value of the message.
![]() |
Note |
|---|---|
|
The above macros can be used in database columns and filename templates as well, if you create custom templates for the destination or logspace. Use a consistent naming scheme for your macros, for example,
|
Pattern databases are XML files that contain rules describing the message patterns.
The XML schema of the V1 pattern database used in syslog-ng OSE and PE 3.0.X is the following:
![]() |
Warning |
|---|---|
This is an experimental database format that will change in the future releases of syslog-ng. When the new format will be released, an upgrading script will be available to convert the existing databases to the new format. Note that the sample pattern databases available at the BalaBit website already use the new format (dubbed V2). |
: The container element of the pattern database. For example:
<patterndb version='1' pub_date='2008-08-25'>
version: The schema version of the pattern
database. The current version is 2.
pubdate: The publication date of the XML file.
: A container element to group log patterns for an application or program. For example:
<program name='su' id='480de478-d4a6-4a7f-bea4-0c0245d361e1'>
<patterndb> element may contain
any number of elements.
name: The name of the application. Note
that the function of this attribute is to make the database more
readable, syslog-ng uses the
<pattern> element to
identify the applications sending log messages.
id: A unique ID of the application, for
example, the md5 sum of the name
attribute.
: The name of the application
— syslog-ng matches this value to the $PROGRAM header
of the syslog message to find the rulesets applicable to the
syslog message. This element is also called program
pattern. E.g.,
<pattern>su</pattern>
: OPTIONAL — A description of the ruleset or the application.
: OPTIONAL — An URL referring to further information about the ruleset or the application.
: A container element for the rules of the ruleset.
: An element containing message patterns and how a message that matches these patterns is classified. For example:
<rule provider='balabit' id='f57196aa-75fd-11dd-9bba-001e6806451b' class='violation'>
![]() |
Note |
|---|---|
|
If the following characters appear in the message, they must be escaped in the rule as follows:
|
The element may contain any number of elements.
provider: The provider of the rule. This is used to distinguish between who supplied the rule; i.e., if it has been created by BalaBit, or added to the xml by a local user.
id: The globally unique ID of the rule.
class: The class of the rule — syslog-ng assigns this class to the messages matching a pattern of this rule.
: A pattern
describing a log message. This element is also called
message pattern. For example:
<pattern>+ ??? root-</pattern>
The following scheme describes the V2 format of the pattern database. This format is used by the syslog-ng Store Box (SSB) appliance version 1.0.x (see http://www.balabit.com/network-security/syslog-ng/log-server-appliance/ for details).
For a sample database containing only a single pattern, see Example 8.36, “A V2 pattern database containing a single rule”.
: The container element of the pattern database. For example:
<patterndb version='2' pub_date='2008-08-25'>
version: The schema version of the pattern
database. The current version is 2.
pubdate: The publication date of the XML file.
: A container element to group log patterns for an application or program. For example:
<ruleset name='su' id='480de478-d4a6-4a7f-bea4-0c0245d361e1'>
A <patterndb> element may
contain any number of
elements.
name: The name of the application. Note
that the function of this attribute is to make the database more
readable, syslog-ng uses the
<pattern> element to
identify the applications sending log messages.
id: A unique ID of the application, for
example, the md5 sum of the name
attribute.
: OPTIONAL — A description of the ruleset or the application.
: OPTIONAL — An URL referring to further information about the ruleset or the application.
: The name of the application
— syslog-ng matches this value to the $PROGRAM header
of the syslog message to find the rulesets applicable to the
syslog message. This element is also called program
pattern. E.g.,
<pattern>su</pattern>
![]() |
Note |
|---|---|
If the |
: A container element for the rules of the ruleset.
: An element containing message patterns and how a message that matches these patterns is classified. For example:
<rule provider='balabit'
id='f57196aa-75fd-11dd-9bba-001e6806451b'
class='violation'>
![]() |
Note |
|---|---|
|
If the following characters appear in the message, they must be escaped in the rule as follows:
|
The element may contain any number of elements.
provider: The provider of the rule. This is used to distinguish between who supplied the rule; i.e., if it has been created by BalaBit, or added to the xml by a local user.
id: The globally unique ID of the rule.
class: The class of the rule — syslog-ng assigns this class to the messages matching a pattern of this rule.
: An element containing the patterns of the rule. If a element contains multiple elements, the class of the is assigned to every syslog message matching any of the patterns.
: A
pattern describing a log message. This element
is also called message
pattern. For example:
<pattern>+ ??? root-</pattern>
: OPTIONAL — A description of the pattern or the log message matching the pattern.
: OPTIONAL — An element containing one or more URLs referring to further information about the patterns or the matching log messages.
: OPTIONAL — An URL referring to further information about the patterns or the matching log messages.
: OPTIONAL — An element containing custom keywords (tags) about the rules. The tags can be used to label specific events (e.g., user logons).
: OPTIONAL — A keyword or tags applied to messages matching the rule. For example:
<tags><tag>UserLogin</tag></tags>
© 2007-2010 BalaBit IT Security
Please send your comments or documentation bugs to: documentation@balabit.com