patterns.go 6.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package grok
  2. var patterns = map[string]string{
  3. "USERNAME": `[a-zA-Z0-9._-]+`,
  4. "USER": `%{USERNAME}`,
  5. "EMAILLOCALPART": `[a-zA-Z][a-zA-Z0-9_.+-=:]+`,
  6. "EMAILADDRESS": `%{EMAILLOCALPART}@%{HOSTNAME}`,
  7. "HTTPDUSER": `%{EMAILADDRESS}|%{USER}`,
  8. "INT": `(?:[+-]?(?:[0-9]+))`,
  9. "BASE10NUM": `([+-]?(?:[0-9]+(?:\.[0-9]+)?)|\.[0-9]+)`,
  10. "NUMBER": `(?:%{BASE10NUM})`,
  11. "BASE16NUM": `(0[xX]?[0-9a-fA-F]+)`,
  12. "POSINT": `\b(?:[1-9][0-9]*)\b`,
  13. "NONNEGINT": `\b(?:[0-9]+)\b`,
  14. "WORD": `\b\w+\b`,
  15. "NOTSPACE": `\S+`,
  16. "SPACE": `\s*`,
  17. "DATA": `.*?`,
  18. "GREEDYDATA": `.*`,
  19. "QUOTEDSTRING": `"([^"\\]*(\\.[^"\\]*)*)"|\'([^\'\\]*(\\.[^\'\\]*)*)\'`,
  20. "UUID": `[A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}`,
  21. "MAC": `(?:%{CISCOMAC}|%{WINDOWSMAC}|%{COMMONMAC})`,
  22. "CISCOMAC": `(?:(?:[A-Fa-f0-9]{4}\.){2}[A-Fa-f0-9]{4})`,
  23. "WINDOWSMAC": `(?:(?:[A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2})`,
  24. "COMMONMAC": `(?:(?:[A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2})`,
  25. "IPV6": `((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\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28. "HOSTNAME": `\b(?:[0-9A-Za-z][0-9A-Za-z-]{0,62})(?:\.(?:[0-9A-Za-z][0-9A-Za-z-]{0,62}))*(\.?|\b)`,
  29. "HOST": `%{HOSTNAME}`,
  30. "IPORHOST": `(?:%{IP}|%{HOSTNAME})`,
  31. "HOSTPORT": `%{IPORHOST}:%{POSINT}`,
  32. "PATH": `(?:%{UNIXPATH}|%{WINPATH})`,
  33. "UNIXPATH": `(/[\w_%!$@:.,-]?/?)(\S+)?`,
  34. "TTY": `(?:/dev/(pts|tty([pq])?)(\w+)?/?(?:[0-9]+))`,
  35. "WINPATH": `([A-Za-z]:|\\)(?:\\[^\\?*]*)+`,
  36. "URIPROTO": `[A-Za-z]+(\+[A-Za-z+]+)?`,
  37. "URIHOST": `%{IPORHOST}(?::%{POSINT:port})?`,
  38. "URIPATH": `(?:/[A-Za-z0-9$.+!*'(){},~:;=@#%_\-]*)+`,
  39. "URIPARAM": `\?[A-Za-z0-9$.+!*'|(){},~@#%&/=:;_?\-\[\]<>]*`,
  40. "URIPATHPARAM": `%{URIPATH}(?:%{URIPARAM})?`,
  41. "URI": `%{URIPROTO}://(?:%{USER}(?::[^@]*)?@)?(?:%{URIHOST})?(?:%{URIPATHPARAM})?`,
  42. "MONTH": `\b(?:Jan(?:uary|uar)?|Feb(?:ruary|ruar)?|M(?:a|ä)?r(?:ch|z)?|Apr(?:il)?|Ma(?:y|i)?|Jun(?:e|i)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|O(?:c|k)?t(?:ober)?|Nov(?:ember)?|De(?:c|z)(?:ember)?)\b`,
  43. "MONTHNUM": `(?:0?[1-9]|1[0-2])`,
  44. "MONTHNUM2": `(?:0[1-9]|1[0-2])`,
  45. "MONTHDAY": `(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9])`,
  46. "DAY": `(?:Mon(?:day)?|Tue(?:sday)?|Wed(?:nesday)?|Thu(?:rsday)?|Fri(?:day)?|Sat(?:urday)?|Sun(?:day)?)`,
  47. "YEAR": `(\d\d){1,2}`,
  48. "HOUR": `(?:2[0123]|[01]?[0-9])`,
  49. "MINUTE": `(?:[0-5][0-9])`,
  50. "SECOND": `(?:(?:[0-5]?[0-9]|60)(?:[:.,][0-9]+)?)`,
  51. "TIME": `([^0-9]?)%{HOUR}:%{MINUTE}(?::%{SECOND})([^0-9]?)`,
  52. "DATE_US": `%{MONTHNUM}[/-]%{MONTHDAY}[/-]%{YEAR}`,
  53. "DATE_EU": `%{MONTHDAY}[./-]%{MONTHNUM}[./-]%{YEAR}`,
  54. "ISO8601_TIMEZONE": `(?:Z|[+-]%{HOUR}(?::?%{MINUTE}))`,
  55. "ISO8601_SECOND": `(?:%{SECOND}|60)`,
  56. "TIMESTAMP_ISO8601": `%{YEAR}-%{MONTHNUM}-%{MONTHDAY}[T ]%{HOUR}:?%{MINUTE}(?::?%{SECOND})?%{ISO8601_TIMEZONE}?`,
  57. "DATE": `%{DATE_US}|%{DATE_EU}`,
  58. "DATESTAMP": `%{DATE}[- ]%{TIME}`,
  59. "TZ": `(?:[PMCE][SD]T|UTC)`,
  60. "DATESTAMP_RFC822": `%{DAY} %{MONTH} %{MONTHDAY} %{YEAR} %{TIME} %{TZ}`,
  61. "DATESTAMP_RFC2822": `%{DAY}, %{MONTHDAY} %{MONTH} %{YEAR} %{TIME} %{ISO8601_TIMEZONE}`,
  62. "DATESTAMP_OTHER": `%{DAY} %{MONTH} %{MONTHDAY} %{TIME} %{TZ} %{YEAR}`,
  63. "DATESTAMP_EVENTLOG": `%{YEAR}%{MONTHNUM2}%{MONTHDAY}%{HOUR}%{MINUTE}%{SECOND}`,
  64. "HTTPDERROR_DATE": `%{DAY} %{MONTH} %{MONTHDAY} %{TIME} %{YEAR}`,
  65. "SYSLOGTIMESTAMP": `%{MONTH} +%{MONTHDAY} %{TIME}`,
  66. "PROG": `[\x21-\x5a\x5c\x5e-\x7e]+`,
  67. "SYSLOGPROG": `%{PROG:program}(?:\[%{POSINT:pid}\])?`,
  68. "SYSLOGHOST": `%{IPORHOST}`,
  69. "SYSLOGFACILITY": `<%{NONNEGINT:facility}.%{NONNEGINT:priority}>`,
  70. "HTTPDATE": `%{MONTHDAY}/%{MONTH}/%{YEAR}:%{TIME} %{INT}`,
  71. "QS": `%{QUOTEDSTRING}`,
  72. "SYSLOGBASE": `%{SYSLOGTIMESTAMP:timestamp} (?:%{SYSLOGFACILITY} )?%{SYSLOGHOST:logsource} %{SYSLOGPROG}:`,
  73. "COMMONAPACHELOG": `%{IPORHOST:clientip} %{HTTPDUSER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-)`,
  74. "COMBINEDAPACHELOG": `%{COMMONAPACHELOG} %{QS:referrer} %{QS:agent}`,
  75. "HTTPD20_ERRORLOG": `\[%{HTTPDERROR_DATE:timestamp}\] \[%{LOGLEVEL:loglevel}\] (?:\[client %{IPORHOST:clientip}\] ){0,1}%{GREEDYDATA:errormsg}`,
  76. "HTTPD24_ERRORLOG": `\[%{HTTPDERROR_DATE:timestamp}\] \[%{WORD:module}:%{LOGLEVEL:loglevel}\] \[pid %{POSINT:pid}:tid %{NUMBER:tid}\]( \(%{POSINT:proxy_errorcode}\)%{DATA:proxy_errormessage}:)?( \[client %{IPORHOST:client}:%{POSINT:clientport}\])? %{DATA:errorcode}: %{GREEDYDATA:message}`,
  77. "HTTPD_ERRORLOG": `%{HTTPD20_ERRORLOG}|%{HTTPD24_ERRORLOG}`,
  78. "LOGLEVEL": `([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)?)`,
  79. }