解析Json错误Logstash

时间:2017-12-23 16:39:23

标签: logstash

我正在尝试读取json的日志通知并使用logstash将结果吐出到stdout我的json文件如下:

我想知道如何解析json

{"shoppers" : [
{
"type": "login",
"source": "user",
"triggered_at": "Login Screen",
"triggered_by": "Login Button",
"api_url": "<URL>",
"username": "Shopper123",
"timestamp": "17.04.2017 13:37:57"
},
{
"type": "logout",
"source": "user",
"triggered_at": "Account Screen",
"triggered_by": "User Pressed Logout Button",
"api_url": "<URL>",
"username": "Shopper123",
"timestamp": "17.04.2017 13:37:57"
}
]}

我的logstash conf示例文件如下所示: 你可以看到我正在从s3桶读取,我正在使用json过滤器,但结果总是显示我_parsejsonerror

input {
    s3 {
        access_key_id => '<access_key>'
        secret_access_key => '<secret_key>'
        bucket => 'some-bucket'
        region => 'eu-west-2'
        type => 'shopper_app'
        delete => true
        sincedb_path => "/home/user/logstash/last-s3-file"
        codec => json_lines
    }
}


filter {

    json {
        source => "message"
        add_field => ["type", "%{[message][type]}"]
    }
}



output
{
    stdout {codec => rubydebug}
}

1 个答案:

答案 0 :(得分:0)

实际上我解决了问题是由于格式错误的json文件造成的。 json文件不应包含新行,如下所示:

[{"type": "login","source": "user","triggered_at": "Login Screen","triggered_by": "Login Button","api_url": "<URL>","username": "Shopper123","timestamp": "17.04.2017 13:37:57"},{"type": "logout","source": "user","triggered_at": "Account Screen","triggered_by": "User Pressed Logout Button","api_url": "<URL>","username": "Shopper123","timestamp": "17.04.2017 13:37:57"}]

由于