2017-04-07 95 views
0

我复制如何筛选{“foo”:“bar”,“bar”:“foo”} grok只获取foo字段?

{"name":"myapp","hostname":"banana.local","pid":40161,"level":30,"msg":"hi","time":"2013-01-04T18:46:23.851Z","v":0} 

https://github.com/trentm/node-bunyan并将其保存为我的logs.json。我试图通过LogStash将两个字段(名称和味精)导入ElasticSearch。问题是我依赖于一种我无法完成的过滤器。那么我已经成功地将这一行作为一条消息导入,但在我的真实情况下肯定不值得。

这就是说,我如何才能将名称和味精导入ElasticSearch?我使用http://grokdebug.herokuapp.com/测试了几种替代方案,以达到一个有用的过滤器,但根本没有成功。

例如,%{GREEDYDATA:message}会将整行作为唯一消息,但如何拆分它并忽略名称和消息字段以外的所有内容?

最后,我刨用在这里:

input { 
    file { 
     type => "my_type" 
     path => [ "/home/logs/logs.log" ] 
     codec => "json" 
    } 
} 

filter {  

    grok { 
      match => { "message" => "data=%{GREEDYDATA:request}"}   
     } 
#### some extra lines here probably 
} 

output 
{ 
    elasticsearch { 
    codec => json 
    hosts => "http://127.0.0.1:9200" 
    index => "indextest" 
    } 

    stdout { codec => rubydebug } 
} 

回答

0

我刚刚通过的available Logstash filters列表中消失了。 prune filter应该符合您的需求。

假定您已经安装了prune filter,你的配置文件应该是这样:

input { 
    file { 
    type => "my_type" 
    path => [ "/home/logs/logs.log" ] 
    codec => "json" 
    } 
} 

filter { 
    prune { 
    whitelist_names => [ 
     "@timestamp", 
     "type", 
     "name", 
     "msg" 
    ] 
    } 
} 

output { 
    elasticsearch { 
    codec => json 
    hosts => "http://127.0.0.1:9200" 
    index => "indextest" 
    } 

    stdout { codec => rubydebug } 
} 

请注意,你会希望保持type为Elasticsearch索引它变成一个正确的类型。如果您要查看Kibana上的数据,则需要@timestamp

相关问题