Hi community,
I need to pass a base64 encoded environment variable as constant to a starlark script.The value of the decoded variable is a json string which is required to extract matching data from a http response to return the related metrics.
…
[[processors.starlark]]
script = “/etc/telegraf/telegraf.d/examlpe/apply_metric_json.star”
[processors.starlark.constants]
myjson = “${MYJSON}” # base64 encoded environment variable
As the script returns valid metrics when I pass the json string as hard coded constant, it would be possible to either decode the base64 environment variable within telegraf before calling the script or to do the decoding within the starlark script.
Does anyone have any ideas on how this could be done?
Hello @pagules,
welcome!
Telegraf does support secret stores:
But it doesn’t look like the starlark plugin does.
You could maybe use execd to to decode the environment variable before sending it to Starlark.
But perhaps @srebhan has a better idea?
@pagules up to now, starlark is capable of decoding base64 encoded data. You would need to add this feature to the underlying Starlark library first…
Hello everybody,
First of all many thanks for your help an suggestions.
I now have found a simpler solution for my problem. Since the Telegraf service runs in a Docker container,this special environment variable will now be decoded and replaced it in the related conf file just before the container startup. Compared to decoding the variable on every relevant metric with the help of any tool, this seems to be quite more efficient. I wonder why I didn’t think of this earlier.