【问题标题】:Logstash parsing jsonLogstash 解析 json
【发布时间】:2021-02-22 07:12:00
【问题描述】:

我正在尝试使用 log-stash 以 JSON 格式读取输入文件 1.log 并在 elasticsearch 上写入。这是我的日志文件:

{"key":"value00"}
{"key":"value01"}
{"key1":[{"key2":"value02"},{"key3":"value03"},{"key4":[{"key5":"value 04"}]}]}

这是我的配置文件:

input {
  file {
    type => "json"
    path => "/logstash/1.log"
  }
}
filter{
  json {
    source => "message"
    remove_field => ["message"]
  }
}
output {
    elasticsearch {
        hosts => ["192.168.1.6:9200"]
        user => "elastic"
        password => "something"
    }
}

日志存储行为是完全随机的。有时它可以正常工作,但有时它会为相同的输入结构返回以下错误:

Error parsing json {:source=>"message", :raw=>"4\"}]}]}", :exception=>#<LogStash::Json::ParserError: Unexpected character ('"' (code 34)): Expected space separating root-level values

【问题讨论】:

    标签: logstash logstash-configuration


    【解决方案1】:

    我的建议:

    在调试过程中不要从一开始就删除消息,因为您不知道问题的根源是什么。 根据 json 过滤器结果有条件地执行此操作,如果失败,将其写入文件以确定它何时完全失败。

    根据我的经验,主要是输入错误或不希望以这种格式输入。

    基于您的配置的示例:

    input {
      file {
        type => "json"
        path => "/logstash/1.log"
      }
    }
    filter{
      json {
        source => "message"
      }
      if "_jsonparsefailure" not in [tags] {
        mutate {
          remove_field => ["message"]
        }
      }
    }
    output {
      if "_jsonparsefailure" not in [tags] {
        elasticsearch {
            hosts => ["192.168.1.6:9200"]
            user => "elastic"
            password => "something"
        }
      }
      if "_jsonparsefailure" in [tags] {
        file {
            path => "/write/to/this/file.txt"
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-03
      • 1970-01-01
      • 2015-04-29
      • 1970-01-01
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多