【发布时间】:2017-02-08 17:26:17
【问题描述】:
我正在使用 Logstash 解析包含单行 JSON 数据的文件,并将其输出为 CSV 格式的文件。它不是将数据输出为很好的分隔值,而是使用时间戳、主机和消息字段为我提供单行数据。我在 Logstash 官方论坛上找到了this question,但没有任何回应。有没有其他人遇到过这个问题并知道如何解决它或有任何建议?提前致谢。
输出
电流输出
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}
期望的输出
timestamp, id, name
timestamp, id, name
timestamp, id, name
配置
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"
}
}
【问题讨论】:
-
那么标准输出 rubydebug 输出看起来正确,而 csv 输出有这个问题?
-
如果您使用的是 Logstash 5,这个答案可能会有所帮助:stackoverflow.com/questions/41681873/…
-
Logstash 5.x 是我的问题。我最终在这里找到了解决方案github.com/logstash-plugins/logstash-output-csv/pull/11。拉取请求中的更改使其对我有用。
标签: csv logstash logstash-configuration