我有一个格式的 JSON:
{
"SOURCE":"Source A",
"Model":"ModelABC",
"Qty":"3"
}
我正在尝试使用 logstash 解析这个 JSON。基本上,我希望logstash 输出是可以使用kibana 分析的键:值对列表。我认为这可以开箱即用。从大量阅读中,我知道我必须使用 grok 插件(我仍然不确定 json 插件的用途)。但我无法获得所有领域的事件。我得到了多个事件(甚至对于我的 JSON 的每个属性都有一个)。像这样:
{
"message" => " \"SOURCE\": \"Source A\",",
"@version" => "1",
"@timestamp" => "2014-08-31T01:26:23.432Z",
"type" => "my-json",
"tags" => [
[0] "tag-json"
],
"host" => "myserver.example.com",
"path" => "/opt/mount/ELK/json/mytestjson.json"
}
{
"message" => " \"Model\": \"ModelABC\",",
"@version" => "1",
"@timestamp" => "2014-08-31T01:26:23.438Z",
"type" => "my-json",
"tags" => [
[0] "tag-json"
],
"host" => "myserver.example.com",
"path" => "/opt/mount/ELK/json/mytestjson.json"
}
{
"message" => " \"Qty\": \"3\",",
"@version" => "1",
"@timestamp" => "2014-08-31T01:26:23.438Z",
"type" => "my-json",
"tags" => [
[0] "tag-json"
],
"host" => "myserver.example.com",
"path" => "/opt/mount/ELK/json/mytestjson.json"
}
我应该使用多行编解码器还是 json_lines 编解码器?如果是这样,我该怎么做?我是否需要编写自己的 grok 模式,或者是否有一些通用的 JSON 可以给我一个带有键的事件:我为上面的一个事件获得的值对?我找不到任何说明这一点的文档。任何帮助,将不胜感激。我的 conf 文件如下所示:
input
{
file
{
type => "my-json"
path => ["/opt/mount/ELK/json/mytestjson.json"]
codec => json
tags => "tag-json"
}
}
filter
{
if [type] == "my-json"
{
date { locale => "en" match => [ "RECEIVE-TIMESTAMP", "yyyy-mm-dd HH:mm:ss" ] }
}
}
output
{
elasticsearch
{
host => localhost
}
stdout { codec => rubydebug }
}