influxdb – MQTT/Telegraf Parsing of json data

I have been attempting to build a Telegraf configuration file that would parse the following MQTT json payloads. The first is on a topic channel of “Pool” and the second is from a topic of “Log”.

{"Pool":{"Sequence":757,"Temp":75.20,"Humidity":18.00,"HeatIndex":73.27,"WiFiSignal":-49,"Lux":0.00,"InFlow":79.42,"OutFlow":79.97,"Pressure":-0.61,"Memory":25355}}
{"MKR1010-ENV":{"Seq":3,"DHTf":83.66,"DHTc":28.70,"DHTHumid":49.10,"WiFiSignal":-60,"ENVTemp":93.95,"ENVHumid":-16.85,"kPa":101.10,"Sun":55.38,"UVa":0.00,"UVb":0.00,"UVIndex":0.00,"DPSc":28.90,"hPa":1009.83,"Mem":25007}}

Using ChatGPT I was guided to the following MQTT entries for the telegraf.conf:

  ## Data format to consume.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md

  data_format = "json_v2"
  [[inputs.mqtt_consumer.json_v2]]
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "Pool"
      tags = ["Pool"]
      fields = [
        { name = "Sequence", type = "int"},
        { name = "Temp", type = "float"},
        { name = "Humidity", type = "float"},
        { name = "HeatIndex", type = "float"},
        { name = "WiFiSignal", type = "float"},
        { name = "InFlow", type = "float"},
        { name = "OutFlow", type = "float"},
        { name = "Pressure", type = "float"},
        { name = "Memory", type = "int"}
      ]
  [[inputs.mqtt_consumer.json_v2]]
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "Log"
      tags = ["MKR1010-ENV"]
      fields = [
        { name = "Seq", type = "int"},
        { name = "DHTf", type = "float"},
        { name = "DHTc", type = "float"},
        { name = "DHTHumid", type = "float"},
        { name = "WiFiSignal", type = "float"},
        { name = "ENVTemp", type = "float"},
        { name = "ENVHumid", type = "float"},
        { name = "kPa", type = "float"},
        { name = "Sun", type = "float"},
        { name = "UVa", type = "float"},
        { name = "UVb", type = "float"},
        { name = "UVIndex", type = "float"},
        { name = "DPSc", type = "float"},
        { name = "hPa", type = "float"},
        { name = "Mem", type = "int"},
      ]

But this results in an error of:

error loading config file /etc/telegraf/telegraf.conf: error parsing mqtt_consumer, adding parser failed: line 220: (json_v2.Object.Fields) cannot unmarshal TOML array table into map[string]string (need slice)

What should the telegraf.conf file contain to parse these two MQTT channels?

Read more here: Source link