# Telegraft unauthorized to connect - even with a token

**URL:** <https://community.influxdata.com/t/telegraft-unauthorized-to-connect-even-with-a-token/21997>\
**Category:** Telegraf\
**Tags:** influxdb, telegraf\
**Created:** [October 7, 2021, 11:48am UTC](https://community.influxdata.com/t/telegraft-unauthorized-to-connect-even-with-a-token/21997 "2021-10-07T11:48:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattias](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/mattias/32/8498_2.png) [@mattias](https://community.influxdata.com/u/mattias)\
**Post date:** [October 7, 2021, 11:48am UTC](https://community.influxdata.com/t/telegraft-unauthorized-to-connect-even-with-a-token/21997/1 "2021-10-07T11:48:41Z")

</div>

I have a influxdb, grafana setup, using Telegraf to feed it.  
On the “localhost” I use telegraf, I created it’s token inside influxdb gui and it works. So now onto the next machine I want to fetch metrics from. I create an new bucket (why not?), create an rw token for that bucket. Create an telegram.conf on that machine fix it and start telegram using docker-compose.  
This is what I get:

```auto
E! [agent] Error writing to outputs.influxdb_v2: failed to write metric (401 Unauthorized): unauthorized: unauthorized access

```

This is the part where the output is set:

```auto
[[outputs.influxdb_v2]]
urls = ["http://10.1.1.150:8086"]
token = "${INFLUX_TOKEN}"
organization = "home"
bucket = "dockerone"

```

And here is the docker-compose for telegraf:

```auto
  telegraf:
    image: telegraf:latest
    pid: "host"
    container_name: telegraf
    ports:
      - 8092:8092
      - 8094:8094
      - 8125:8125
    volumes:
      - ./appdata/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /sys:/host/sys:ro
      - /proc:/host/proc:ro
      - /etc:/host/etc:ro
    environment:
      - HOST_PROC=/host/proc
      - HOST_SYS=/host/sys
      - HOST_ETC=/host/etc
    restart: unless-stopped

```

I have tried with two different tokens, the one I created for that bucket and I got a access all token same error. I tried redoing the token for the bucket, still the same error.  
I have created the two token the same way, they look the same in influxgui.

What have I missed?

---

<div class="post-metadata">

**Author:** ![Jay\_Clifford](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jay_clifford/32/8287_2.png) [@Jay\_Clifford](https://community.influxdata.com/u/Jay_Clifford)\
**Post date:** [October 7, 2021, 12:58pm UTC](https://community.influxdata.com/t/telegraft-unauthorized-to-connect-even-with-a-token/21997/2 "2021-10-07T12:58:39Z")

</div>

> [@mattias](#):
>
> `INFLUX_TOKEN`

Hi there, nice to meet you and welcome to the community. Where are you setting the above environment variable within your docker-compose file?

My expectation would be this:

```auto
  telegraf:
    image: telegraf:latest
    pid: "host"
    container_name: telegraf
    ports:
      - 8092:8092
      - 8094:8094
      - 8125:8125
    volumes:
      - ./appdata/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /sys:/host/sys:ro
      - /proc:/host/proc:ro
      - /etc:/host/etc:ro
    environment:
      - HOST_PROC=/host/proc
      - HOST_SYS=/host/sys
      - HOST_ETC=/host/etc
      - INFLUX_TOKEN=<token> 
    restart: unless-stopped

```

---

<div class="post-metadata">

**Author:** ![mattias](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/mattias/32/8498_2.png) [@mattias](https://community.influxdata.com/u/mattias)\
**Post date:** [October 7, 2021, 2:39pm UTC](https://community.influxdata.com/t/telegraft-unauthorized-to-connect-even-with-a-token/21997/3 "2021-10-07T14:39:05Z")

</div>

I set in a .env file placed beside the docker-compose file.  
But the token is set inside the telegraf.conf isn’t that enough?

And also I di manage to solve it… it was due to that I pointed to another bucket.  
Changing the the one I create with the influxdb container and using a token to access that all started to work.

I am new to influxdb and all, so I need to read up on best practies. 🙂

---

<div class="post-metadata">

**Author:** ![Jay\_Clifford](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jay_clifford/32/8287_2.png) [@Jay\_Clifford](https://community.influxdata.com/u/Jay_Clifford)\
**Post date:** [October 7, 2021, 3:12pm UTC](https://community.influxdata.com/t/telegraft-unauthorized-to-connect-even-with-a-token/21997/4 "2021-10-07T15:12:50Z")

</div>

Hi Mattias,  
Interesting way of doing it, I have not considered that before. Glad you managed to solve your issue. Please post anytime, we are very happy to play as rubber ducks to get your question solved 🙂 . Looking forward to hearing from you again at some point.

Many thanks,  
Jay
