Grok 自定义模式中 Lookahead 和 Lookbehind 的语法

Syntax for Lookahead and Lookbehind in Grok Custom Pattern

我正在尝试在 Grok 自定义模式中使用后视和先行,并在 Grok 调试器中遇到我无法解决的模式匹配错误。

这是为了归档系统日志。我目前正在尝试解析 postgrey 应用程序。

给出的数据如:

2019-04-09T11:41:31-05:00 67.157.192.7 postgrey: action=pass, reason=triplet found, delay=388, client_name=unknown, client_address=103.255.78.9, sender=members@domain.com, recipient=person@domain.com

我正在尝试使用以下内容将 "action=" 和紧随其后的逗号之间的字符串作为字段 "postgrey_action":

%{TIMESTAMP_ISO8601:timestamp} (?:%{SYSLOGFACILITY} )?%{SYSLOGHOST:logsource} %{SYSLOGPROG} (?<postgrey_action>(?<=action=).+?(?=\,))

我希望看到以下输出:

{
  "program": "dhcpd:",
  "logsource": "66.146.192.67",
  "timestamp": "2019-04-09T11:41:31-05:00"
  "postgrey_action": "pass"
}

相反,我从调试器收到 "Provided Grok patterns do not match data in the input"。

我怎样才能正确地使这个 lookbehind/lookahead 工作?

编辑:我应该注意到,如果 Grok 模式末尾没有 postgrey_action 匹配,Grok 调试器会按预期运行和工作(使用 linux-syslog 和 grok-patterns)。

Logstash 版本 6.3.2

作为变通方法,我修改了我的语法,使用自定义模式文件,并使用 patterns_dir 指令在每个过滤器中引用它。

例如 我的图案:

POSTGREY %{TIMESTAMP_ISO8601:timestamp} (?:%{SYSLOGFACILITY} )?%{SYSLOGHOST:logsource} %{SYSLOGPROG} (action=)%{WORD:postgrey_action}(,) (reason=)%{DATA:postgrey_reason}(,) (delay=)%{NUMBER:postgrey_delay}(,) (client_name=)%{IPORHOST}(,) (client_address=)%{IPORHOST:postgrey_clientaddr}(,) (sender=)%{EMAILADDRESS:postgrey_sender}(,)

我的过滤器:

    if "postgrey" in [program]  {
        grok {
        match => { "message" => "%{POSTGREY}"}
        patterns_dir => ["/etc/logstash/patterns"]
        overwrite => [ "message" ]
        }
    }

但是,这个解决方法仍然没有回答我最初的问题,即为什么我最初的方法不起作用?

查看 Oniguruma Regex documentation and the Grok filters documentation,我不清楚我的原始语法有什么问题,或者如何使用名为 capture 的 grok regex 正确实现 look-ahead/look-behind。如果不受支持,则不应如此记录。