Mielzus
Mielzus

Reputation: 125

Logstash CSV output plugin

I am using Logstash to parse a file containing single line JSON data and output it in a CSV formatted file. Instead of outputting the data as nice separated values it is giving me single line data using timestamp, host, and message fields. I found this question on the official Logstash forums however it had no responses. Has anyone else encountered this issue and know how to fix it or have any suggestions? Thanks in advance.

Output

Current output

2017-02-08T16:48:45.907Z %{host} %{message}
2017-02-08T16:48:45.907Z %{host} %{message}
2017-02-08T16:48:45.907Z %{host} %{message}
2017-02-08T16:48:45.907Z %{host} %{message}
2017-02-08T16:48:45.907Z %{host} %{message}
2017-02-08T16:48:45.907Z %{host} %{message}

Desired output

timestamp, id, name
timestamp, id, name
timestamp, id, name

Config

input {
    file {
        path => "input path"
        sincedb_path => "C:\Logstash\.sincedb*"
        start_position => "beginning"
        codec => "json"
        type => "type"
    }
}

filter {
    mutate {
        add_field => {"eventName" => "%{[event][eventName]}"}
        add_field => {"uniqueDeviceID" => "%{[event][deviceSegment][uniqueDeviceID]}"}
    }
    prune {
        whitelist_names => ["eventName", "uniqueDeviceID", "@timestamp"]
    }
}

output {
    stdout {codec => rubydebug}
    csv {
        fields => ["uniqueDeviceID", "eventName", "@timestamp"]
        path => "output path"
    }
}

Upvotes: 1

Views: 9090

Answers (1)

Related Questions