Telegraft unauthorized to connect - even with a token

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:

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:

[[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:

  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?

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:

  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
1 Like

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. :slight_smile:

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 :slight_smile: . Looking forward to hearing from you again at some point.

Many thanks,
Jay

1 Like