【问题标题】:Logstash is not converting correctly in JSONLogstash 未在 JSON 中正确转换
【发布时间】:2016-07-11 13:56:27
【问题描述】:

以下是我的 json 日志文件

[
    {
        "error_message": " Failed to get line from input file (end of file?).", 
        "type": "ERROR", 
        "line_no": "2625", 
        "file": "GTFplainText.c", 
        "time": "17:40:02", 
        "date": "01/07/16", 
        "error_code": "GTF-00014"
    }, 
    {
        "error_message": " Bad GTF plain text file header or footer line. ", 
        "type": "ERROR", 
        "line_no": "2669", 
        "file": "GTFplainText.c", 
        "time": "17:40:02", 
        "date": "01/07/16", 
        "error_code": "GTF-00004"
    }, 
    {
        "error_message": " '???' ", 
        "type": "ERROR", 
        "line_no": "2670", 
        "file": "GTFplainText.c", 
        "time": "17:40:02", 
        "date": "01/07/16", 
        "error_code": "GTF-00005"
    }, 
    {
        "error_message": " Failed to find 'event source'/'product detail' records for event source '3025188506' host event type 1 valid", 
        "type": "ERROR", 
        "line_no": "0671", 
        "file": "RGUIDE.cc", 
        "time": "15:43:48", 
        "date": "06/07/16", 
        "error_code": "RGUIDE-00033"
    }
]

据我了解由于日志已经在 json 中,我们不需要在 logstash 配置中的 filter 部分。以下是我的 logstash 配置

input {
  file{
    path => "/home/ishan/sf_shared/log_json.json"
    start_position => "beginning"
    codec => "json"
  }
}

输出配置为

output {
  elasticsearch {
    hosts => ["localhost:9200"]
    sniffing => true
    manage_template => false
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
    document_type => "%{[@metadata][type]}"
  }
  stdout { codec => rubydebug }
}

但是数据似乎没有进入 ES,因为我在查询索引时看不到数据。我错过了什么?

【问题讨论】:

    标签: json elasticsearch logstash


    【解决方案1】:

    我认为问题在于 json codec 期望在一行中包含完整的 json 消息,并且不适用于多行中的消息。

    一种可能的解决方法是使用多行法典并使用json filter
    多行编解码器的配置为:

    multiline {
      pattern => "]"
      negate => "true"
      what => "next"
    }
    

    所有不以] 开头的行都将与下一行重新组合,因此您将有一个完整的 json 文档提供给 json 过滤器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-29
      • 2020-06-21
      • 1970-01-01
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      相关资源
      最近更新 更多