Regex Log Parser
Overview
For text log types with more complex structure, you can use the regex
parser.
The regex
parser uses named groups in regular expressions to extract field values from each line of text. You can use grok syntax (i.e. %{PATTERN_NAME:field_name}
) to build complex expressions taking advantage of the built-in patterns provided by Panther or by defining your own.
Panther's log processor uses the RE2
syntax for regular expressions. RE2
does not support some operations common to other regular expression engines, such as lookbehind
. Be sure to check any expressions or grok patterns you copy/paste from other systems.
For example to match the text
We can use this grok syntax with this pattern:
Which is the rough equivalent of this 'raw' regular expression:
For best performance stick to simple built-in patterns such as DATA
, NOTSPACE
, GREEDYDATA
and WORD
. Avoid complex expressions unless it is required to distinguish the field name based on the value (e.g. (%{IP:ip_address}|%{WORD:username})
Example using regex
Using the regex
parser we will define a log type for Juniper.Audit
logs. Panther already supports these logs natively, but we will be using them here because they have variable conflicting forms and can only be 'solved' by using regex
parser.
The sample logs for Juniper.Audit
are:
Here is how we would define a log schema for these logs using regex
:
In the Panther Console, we would follow the How to create a custom schema manually instructions, selecting the Regex parser.
In the Fields & Indicators section (below the Parser section shown in the screenshot above), we would define the fields:
Built-in regex pattern reference
The following tables detail the built-in Panther regex patterns you can use.
General
Name | Regex |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Numbers
Name | Regex |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Network
Name | Regex |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
URI
Name | Regex |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timestamps
Name | Regex |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Aliases
Name | Equivalent To |
---|---|
|
|
|
|
|
|
|
|
|
|
Last updated