我正在尝试从替换为其他内容的字符串中获取双引号(放置在随机位置)。
这是logline-
msg="AUT30544: User chose to proceed on the sign-in notification page "Sign-In Notification Message""实际上,这是logstash过滤器部分中KV解析的一部分。如果您注意到,在字符串内部有一个带引号的字符串,而字符串本身是用双引号括起来的。
然而,下面的字符串在KV中被正确解析-
msg="AUT23278: User Limit realm restrictions successfully passed for /google_auth "现在,我创建了一个正则表达式来删除有问题的字符串中的双引号- https://regex101.com/r/o00oot/1/将其应用于logstash,但没有任何更改。下面是我的配置文件-
input {
tcp {
port => 1301
}
}
filter {
if "type=vpn" in [message] {
dissect {
mapping => { "message" => "%{reserved} id=firewall %{message1}" }
}
#mutate { gsub => ["message1",':'," "] }
#mutate { gsub => ["message1",'"',''] }
mutate {gsub => ["msg","(.*)\"(.*)\"(\")", "\1 '\2 '\3"] }
kv { source => "message1" value_split => "=" whitespace => "strict" } #field_split => " " remove_char_value => '"' }
geoip { source => "src" }
# \/ end of if vpn type log
}
else { drop {} }
}我可以使用tcpdump捕获的一个类似的logline是-
<134>Oct 2 11:24:45 1xx.xx.43.101 1 2021-10-02T11:24:45+05:30 canopus.domain1.com2 PulseSecure: - - - id=firewall time="2021-10-02 11:24:45" pri=6 fw=172.20.43.101 vpn=ive user=user1 realm="google_auth" roles="" proto=auth src=2xx.176.114.94 dst= dstname= type=vpn op= arg="" result= sent= rcvd= agent="" duration= msg="AUT30544: User chose to proceed on the sign-in notification page "Sign-In Notification Message""stdout上同类消息的stdout。我可以看到双引号被转义,但它们仍然会在解析时产生问题。
{
"type" => "vpn",
"user" => "user1",
"fw" => "1xx.xx.43.101",
"host" => "1xx.xx.4.63",
"realm" => "google_auth",
"src" => "1xx.66.50.112",
"port" => 33003,
"@version" => "1",
"message" => "<13>Oct 2 11:54:39 1xx.xx.43.101 396 <134>1 2021-10-02T11:54:39+05:30 canopus.domain1.com2 PulseSecure: - - - id=firewall time=\"2021-10-02 11:54:39\" pri=6 fw=1xx.xx.43.101 vpn=ive user=user1 realm=\"google_auth\" roles=\"\" proto=auth src=1xx.66.50.112 dst= dstname= type=vpn op= arg=\"\" result= sent= rcvd= agent=\"\" duration= msg=\"AUT30544: User chose to proceed on the sign-in notification page \"Sign-In Notification Message\"\"",
"geoip" => {
"location" => {
"lon" => 77.5937,
"lat" => 12.9719
},如果有人知道这个问题的KV插件的本地解决方案,我就不需要在gsub中经历regex的麻烦了。
发布于 2021-10-02 08:37:26
我不确定你是否可以在整个消息上使用kv,因为你已经有了,试着拆分它,这样你就可以在单独的字段中获得消息的键/值部分,然后对它使用kv。也就是说,我建议你在这里完全跳过使用gsub,因为kv过滤器有一个叫做trim_value的选项。
使用该选项,您的配置将如下所示。免责声明,这是未经测试的,也许你将不得不在trim_value中使用正则表达式,但这是更简单的处理方式。
input {
tcp {
port => 1301
}
}
filter {
if "type=vpn" in [message] {
dissect {
mapping => { "message" => "%{reserved} id=firewall %{message1}" }
}
kv {
source => "message1"
value_split => "="
whitespace => "strict"
trim_value => "\\\""
}
geoip {
source => "src"
}
}
else {
drop { }
}
}https://stackoverflow.com/questions/69414587
复制相似问题