How to make a python plugin that changes incoming data before it's sent to influxdb

hey, i’m receiving some sensor data (in json format) with telegraf and need to decrpyt the payload, there’s no existing plugin for this so the only option is to write my own. So far i’ve made a working script in python that decrypts the payload.

how would i go about implementing this in telegraf?
i’ve tried setting it up as a processors.execd and curling a sample json file with a sample payload. the data is unmodified. im not quite sure how stdin and stdout work in this context and i’d love to see some examples of python scripts that modify the passing data in any way.

I am pretty sure that there is a plugin for that, unless that by decrypt you actually mean “decrypt” using keys and passphrases and all of that encryption stuff.

if parsing was what you mean then:

Parser plugin

Data formats

Hey, i’ve translated this script from javascript to python.

I want each file to be processed through it and i can’t seem to find a way to implement the same logic in the processors mentioned. The modified python script looks for a specific key-value pair in the json document and runs it through the logic and simply rewrites the new value to the json. Can’t really say this is decrypting but this is what i meant with it.

@testiacco I would recommend to decode the payload directly using the binary parser. Alternatively you can use the starlark processor as starlark has a syntax similar to python. If all of the above does not work, you either can run your python code using the execd processor or, even better, code a parser in Golang and submit a PR. :wink:

like @srebhan said if you have your source data in binary format the binary parser will be the best solution, you were the one that did it @srebhan right? I remember seeing that lambda icon before, kudos to your work, the documentation was not as easy to understand for me but investing some time and doing some trial and error I could figure it out.

exceed processor and custom code may work too, I did my own “binary to ascii” using Go before the binary plugin was added to Telegraf. the only reason I have not upgraded to binary parser is because “if it ain’t broke don’t fix it” but sure binary parser is more robust and efficient.

1 Like