日志文件的 Grok 模式

Grok pattern for log files

总的来说,我对 Logstash 和 ELK 还是很陌生。 我需要按照以下格式为日志文件编写 grok 模式:

[191114|16:51:13.577|BPDM|MDS|2|209|ERROR|39999]Interrupted by a signal!!!

我尝试参考grok-patterns and by trying out my implementation in grok-debugger写了一个grok模式,但是没有成功。

grok {
match => { "message" => "%{NONNEGINT:fixed}|%{HOSTNAME:host}|%{WORD:word1}|%{WORD:word2}|%{NONNEGINT:num1}|%{NONNEGINT:num2}|%{ERROR|INFO|EVENT}|%{NONNEGINT:num1}|%{GREEDYDATA:message}" }
 }

你需要对括号和管道进行转义,你的第二个字段不是主机,它是时间。

这个有效,只需验证字段名称。

\[%{NONNEGINT:fixed}\|%{DATA:time}\|%{WORD:word1}\|%{WORD:word2}\|%{NONNEGINT:num1}\|%{NONNEGINT:num2}\|%{WORD:loglevel}\|%{NONNEGINT:num3}\]%{GREEDYDATA:message}

此 grok 将像这样解析您的消息。

{
  "word1": "BPDM",
  "word2": "MDS",
  "message": "Interrupted by a signal!!!",
  "loglevel": "ERROR",
  "num1": "2",
  "fixed": "191114",
  "time": "16:51:13.577",
  "num3": "39999",
  "num2": "209"
}