I think I have successfully achieved what I wanted to perform. However, it seems very complex for a thing that I thought quite basic.
I share it for the ones, that would like to perform the same thing. Do not hesitate to comment if you think that it could be optimised, because I am very new in telegraf.
The goal is to transform this MQTT message read by input.mqtt_consummer
/field1/field2/field3 XXX
To this influxdb line
field1,location=field3 field2=XXX
My telegraf configuration is the following (commented)
# Create the good "bucket" tag that will route the message to the correct bucket
# In: mqtt_consummer,topic=/field1/field2/field3 value=XXX
# Out: mqtt_consummer,topic=/field1/field2/field3,bucket=field1 value=XXX
[[processors.regex]]
order = 1
[[processors.regex.tags]]
key = "topic"
pattern = "^/([^/]*)/.*"
replacement = "$1"
result_key = "bucket"
# Rename to get the correct measurement name
# In: mqtt_consummer,topic=/field1/field2/field3,bucket=field1 value=XXX
# Out: field1,topic=/field1/field2/field3,bucket=field1 value=XXX
[[processors.converter]]
order = 2
[processors.converter.tags]
measurement = ["bucket"]
# Create a garbage tag, that will be exchanged with the field
# In: field1,topic=/field1/field2/field3,bucket=field1 value=XXX
# Out: field1,topic=/field1/field2/field3,bucket=field1,garbage=field2 value=XXX
[[processors.regex]]
order = 3
[[processors.regex.tags]]
key = "topic"
pattern = "^/[^/]+/([^/]+).*"
replacement = "$1"
result_key = "garbage"
# Extract the tag
# In: field1,topic=/field1/field2/field3,bucket=field1,garbage=field2 value=XXX
# Out: field1,topic=/field1/field2/field3,bucket=field1,garbage=field2,location=field3 value=XXX
[[processors.regex]]
order = 4
[[processors.regex.tags]]
key = "topic"
pattern = "^/[^/]+/[^/]+/(.*)"
replacement = "$1"
result_key = "location"
# Pivot the tag with the field
# In: field1,topic=/field1/field2/field3,bucket=field1,garbage=field2,location=field3 value=XXX
# Out: field1,topic=/field1/field2/field3,bucket=field1,location=field3 field2=XXX
[[processors.pivot]]
order = 5
tag_key = "garbage"
value_key = "value"
The remaining tags topic and bucket are removed by the output plugin.
Hope it will help someone.
Bill