Update to FilterX
The following sections show you how you can change your existing filters, parsers, and rewrite rules to FilterX statements. Note that:
- Many examples in the FilterX documentation were adapted from the existing filter, parser, and rewrite examples to show how you can achieve the same functionality with FilterX.
- Don’t worry if you can’t update something to FilterX. While you can’t use other blocks within a FilterX block, you can use both in a log statement, for example, you can use a FilterX block, then a parser if needed.
- There is no push to use FilterX. You can keep using the traditional blocks if they satisfy your requirements.
Update filters to FilterX
This section shows you how to update your existing filter expressions to filterx.
You can replace most filter functions with a simple value comparison of the appropriate macro, for example:
-
facility(user)with${FACILITY} == "user" -
host("example-host")with${HOST} == "example-host" -
inlist()with theinlist membership operator -
level(warning)with${LEVEL} == "warning"If you want to check for a range of levels, use numerical comparison with the
${LEVEL_NUM}macro instead. For a list of numerical level values, see LEVEL_NUM. -
message("example")with${MESSAGE} =~ "example"(see the equal tilde operator for details) -
netmask()andnetmask6()withsubnetand a list membership check, for example,netmask(192.168.5.0/255.255.255.0)becomes${SOURCEIP} in subnet("192.168.5.0/255.255.255.0");. For details, see IP addresses and subnets. -
program(nginx)with${PROGRAM} == "nginx" -
source(my-source)with${SOURCE} == "my-source"
You can compare values and use boolean operators similarly to filters.
Since all FilterX statements must match a message to pass the FilterX block, you can often replace complex boolean filter expressions with multiple, simple FilterX statements. For example, consider the following filter statement:
filter { host("example1") and program("nginx"); };The following is the same FilterX statement:
filterx { ${HOST} == "example1" and ${PROGRAM} == "nginx"; };which is equivalent to:
filterx {
${HOST} == "example1";
${PROGRAM} == "nginx";
};The following filter functions have no equivalents in FilterX yet:
- The
filter()filter function . You can’t call a FilterX block from another FilterX block, but you can access name-value pairs and pass variables from multiple FilterX blocks. rate-limit()tags()
Update rewrite rules
This section shows you how to update your existing rewrite expressions to filterx.
You can replace most rewrite rules with FilterX functions and value assignments, for example:
rewrite{subst()}with theregexp_substFilterX functionrewrite{set()}with value assignmentsrewrite{unset()}with theunsetFilterX functionrewrite{rename()}with assigning a value to the new field, then using theunsetfunction on the old field- Timezone manipulation with the similar FilterX functions .
set-pri(),set-severity(), andset-facility()with theset_priFilterX function- Setting multiple fields at once with the
set_fieldsFilterX function - Conditional rewrites with value comparisons in the FilterX block. For an example, see FilterX use cases and examples.
The following rewrite rules have no equivalents in FilterX yet:
credit-card-mask()andcredit-card-hash(). You can mask the numbers with theregexp_substFilterX function instead.set-tag()andclear-tag()set-matches()
Update parsers
This section shows you how to update your existing parser expressions to filterx.
You can replace most parsers with FilterX functions. These functions return the parsed data, which you can assign to a variable or a name-value pair. For example, you can replace:
csv-parser()with theparse_csvFilterX functiondate-parser()with thestrptimeFilterX function. To set the timestamp of the message, useset_timestampon the result.json-parser()with thejsonFilterX functionkv-parser()with theparse_kvFilterX functionmetrics-probe()with theupdate_metricFilterX functionregexp-parser()with theregexp_searchFilterX functionwindows-eventlog-xml-parser()with theparse_windows_eventlog_xmlFilterX functionxml-parser()with theparse_xmlFilterX function
To parse CEF and LEEF messages, use the parse_cef
and parse_leef
FilterX functions. These formats have no classic parsers.
The following parsers have no equivalents in FilterX yet. You can still use them in the same log path as your FilterX blocks.
db-parser()(pattern databases)grouping-by()and other correlation parsers- Application-specific parsers, like the Cisco, FortiGate, or iptables parsers