Skip to content

json_v2 parser with wildcard mqtt topics produces lot of "GJSON Path returned null" errors #10072

@reimerp

Description

@reimerp

Relevent telegraf.conf

[[inputs.mqtt_consumer]]
  topics = [
    "home/+/tele"
  ]
  [[inputs.mqtt_consumer.json_v2]]
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "BME280"
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "TSL2561"
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "ATC*"
      tags = ["mac"]
    [[inputs.mqtt_consumer.json_v2.object]]
      path = "DS18B20"
      tags = ["Id"]

System info

Telegraf 1.20.3

Docker

No response

Steps to reproduce

Using json_v2 seems ok for input with a unique schema, but when using in an mqtt input on wildcard topics this is not true and you will get tons of errors (even if output is correct)

I have a couple of tasmota device sending mqtt data on topics "home/device/tele"
Each device sends Json Objects, grouped on their sensor types, eg:

home/ds18/tele {"DS18B20":{"Id":"000F98431670","Temperature":18.9}}
home/atc/tele {"ATCxxxxxx":{"mac":"a4c138xxxxxx","Temperature":24.1,"Humidity":63.0}}

or multiple objects if multiple sensors are present on one single device, eg:

home/esp32/tele {"BME280":{"Temperature":23.6,"Humidity":76.6, "Pressure":1015.6},"TSL2561":{"Illuminance":10.950}}

if they are all read in one mqtt_input by using mqtt wildcards, eg "home/+/tele"
there is no distinct schema on the input json stream which leads to many "GJSON Path returned null" errors.

I can get around this with the old JSON parse (with has other drawbacks) using tons of regex or string replace.

Expected behavior

no errors if object is not present.
maybe an additonal config directive marking objects optional would help.

Actual behavior

[2021-11-06T11:37:55Z E! [inputs.mqtt_consumer] Error in plugin: GJSON Path returned null]

Additional info

No response

Metadata

Metadata

Assignees

Labels

area/jsonjson and json_v2 parser/serialiser relatedarea/mqttbugunexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions