I’m struggling to parse the message in the title:
{"${tagName}" : "${value}", "time": "${timestamp}"}
Where:
- tagName = any string
- value = int, float, bool or string
- timestamp is in this format: 2025-09-03T14:05:18Z
Ideally, I’d like to not have to change the original message format because it’s already being used in a data pipeline.
I’ve spent three days trying to piece this together using github, questions on this forum, and docs on the plugins I’m trying to use, but it’s beating both me and copilot.
I’ve started the process of writing my own plugin, but I can’t imagine there’s not someone else who’s parsed something like the above already, which theoretically looks really simple.
Please help if you can push me in the right direction!
Here are some configurations I’ve tried so far with errors from logs:
[[inputs.mqtt_consumer.json_v2]]
data_format = "json_v2"
[[inputs.mqtt_consumer.json_v2]]
measurement_name = "test_measurement"
[[inputs.mqtt_consumer.json_v2.object]]
path = "*"
2025-09-03T14:21:10Z E! [agent] Error writing to outputs.influxdb_v2: failed to write metrics to bucket “test_bucket”: 500 Internal Server Error: internal error: An internal error has occurred - check server logs
[[inputs.mqtt_consumer.xpath]]
timestamp = “time”
timestamp_format = “2006-12-25T15:04:01.235Z”
2025-09-03T11:15:09Z E! [inputs.mqtt_consumer] Error in plugin: failed to parse timestamp: parsing time “2025-09-03T11:15:58.308Z” as “2006-12-25T15:04:01.235Z”: cannot parse “-03T11:15:58.308Z” as “2”
timestamp = "time"
timestamp_format = "%Y-%m-%dT%H:%M:%S.%fZ"
[inputs.mqtt_consumer] Error in plugin: failed to parse timestamp: parsing time “2025-09-03T11:25:04.311Z” as “%Y-%m-%dT%H:%M:%S.%fZ”: cannot parse “2025-09-03T11:25:04.311Z” as “%Y-%m-%dT%H:%M:%S.%fZ”
[[inputs.mqtt_consumer.xpath]]
field_selection = "*"
[inputs.mqtt_consumer.xpath.tags]
2025-09-03T14:05:18Z E! loading config file /etc/telegraf/telegraf.conf failed: plugin inputs.mqtt_consumer: line 39: configuration specified the fields [“xpath”], but they were not used; this is either a typo or this config option does not exist in this version