Sample Patterns for Dissect, Grok, Regex, and Ruby Parsers
Custom log sources can implement user-defined parsers. Anomali provides sample patterns for programmable sub parsers.
Dissect
Dissect is a Logstash filter used to extract fields from log data. The following table provides examples of patterns commonly used to parse event logs.
Grok
Grok is a Logstash filter used to extract fields from log data. The following table provides examples of patterns commonly used to parse event logs.
| Grok Pattern | Example |
|---|---|
| %{URIPATH:uri_path} | /v2/blacklist/ |
| %{NUMBER:response_status} | 15824, 0.043 |
| %{WORD:method} | GET,production |
| %{GREEDYDATA:body} | any sentence |
| %{INT:port} | 1234 |
| %{IPORHOST:ip} | 55.3.244.1 |
| %{URI:url} | http://sylvaclouds.eu/new1/IMG-0001-documents.exe |
| %{DATESTAMP:datetime} | 2017-09-27 0:21:12 |
| %{SYSLOGTIMESTAMP:date} | Jun 2 14:55:46 |
Regex
Regex is short for regular expression. A regular expression specifies a string search pattern. The following table provides examples of regex patterns commonly used to extract fields from unstructured data.
| Regex Pattern | Example |
|---|---|
|
(?<ip>([0-9]{1,3}.){3}[0-9]{1,3}) |
38.99.50.98 |
| (?<port>\d+) | 8554 |
| (?<method>\w+) | GET |
| (?<action>\w+\s\w+). | session miss.^M |
| (?<url>(?:https?:)(?:/[A-Za-z0-9$.+!*'(){},~:;=@#%_-]*)+) | http://sylvaclouds.eu/new1/IMG-0001-documents.exe |
| (?<hostname>[\w-]+) | elb-shop-com |
| (?<status>\d{1,3}) | 200 |
| (?<customer_uri>[^/]+$) | customerURI=/All Customers/ANSI/ANSI/740663 |
| (?<uri_path>(?:/[A-Za-z0-9$.+!*'(){},~:;=@#%_-]*)+) | /Users/jdoe/Downloads/110 |
| (?<hash>(^[a-fA-F0-9]{32}$)|(^[a-fA-F0-9]{40}$)|(^[a-fA-F0-9]{64}$)) | Matches md5 or sha1 or sha256 |
| (?<event_time>([\d{2,4}-]+){2}\d{2}\s([\d:]+){2}\d{2}) | 2017-09-25 23:27:36 |
| (?<timestamp>[\d-]+\w[\d:.-]+) | 2019-10-20T23:00:26.059475-07:00 |
| \<\d+\>(?<datetime>\d{2,4}[-/\s][A-Za-z]{3,9}[-/\s]\d+\s[\d:]+) | <14>2019 Jun 22 16:24:05 |
| (?<datetime>[A-Za-z]{3,9}\s[A-Za-z]{3,9}\s[0-9]{1,2}\s[\d:]+) | Fri Aug 5 22:11:53 2011 |
Ruby
Ruby is a programming language that can be used to extract fields from unstructured data. The following table provides examples of Ruby logic commonly used to parse unstructured data.