logstash的grok条件匹配

logstash的grok条件匹配,logstash,logstash-grok,Logstash,Logstash Grok,我有这种格式的php日志 [Day Mon DD HH:MM:SS YYYY] [Log-Type] [client <ipv4 ip address>] <some php error type>: <other msg with /path/of/a/php/script/file.php and something else> [Day Mon DD HH:MM:SS YYYY] [Log-Type] [client <ipv4 ip addres

我有这种格式的php日志

[Day Mon DD HH:MM:SS YYYY] [Log-Type] [client <ipv4 ip address>] <some php error type>: <other msg with /path/of/a/php/script/file.php and something else>
[Day Mon DD HH:MM:SS YYYY] [Log-Type] [client <ipv4 ip address>] <some php error type>: <other msg without any file name in it>
[Day Mon DD HH:MM:SS YYYY] [Log-Type] [client <ipv4 ip address>] <some msg with out semicolon in it but /path/of/a/file inside the message>
但不知何故,我发现很难让它对整个日志文件起作用

有什么建议吗?此外,不确定日志文件中是否会出现任何其他类型的错误消息。但目的是为所有人提供相同的格式。如何处理这些日志以获得上述格式,有什么建议吗?

可以使用多种模式进行配置:

grok {
  match => [
    "message", "%{DATA:php_error_type}: %{DATA:message_part1}%{URIPATHPARAM:file_name}%{GREEDYDATA:errormsg}",
    "message", "%{DATA:php_error_type}: %{GREEDYDATA:errormsg}",
    "message", "%{DATA:message_part1}%{URIPATHPARAM:file_name}%{GREEDYDATA:errormsg}"
  ]
}

(与具有多个模式的单个过滤器不同,您可以使用多个grok过滤器,但您可能需要禁用_GrokParseFailureTagging with。)

如果有时日志行的某些部分丢失,您可以使用以下语法:

(?:%{PATTERN1}|%{PATTERN2})

允许模式1或“”。(空)

使用此选项,您只能管理一个模式:

grok {
   match => [
      "message", "(?:%{DATA:php_error_type}: |)(?:%{DATA:message_part1}:)(?:%{URIPATHPARAM:file_name}|)%{GREEDYDATA:errormsg}",
   ]
}
如果您有问题,可以用更严格的模式替换
%{DATA}

您也可以使用这种语法(更像正则表达式)

要调试复杂的grok模式,我建议:

  • (多行选项+同时多个输入行+其他选项)
  • (使用更简单)

什么是“非常困难”的意思?您的某个模式是否在调试器中不起作用,或者??我不确定我问的问题是否正确。我实际上希望在配置文件中使用所有这些条件,以便解析所有行并获得相同的输出。到目前为止,我还不知道如何添加它们,在哪里添加它们。我来这里写同样的东西。事实上,我一开始确实看到了,但不明白。今天,我能够。所以现在我已经开始工作了。尽管如此,还是谢谢你。超级快乐的logstash+graylog2用户:)。嗨@Magnus对我来说我面对的是无效的configuration@feelgoodandprogramming正确的语法是grok{match=>{“message”=>[“%{DATA:php_error_type}:%{DATA:message_part1}%{URIPATHPARAM:file_name}%{GREEDYDATA:errormsg},“%{DATA:php_error_type}”:%%{GREEDYDATA:errormsg}',“%%{DATA:message_part1}%{URIPATHPARAM:file_name}%{GREEDYDATA:errormsg}',]}}@SaurabhSaxena这两种形式都有效。然而,在我的帖子中最后一个grok表达式后面有一个逗号,这会导致Logstash拒绝它。我把它拿走了。
(?:%{PATTERN1}|%{PATTERN2})
(?:%{PATTERN1}|)
grok {
   match => [
      "message", "(?:%{DATA:php_error_type}: |)(?:%{DATA:message_part1}:)(?:%{URIPATHPARAM:file_name}|)%{GREEDYDATA:errormsg}",
   ]
}
(?:%{PATTERN1})?