【问题标题】:json filter fails with >#<NoMethodError: undefined method `[]' for nil:NilClass>json 过滤器失败,出现 >#<NoMethodError: undefined method `[]' for nil:NilClass>
【发布时间】:2013-08-16 07:41:44
【问题描述】:

我正在尝试处理日志文件中的条目,该日志文件同时包含普通消息和 json 格式的消息。我最初的想法是 grep 用大括号括起来的消息,并让它们由另一个链式过滤器处理。 Grep 工作正常(与普通消息处理一样),但随后的 json 过滤器报告异常。我在下面附上了logstash的配置、输入和错误信息。

您有什么想法可能是什么问题吗?对于处理来自同一文件的普通和 json 格式的条目有任何替代建议吗?

非常感谢, 约翰内斯

错误信息:

Trouble parsing json {:key=>"@message", :raw=>"{\"time\":\"14.08.2013 10:16:31:799\",\"level\":\"DEBUG\",\"thread\":\"main\",\"clazz\":\"org.springframework.beans.factory.support.DefaultListableBeanFactory\",\"line\":\"214\",\"msg\":\"Returning cached instance of singleton bean 'org.apache.activemq.xbean.XBeanBrokerService#0'\"}", :exception=>#<NoMethodError: undefined method `[]' for nil:NilClass>, :level=>:warn}

logstash 配置:

file {
        path => [ "plain.log" ] 
        type => "plainlog" 
        format => "plain" 
    }
}
filter {
  # Grep json formatted messages and send them to following json filter
  grep {
    type => "plainlog"
    add_tag => [ "grepped_json" ]
    match => [ "@message", "^{.*}" ]
  }
  json {
    tags => [ "grepped_json" ]
    source => "@message"
  }
}
output { 
  stdout { debug => true debug_format => "json"}
  elasticsearch { embedded => true }
}

来自日志文件的输入(仅一行):

{"time":"14.08.2013 10:16:31:799","level":"DEBUG","thread":"main","clazz":"org.springframework.beans.factory.support.DefaultListableBeanFactory","line":"214","msg":"Returning cached instance of singleton bean 'org.apache.activemq.xbean.XBeanBrokerService#0'"}

【问题讨论】:

    标签: json logstash


    【解决方案1】:

    我遇到了同样的问题,并通过向 json 过滤器添加 target 来解决它。 文档确实说 target 是可选的,但显然不是。

    改变你应该有的例子:

    json {
      tags => [ "grepped_json" ]
      source => "@message"
      target => "data"
    }
    

    【讨论】:

    • 顺便说一句,在回复这个之后我注意到我所指的文档是针对1.2.0版本的。我测试了新版本,它不再需要 target
    猜你喜欢
    • 1970-01-01
    • 2015-03-19
    • 2016-08-13
    • 1970-01-01
    • 2016-01-02
    • 2012-08-08
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多