# Telegraf: environment variable for http special header?

**URL:** <https://community.influxdata.com/t/telegraf-environment-variable-for-http-special-header/13039>\
**Category:** Telegraf\
**Tags:** telegraf\
**Created:** [February 14, 2020, 4:30pm UTC](https://community.influxdata.com/t/telegraf-environment-variable-for-http-special-header/13039 "2020-02-14T16:30:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![florentlm](https://avatars.discourse-cdn.com/v4/letter/f/87869e/32.png) [@florentlm](https://community.influxdata.com/u/florentlm)\
**Post date:** [February 14, 2020, 4:30pm UTC](https://community.influxdata.com/t/telegraf-environment-variable-for-http-special-header/13039/1 "2020-02-14T16:30:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daniel](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/daniel/32/142_2.png) [@daniel](https://community.influxdata.com/u/daniel)\
**Post date:** [February 15, 2020, 2:16am UTC](https://community.influxdata.com/t/telegraf-environment-variable-for-http-special-header/13039/2 "2020-02-15T02:16:25Z")

</div>

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:

```auto
source /etc/default/telegraf
telegraf --test

```

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

---

<div class="post-metadata">

**Author:** ![florentlm](https://avatars.discourse-cdn.com/v4/letter/f/87869e/32.png) [@florentlm](https://community.influxdata.com/u/florentlm)\
**Post date:** [February 15, 2020, 12:26pm UTC](https://community.influxdata.com/t/telegraf-environment-variable-for-http-special-header/13039/3 "2020-02-15T12:26:55Z")

</div>

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

```auto
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). 🤔

> 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
