Telegraf: environment variable for http special header?

Hi,

I use the Telegraf http plugin to query a server which requires authentication. This authentication is based a special header containing a special token. So far so good.

However, the server requires the token to be updated regularly (like once an hour), which causes my http plugin to lose the connection after a while if I hardcode the token in /etc/telegraf/telegraf.conf.

So, first question is, can I use an environment variable to define the header, like so:

[[inputs.http]]
    headers = {"X-My-Special-Header" = "${MYAUTH}"}

With, in /etc/default/telegraf:

MYAUTH="xxxxxxxxxxxxxxxxxxxxx"

?
It does not seem to work right now, I get a 403 error from the server (whereas it works fine if I hardcode directly the header and its value into /etc/telegraf/telegraf.conf).

Also, is this method the best one? I mean by this, does telegraf keep track of updates in /etc/default/telegraf without having to restart the telegraf service?

If not, do I have another option?

Many thanks

This will work, the /etc/default/telegraf file is only read if you run Telegraf as a service, perhaps that’s the issue? For testing you can source it first:

source /etc/default/telegraf
telegraf --test

When you update the file you will have to restart Telegraf.

Okay so I tested it and it seems to work indeed.
One weird thing is, when I do the

source /etc/default/telegraf
telegraf --test

it says in the test that the http plugins return a 403 error, but the actual telegraf service seems to grab the data just fine (I can see them real time in grafana). :thinking:

When you update the file you will have to restart Telegraf.

Okay so currently there’s no way to do it without restarting the service? I just have to add a systemctl restart telegraf somewhere in my custom auth checking service each time the header is updated?

Thanks daniel