title: Can we nicely convert MQTT topic descriptions into InfluxDB tags, using the mqtt_consumer Telegraf input plugin?
body: <p>I am publishing data to MQTT topics with the Mosquitto broker, and am trying to pipe the data points through to my InfluxDB database. Currently I am trying to do this using the <a href="https://github.com/influxdata/telegraf/tree/master/plugins/inputs/mqtt_consumer" rel="nofollow noreferrer">mqtt_consumer</a> input plugin for Telegraf.</p>
  <p>A simplified version of my telegraf.conf file looks like this:</p>
  <pre><code># Global Agent Configuration
  [agent]
    interval = &quot;1m&quot;
  
  # Input Plugins 
  [[inputs.mqtt_consumer]]
    name_prefix = &quot;sensors_&quot;
    servers = [&quot;localhost:1883&quot;]
    qos = 0
    connection_timeout = &quot;30s&quot;
    topics = [
      &quot;/inside/kitchen/temperature&quot;
    ]
    persistent_session = false
    data_format = &quot;value&quot;
    data_type = &quot;float&quot;
  
  # Output Plugins
  [[outputs.influxdb]]
    database = &quot;telegraf&quot;
    urls = [ &quot;http://localhost:8086&quot; ]
  </code></pre>
  <p>Now, I can manually publish a data point using MQTT via the following:</p>
  <p><code> ~ $ mosquitto_pub -d -t /inside/kitchen/temperature -m 23.5</code></p>
  <p>where I have used the MQTT topic /inside/kitchen/temperature and a value of 23.5.</p>
  <p>Examining my InfluxDB database, I see the following data points:</p>
  <pre><code>name: sensors_mqtt_consumer
  time                 topic                        value
  ----                 -----                        -----
  2020-06-27T20:08:50  /inside/kitchen/temperature  23.5
  2020-06-27T20:08:40  /inside/kitchen/temperature  23.5
  </code></pre>
  <p>Is there any way that I can use the MQTT topic name description to properly allocate Influx tags? For example, I would like something like:</p>
  <pre><code>name: temperature
  time                location  room     value
  ----                -----     -----    -----
  2020-06-27T20:08:50 inside    kitchen  23.5
  2020-06-27T20:08:40 inside    kitchen  23.5
  </code></pre>
  <p>Is there a way to do this with the InfluxDB/Mosquitto/Telegraf configurations? Later I will be adding more topics (locations, etc) and measurements (humidity, voltage, etc), so the solution should allow for this.</p>
  <p>(I know that this can be done by by choosing <code>data_format = &quot;influx&quot;</code> as described <a href="https://github.com/influxdata/telegraf/tree/master/plugins/parsers/influx" rel="nofollow noreferrer">here</a>, where Telegraf interprets the message as InfluxDB line protocol and passes it through directly. However, then I would have to publish to the topic in this way:</p>
  <p><code>mosquitto_pub -d -t /inside/kitchen/temperature -m &quot;temperature,location=inside,room=kitchen value=23.5&quot;</code></p>
  <p>where you can see that most of the information has been input twice, even though it already existed. The same can be said for the data_format=&quot;json&quot; option. What I need is more of a mapping).</p>