Telegraf plugin inputs.mqtt_consumer: line 2: configuration specified the fields ["json_v2"], but they weren't used

loggik
Sat, 27 Apr 2024 20:27:30 +0000
Telegraf

Hi i try to setup telegraf to write mqtt messages to influxdb.
I got telegraf up and running but got error messages when trying to consume mqtt messages because the payload is json.
I found a blog post on how to parse json from mqtt-payloads: MQTT Topic and Payload Parsing with Telegraf | InfluxData
I tried it and of course it doesn’t work and sadly there are only config snippets instead of a complete config.
I get the following error:

plugin inputs.mqtt_consumer: line 2: configuration specified the fields ["json_v2"], but they weren't used

Why do i get this error? Why does telegraf think i try to specify the field “json_v2”

Here is my config:

[[inputs.mqtt_consumer]]
  [[inputs.mqtt_consumer.json_v2]]
    data_format = "json_v2"
    [[inputs.mqtt_consumer.json_v2]]
      [[inputs.mqtt_consumer.json_v2.field]]
        path = "humidity"
        type = "float"
      [[inputs.mqtt_consumer.json_v2.field]]
        path = "temperature"
        type = "float"
  ## Broker URLs for the MQTT server or cluster.  To connect to multiple
  ## clusters or standalone servers, use a separate plugin instance.
  ##   example: servers = ["tcp://localhost:1883"]
  ##            servers = ["ssl://localhost:1883"]
  ##            servers = ["ws://localhost:1883"]
  servers = ["tcp://192.168.178.38:1883"]

  ## Topics that will be subscribed to.
  topics = [
    "zigbee2mqtt/#",
  ]

Example mqtt message:

MQTT publish: topic 'zigbee2mqtt/Badezimmer', payload '{"battery":51,"humidity":51.99,"linkquality":93,"temperature":19.39,"voltage":2700}'

I can even try to use the config from the blog post and of course this also does not work:

data_format = "json_v2" # invokes the parser -- lines following are parser config
[[inputs.mqtt_consumer.json_v2]]
    [[inputs.mqtt_consumer.json_v2.tag]]
        path = "orientation" # GJSON path: JSON is flat -- all keys at root
    [[inputs.mqtt_consumer.json_v2.field]]
        path = "rpm"
        type = "int"
    [[inputs.mqtt_consumer.json_v2.tag]]
        path = "latitude"
        rename = "lat"
        type = "float"
    [[inputs.mqtt_consumer.json_v2.field]]
        path = "longitude"
        rename = "lon"
        type = "float"

invalid configuration, error parsing field “data_format” as table

5 posts - 2 participants