I am receiving json formatted data with mqtt. The problem is that I can not set the json_name_key and the tag_keys with external properties which are not inside the json_query subset.
I have solved the issue. It is not the cleanest way, but you can create your own plugin. I have made slight changes to the mqtt_consumer plugin source code to add the external fields into each element of the array before passing it to the json parser. Finally I add these fields as tags in the telegraf.conf tag_keys array.
To create your own plugin you can follow this guide:
To sum up, the steps are:
Download the telegraf source code
In the telegraf/inputs folder, duplicate the mqtt_consumer and change the name.
Make the necessary modifications in the go file
Add the plugin in this file imports: plugins/inputs/all/all.go
Just go back in the telegraf folder and do make
Once it is compiled, you have a new telegraf executable, you can launch it with ./telegraf --config <you-own-custom-telegraf.conf>