grok patterns

官方Grok Pattern源码

Custom Grok Pattern

自定义的正则格式

1
(?<field_name>the pattern here)

General Grok Patterns

USER

1
%{USERNAME}

USERNAME

1
[a-zA-Z0-9._-]+

BASE10NUM

1
(?<![0-9.+-])(?>[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+)))

BASE16FLOAT

1
\b(?<![0-9A-Fa-f.])(?:[+-]?(?:0x)?(?:(?:[0-9A-Fa-f]+(?:\.[0-9A-Fa-f]*)?)|(?:\.[0-9A-Fa-f]+)))\b

INT

1
(?:[+-]?(?:[0-9]+))

NONNEGINT

1
\b(?:[0-9]+)\b

NUMBER

1
(?:%{BASE10NUM}) BASE16NUM (?<![0-9A-Fa-f])(?:[+-]?(?:0x)?(?:[0-9A-Fa-f]+))

POSINT

1
\b(?:[1-9][0-9]*)\b

WORD

1
\b\w+\b

NOTSPACE

1
\S+

SPACE

1
\s*

DATA

1
.*?

GREEDYDATA

1
.*

QUOTEDSTRING

1
(?>(?<!\\)(?>"(?>\\.|[^\\"]+)+"|""|(?>'(?>\\.|[^\\']+)+')|''|(?>`(?>\\.|[^\\`]+)+`)|``))

UUID

1
[A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}

Date and Time Grok Patterns

MONTH

1
\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b

MONTHNUM

1
(?:0?[1-9]|1[0-2])

MONTHNUM2

1
(?:0[1-9]|1[0-2])

MONTHDAY

1
(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9])

DAY

1
(?:Mon(?:day)?|Tue(?:sday)?|Wed(?:nesday)?|Thu(?:rsday)?|Fri(?:day)?|Sat(?:urday)?|Sun(?:day)?)

YEAR

1
(?>\d\d){1,2} HOUR (?:2[0123]|[01]?[0-9]) MINUTE (?:[0-5][0-9])

SECOND

1
(?:(?:[0-5]?[0-9]|60)(?:[:.,][0-9]+)?) TIME (?!<[0-9])%{HOUR}:%{MINUTE}(?::%{SECOND})(?![0-9])

Note: 60 is a leap second in most time standards.

DATE_US

1
%{MONTHNUM}[/-]%{MONTHDAY}[/-]%{YEAR}

DATE_EU

1
%{MONTHDAY}[./-]%{MONTHNUM}[./-]%{YEAR}

ISO8601_TIMEZONE

1
(?:Z|[+-]%{HOUR}(?::?%{MINUTE}))

ISO8601_SECOND

1
(?:%{SECOND}|60)

TIMESTAMP_ISO8601

1
%{YEAR}-%{MONTHNUM}-%{MONTHDAY}[T ]%{HOUR}:?%{MINUTE}(?::?%{SECOND})?%{ISO8601_TIMEZONE}?

DATE

1
%{DATE_US}|%{DATE_EU}

DATESTAMP

1
%{DATE}[- ]%{TIME}

TZ

1
(?:[PMCE][SD]T|UTC)

DATESTAMP_RFC822

1
%{DAY} %{MONTH} %{MONTHDAY} %{YEAR} %{TIME} %{TZ}

DATESTAMP_RFC2822

1
%{DAY}, %{MONTHDAY} %{MONTH} %{YEAR} %{TIME} %{ISO8601_TIMEZONE}

DATESTAMP_OTHER

1
%{DAY} %{MONTH} %{MONTHDAY} %{TIME} %{TZ} %{YEAR}

DATESTAMP_EVENTLOG

1
%{YEAR}%{MONTHNUM2}%{MONTHDAY}%{HOUR}%{MINUTE}%{SECOND}

Java Grok Patterns

JAVACLASS

1
(?:[a-zA-Z$_][a-zA-Z$_0-9]*\.)*[a-zA-Z$_][a-zA-Z$_0-9]*

JAVAFILE

1
(?:[A-Za-z0-9_. -]+)

A space character is allowed to match special cases, such as Native Method or Unknown Source.

JAVAMETHOD

1
(?:(<init>)|[a-zA-Z$_][a-zA-Z$_0-9]*)

JAVASTACKTRACEPART

1
%{SPACE}at %{JAVACLASS:class}\.%{JAVAMETHOD:method}\(%{JAVAFILE:file}(?::%{NUMBER:line})?\)

The line number is optional in special cases, such as Native Method or Unknown Source.

Log Grok Patterns

SYSLOGTIMESTAMP

1
%{MONTH} +%{MONTHDAY} %{TIME} PROG (?:[\w._/%-]+)

SYSLOGPROG

1
%{PROG:program}(?:\[%{POSINT:pid}\])?

SYSLOGHOST

1
%{IPORHOST}

SYSLOGFACILITY

1
<%{NONNEGINT:facility}.%{NONNEGINT:priority}>

SYSLOGBASE

1
%{SYSLOGTIMESTAMP:timestamp} (?:%{SYSLOGFACILITY} )?%{SYSLOGHOST:logsource} %{SYSLOGPROG}:

HTTPDATE

1
%{MONTHDAY}/%{MONTH}/%{YEAR}:%{TIME} %{INT}

QS

1
%{QUOTEDSTRING}

COMMONAPACHELOG

1
%{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-)

COMBINEDAPACHELOG

1
%{COMMONAPACHELOG} %{QS:referrer} %{QS:agent}

LOGLEVEL

1
([Aa]lert|ALERT|[Tt]race|TRACE|[Dd]ebug|DEBUG|[Nn]otice|NOTICE|[Ii]nfo|INFO|[Ww]arn?(?:ing)?|WARN?(?:ING)?|[Ee]rr?(?:or)?|ERR?(?:OR)?|[Cc]rit?(?:ical)?|CRIT?(?:ICAL)?|[Ff]atal|FATAL|[Ss]evere|SEVERE|EMERG(?:ENCY)?|[Ee]merg(?:ency)?)

Networking Grok Patterns

MAC

1
(?:%{CISCOMAC}|%{WINDOWSMAC}|%{COMMONMAC})

CISCOMAC

1
(?:(?:[A-Fa-f0-9]{4}\.){2}[A-Fa-f0-9]{4})

COMMONMAC

1
(?:(?:[A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2})

WINDOWSMAC

1
(?:(?:[A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2})

HOST

1
%{HOSTNAME}

HOSTNAME

1
\b(?:[0-9A-Za-z][0-9A-Za-z-]{0,62})(?:\.(?:[0-9A-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-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)? IPV4 (?<![0-9])(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))(?![0-9])

Path Grok Patterns

PATH

1
(?:%{UNIXPATH}|%{WINPATH})

UNIXPATH

1
(?>/(?>[\w_%!$@:.,~-]+|\\.)*)+ TTY (?:/dev/(pts|tty([pq])?)(\w+)?/?(?:[0-9]+))

WINPATH

1
(?>[A-Za-z]+:|\\)(?:\\[^\\?*]*)+ URIPROTO [A-Za-z]+(\+[A-Za-z+]+)?

URIHOST

1
%{IPORHOST}(?::%{POSINT:port})?

URIPATH

1
(?:/[A-Za-z0-9$.+!*'(){},~:;=@#%_\-]*)+ #URIPARAM \?(?:[A-Za-z0-9]+(?:=(?:[^&]*))?(?:&(?:[A-Za-z0-9]+(?:=(?:[^&]*))?)?)*)?

URIPARAM

1
\?[A-Za-z0-9$.+!*'|(){},~@#%&/=:;_?\-\[\]]*

URIPATHPARAM

1
%{URIPATH}(?:%{URIPARAM})?

URI

1
%{URIPROTO}://(?:%{USER}(?::[^@]*)?@)?(?:%{URIHOST})?(?:%{URIPATHPARAM})?

  • 本文作者: forever杨
  • 本文链接: https://blog.yl-online.top/posts/a8d0988c.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。如果文章内容对你有用,请记录到你的笔记中。本博客站点随时会停止服务,请不要收藏、转载!