我期待从单一的日志行提取相同领域的多个实例。例如,假设我有以下日志记录:
Recipients: [email protected] [email protected] [email protected]
我事先不知道有多少电子邮件地址将被列出。
与此相关,在一些早期的工作中,我处理,看上去像这样的日志记录:
Step=12305, Step=11006, Step=11001, Step=11018, Step=12304, Step=11522, Step=11806
在这种情况下,我接过kv{}
过滤器,它会自动产生一个很好的,多值场这样的优势:
"Step": [
"12305",
"11006",
"11001",
"11018",
"12304",
"11522",
"11806"
],
我想获得同种多值字段作为我的结果,但不能简单地再次使用KV因为实际的日志线比我原来的例子混乱。实际的日志行更像是这样的:
Recipients: Unwanted_text [email protected] other junk [email protected] some.hostname.net 1 [email protected] even-more
我想一个神交表达能够捕捉N个电子邮件地址(%{EMAILADDRESS}
),无论他们在日志行,并把它们放到一个多值字段。有人建议如何做到这一点?
谢谢,
克里斯
input{
beats{
port => #specify_your_port_here
}
}
filter{
mutate{
gsub => [
"message","([a-zA-Z][a-zA-Z0-9_.+-=:]+@\b(?:[0-9A-Za-z][0-9A-Za-z-]{0,62})(?:\.(?:[0-9A-Za-z][0-9A-Za-z-]{0,62}))*(\.?|\b))","email=\1"
]
}
kv{
source => "message"
}
}
output{
elasticsearch{
host => "localhost:9200"
index => "manual"
document_type => "log"
}
}
我测试上面的配置文件,其中filebeat从文件中读取所述输入日志,并将其发送到logstash。
说明: - >
gsub
更换电子邮件地址的全部出现在message
和捕获的电子邮件地址输入email=
。例如: - >
输入消息 - >
Recipients: Recipients: Unwanted_text [email protected] other junk [email protected] some.hostname.net 1 [email protected] even-more
GSUB输入消息转换为: - >
Recipients: Unwanted_text [email protected] other junk [email protected] some.hostname.net 1 [email protected] even-more
然后将过滤器KV创建包含所有的电子邮件地址的数组“电子邮件”
"email": [
"[email protected]",
"[email protected]",
"[email protected]"
]
您可以使用正则表达式如下图所示,然后捕获所有匹配字符串:
[\w\d_]*?@[\w]*?\.[\w]{2,3}\.?[\w]?
但是:四联zxsw POI
测试:
https://regex101.com/r/kDUoi5/2
比赛:
Recipients: Unwanted_text [email protected] other junk [email protected] some.hostname.net 1 [email protected] even-more