How to parse the topic name into the measurement metrics

Hi ,

I would like to connect telegraph to a mosquitto broker by subscribing to the topic “+/update/#”.
This is how the received message look like

topic: 02000001000047F9/update/zb/dev/6/ldev/humidity/data/humidity
message: {"key":"humidity","name":"Relative Humidity","type":"double","unit":"% RH","access":"r","lastUpdated":"2019-01-11T09:29:18.327+01:00[Europe/Copenhagen]","value":34.0}

topic: 02000001000047F9/update/zb/dev/6/ldev/temperature/data/temperature
message: {"key":"temperature","name":"Measured Temperature","type":"double","unit":"°C","access":"r","lastUpdated":"2019-01-09T15:32:31.921+01:00[Europe/Copenhagen]","value":26.0}

topic: 02000001000047F9/update/zb/dev/1/ldev/humidity/data/humidity
message: {"key":"humidity","name":"Relative Humidity","type":"double","unit":"% RH","access":"r","lastUpdated":"2019-01-11T09:29:18.327+01:00[Europe/Copenhagen]","value":34.0}

topic: 02000001000047F9/update/zb/dev/1/ldev/temperature/data/temperature
message: {"key":"temperature","name":"Measured Temperature","type":"double","unit":"°C","access":"r","lastUpdated":"2019-01-09T15:32:31.921+01:00[Europe/Copenhagen]","value":26.0}

The topic name keeps on changing based on the device (1/2/3/…) , ldev (temperature/humidity/voc/…), data(temperature/humidity/voc/…). Hence i would like to parse the topic name into the metrics field for example

topic: 02000001000047F9/update/zb/dev/6/ldev/humidity/data/humidity
message: {"key":"humidity","name":"Relative Humidity","type":"double","unit":"% RH","access":"r","lastUpdated":"2019-01-11T09:29:18.327+01:00","value":34.0}

After conversion it should look like this.

measurement: humidity
tags: "id": "6", "data" : "humidity"
fields: "humidity" : 34.0

Going through the documentation, i understood the dataflow go like this “MQTT Consumer Input Plugin” → " Input Data Formats" → JSON But i am not sure how achieve the above conversion from topic name to the measurement and tags fields.

Thanks .

Unfortunately, it isn’t possible to make this transformation with the JSON data format, is there any possibility to change the incoming data?

Unfortunately, the gate way is bought online and we have no control on the gateway. So far, it can only be MQTT publisher with json format. I just wrote one more MQTT Client in python script that subscribes to the topic and does all the necessary transformations publish it back to the broker.