Skip to content

Cannot use both json_name_key and json_query in mqtt_consumer plugin #6990

@fredrikIOT

Description

@fredrikIOT

Relevant telegraf.conf:

[[inputs.mqtt_consumer]]
  servers = ["tcp://localhost:1883"]
  qos = 0
  connection_timeout = "30s"

  topics = [
    "test/#"
  ]
  tag_keys = ["tag"]

  persistent_session = false
  client_id = ""

  data_format = "json"
  json_name_key = "name"
  json_query = "values"

[[outputs.influxdb]]
  urls = ["http://localhost:8086"]
  database = "test_db"
  skip_database_creation = false

System info:

Telegraf version: 1.13.2
Environments: Linux mint, running a docker contariner with telegraf 1.13.2.

Steps to reproduce:

  1. Send this json on mqtt, with mqtt_consumer configurated like described above:
    {
    "name": "test_name",
    "timestamp": "2020-Feb-05 08:06:56.976",
    "values": {
    "temp_outside": 0.05285325646400452,
    "temp_indside": 0.007113146595656872
    }
    }

  2. The measurement name is not the value of the json key "name".

Expected behavior:

Measurement should be named according to the name key in the json message.

Actual behavior:

The measurement name is "mqtt_consumer", not the value in the "name" key.

Additional info:

If I comment out json_query, I get a measurement called "test_name" (like expected), but then i get "values_" as a prefix for all the field_keys ("values_temp_outside" and "values_temp_indside").

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/jsonjson and json_v2 parser/serialiser relatedfeature requestRequests for new plugin and for new features to existing plugins

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions