简体   繁体   English

行尾的 Grok Pattern 可选字段

[英]Grok Pattern optional fields on line end

I want to "grok" these two lines:我想“摸索”这两行:

usg210 CEF:0|ZyXEL|USG210|4.65(AAPI.1)|0|Access Control|5|devID=bccf4fxxxxxx src=192.168.1.228 dst=255.255.255.255 spt=7303 dpt=7303 msg=Match default rule, DROP proto=17 app=others

usg210 CEF:0|ZyXEL|USG210||0|Blocked Web Sites|9|devID=bccf4fxxxxxx src=192.168.1.228 dst=23.57.22.128 spt=50938 dpt=443 msg=gameplay.intel.com : Games, Rule_id=5, SSI=N (HTTPS Domain Filter)

Pattern:图案:

\|(?:.*)\|%{DATA:class}\|%{WORD:loglevel}\|devID=%{WORD:mac} src=%{IPV4:ipsrc} dst=%{IPV4:ipdst} spt=%{WORD:spt} dpt=%{WORD:dpt} msg=%{GREEDYDATA:msg}( proto=%{WORD:proto} app=%{WORD:app})?

The fields 'proto' and 'app' are optional, but my debugger msg looks like this: "Match default rule, DROP proto=17 app=others" and proto an app is null. 'proto' 和 'app' 字段是可选的,但我的调试器消息如下所示:“匹配默认规则,DROP proto=17 app=others”并且应用程序的原型是 null。

Can anyone explain how to get the fields filled if data is present and how I make them optional if not present.谁能解释如果数据存在如何填写字段,如果不存在我如何使它们成为可选的。

You are using GREEDYDATA pattern and do not require your pattern to match the whole string.您正在使用GREEDYDATA模式,并且不需要您的模式来匹配整个字符串。

In Grok, you need to replace GREEDYDATA with DATA and add $ at the end of the pattern:在 Grok 中,您需要将GREEDYDATA替换为DATA并在模式末尾添加$

\|.*\|%{DATA:class}\|%{WORD:loglevel}\|devID=%{WORD:mac} src=%{IPV4:ipsrc} dst=%{IPV4:ipdst} spt=%{WORD:spt} dpt=%{WORD:dpt} msg=%{DATA:msg}( proto=%{WORD:proto} app=%{WORD:app})?$

See the msg=%{DATA:msg}( proto=%{WORD:proto} app=%{WORD:app})?$ part, with msg=%{DATA:msg} and $ .请参阅msg=%{DATA:msg}( proto=%{WORD:proto} app=%{WORD:app})?$部分,其中msg=%{DATA:msg}$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM