Hi all,
I’am trying to parse CSV data embedded in JSON file. Here is a sample :
{
"T" : 1234,
"csv" : "20200708010001,100\n20200708010002,99\n20200708010003,98\n20200708010004,97\n20200708010005,96"
}
with the following telegraf conf file :
[[outputs.file]]
files = ["stdout"]
data_format = "json"
tagexclude = ["topic"]
fielddrop = ["csv", "T"]
[[inputs.mqtt_consumer]]
servers = ["${SERVER_MQTT}"]
name_override = "elec"
data_format = "json"
topics = [
"elec"
]
tag_keys = ["T"
]
json_string_fields = ["csv"]
[[processors.parser]]
parse_fields = ["csv"]
data_format = "csv"
merge = "override"
csv_column_names = ["time","value"]
csv_column_types = ["string","int"]
csv_timestamp_column = "time"
csv_timestamp_format = "20060102150405"
Here is the output JSON string:
{"fields":{"value":96},"name":"elec","tags":{"T":"1234"},"timestamp":1598623798}
And the issues :
1/ It seems that only the last line of CSV data is emitted.
2/ The timestamp is the current timestamp not the CSV “time” field
BTW, I previously used the CSV parser (with raw CSV data, no JSON stuff) directly in the inputs.mqtt_consumer plugins without any problem.
Thanks for your help,
BR