从json子字符串中提取字段-logstash
我对从json子字符串中提取字段-logstash,logstash,elastic-stack,logstash-grok,Logstash,Elastic Stack,Logstash Grok,我对Logstash过滤东西是相当陌生的。下面是json字符串 { "changed": false, "msg": "Foo Facts: oma_phase: prd, oma_app: fsd, oma_apptype: obe, oma_componenttype: oltp, oma_componentname: -, oma_peak: pk99, oma_phaselevel: prd" } 我想提取字段oma\u phase、oma\u app、oma\u a
Logstash
过滤东西是相当陌生的。下面是json字符串
{
"changed": false,
"msg": "Foo Facts: oma_phase: prd, oma_app: fsd, oma_apptype: obe, oma_componenttype: oltp, oma_componentname: -, oma_peak: pk99, oma_phaselevel: prd"
}
我想提取字段oma\u phase、oma\u app、oma\u apptype、oma\u componenttype、oma\u componentname、oma\u peak和oma\u phaselevel
我尝试了以下原生json过滤器
filter {
if [type] == "ansible" {
json {
source => "ansible_result"
}
}
}
这里的ansible\u result
是保存上述json值的键。但是,有许多键具有不同的值,但具有相同的ansible\u结果
key。这会创建很多索引键,我不希望这样
我希望有某种过滤器可以匹配子字符串Foo Facts
,并在提取oma.*
字段后匹配
不知何故,我无法使用grok
过滤器匹配子字符串。如果你能帮我做这件事,那就太好了
非常感谢。请尝试以下代码:
filter {
json {
source => "message"
}
}
ansible_结果json将被视为一条消息 开始时有点困难,但最终还是成功了
“msg\”:\“Foo Facts:oma\u phase:%%{DATA:oma\u phase},oma\u app:%%{DATA:oma\u apptype},(oma\u componenttype:%%{DATA:oma\u componenttype},)?oma\u componentname:%%{DATA:oma\u componentname},oma\u peak:%%{DATA:oma\u peak},oma\u phasevel DATA:oma\u elevel code}
从日志中,我知道一些日志缺少oma\u componenttype
。所以我用()?
如果没有下面在线解析器的帮助,这是不可能的
我试过这个<代码>消息
与ansible\u结果
的json不同。事实上,message
根本不是json。我有解析错误。