Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从json子字符串中提取字段-logstash_Logstash_Elastic Stack_Logstash Grok - Fatal编程技术网

从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。我有解析错误。