Logstash只发送json

问题描述 投票:0回答:3

我通过logstash发送这个日志

2017-02-27T13:00:07+01:00    test    {"createdAt":"2017-02-27T13:00:07+0100","cluster":"undefined","nodeName":"undefined","nodeIP":"10.11.11.50","clientIP":"10.11.11.72","customerId":1,"identityId":332,"appType":"admin","eventGroup":"education","eventName":"insert","eventData":{"education_insert":{"type":"course","data":{"education_id":2055,"education":{"id":2055,"customer_id":1,"creator_id":332,"type":"course","status":"new","is_featured":false,"enroll_deadline":null,"complete_deadline":null,"count_view":0,"count_like":0,"meta_title":"test Course - progress","meta_description":"test Course - progress","discoverable":"everyone","progress_max":0,"instructor_ids":[332],"tag_ids":[135],"discoverable_group_ids":[],"category_ids":[14],"audits":null,"instructors":null,"creator":null,"lessonGroups":null,"categories":null},"duration":"quick"}}},"scopeType":"education","scopeId":"2055"}

我怎么能删除2017-02-27T13:00:07+01:00test.app.event

json logstash logstash-grok
3个回答
1
投票

您需要使用grok提取消息的json部分,然后使用json过滤器将提取的json转换为事件。最后,您需要使用在最终事件中不需要的mutate删除任何字段(例如,message)。


0
投票

您可以使用正则表达式模式,以便只获得jsonregex模式应该在您的模式文件中:

模式可能如下所示:

REQUIREDDATA {([^}]*)}([^}]*)([^}]*)}}}([^}]*)} <-- this extracts only your json part

正在测试的正则表达式pattern

此后,您可以在grok匹配中使用该模式:

grok {
    patterns_dir => ["/pathto/patterns"]
    match => { "message" => "^%{REQUIREDDATA:new}" }            
}

现在消息只有你的日志行中的JSON部分,因此你现在可以通过logstash将它们推送到ES。以上只是一个示例,以便您可以重现。

希望能帮助到你!


0
投票

我用这个并为我工作:) thx寻求帮助

input { kafka { bootstrap_servers=>"localhost:9092" topics=>"test"}}
filter{
grok {
    match => { "message" => "%{TIMESTAMP_ISO8601:timestamp}\t%{GREEDYDATA:topic}\t%{GREEDYDATA:json}" }
  }
  json {
     source => "json"
     remove_field => ["timestamp","topic","json","message","@version","@timestamp","tags"]
  }
 }
output{ elasticsearch {hosts=>["127.0.0.1:9200"] document_type=>"app_stats" index=>"test"}}
© www.soinside.com 2019 - 2024. All rights reserved.