无法通过Logstash从文件导入json数据

时间:2016-12-27 09:32:54

标签: json elasticsearch logstash

我尝试从日志文件mylogs.log导入JSON数据。以下是我的logstash配置文件。

input {
    stdin { }

    file {
        codec => "json"
        path => "/logs/mylogs.log"
        start_position => "beginning"
        sincedb_path => "/dev/null"
    }
}

filter{
    json{
        source => "message"
    }
}

output {
    elasticsearch {
        hosts => ["localhost:9200"]
        index => "jsonlog"
    }

    stdout { codec => rubydebug }

    file {
        path => "/logs/out.log"
    }
}

执行此配置文件后,如果我传递了任何JSON数据,它就会得到解析&发送到Elasticsearch实例。我可以从Elasticsearch实例中看到。但是,无论日志文件中存在哪些数据都不会被logstash导入。

另外,当我手动添加Jash数据时,Logstash&发送Elasticsearch实例......那些数据也没有记录在我的OUTPUT文件中。

不知道是什么问题。

我使用的示例JSON数据。

{ "logger":"com.myApp.ClassName", "timestamp":"1456976539634", "level":"ERROR", "thread":"pool-3-thread-19", "message":"Danger. There was an error",  "throwable":"java.Exception" }
{ "logger":"com.myApp.ClassName", "timestamp":"1456976539649", "level":"ERROR", "thread":"pool-3-thread-16", "message":"I cannot go on", "throwable":"java.Exception" } 

1 个答案:

答案 0 :(得分:0)

好的,在Lagstash配置文件中进行以下修改文件路径插件后,它现在正在工作。

input {
    stdin { }

    file {
        codec => "json"
        path => "/home/suresh/Desktop/tools/logstash-5.1.1/logs/mylogs.log"
        start_position => "beginning"
        sincedb_path => "/dev/null"
    }
}

filter{
    json{
        source => "message"
    }
}

output {
    elasticsearch {
        hosts => ["localhost:9200"]
        index => "jsonlog2"
    }

    stdout { codec => rubydebug }

    file {
        path => "/home/suresh/Desktop/tools/logstash-5.1.1/logs/out.log"
    }
}

但是,我收到了"tags" => [ [0] "_jsonparsefailure" ]

的错误

来自控制台的回应 -

{
          "path" => "/home/suresh/Desktop/tools/logstash-5.1.1/logs/mylogs.log",
    "@timestamp" => 2016-12-27T09:56:08.854Z,
         "level" => "ERROR",
        "logger" => "com.myApp.ClassName",
     "throwable" => "java.Exception",
      "@version" => "1",
          "host" => "BLR-SOFT-245",
        "thread" => "pool-3-thread-19",
       "message" => "Danger. There was an error",
     "timestamp" => "1456976539634",
          "tags" => [
        [0] "_jsonparsefailure"
    ]
}