Troubleshooting
Fix Telegraf authorization not found on InfluxDB 2
Short answer
authorization not found every 10 s means InfluxDB 2 is receiving Telegraf's writes and rejecting the token: the Windows service never saw INFLUX_TOKEN set in a separate CMD session, and token = "$INFLUX_TOKEN" is not the documented substitution form. Reference the variable as "${INFLUX_TOKEN}", deliver its value in the service's startup environment, restart, and confirm the Unauthorized lines stop and the bucket fills.
On this page
authorization not found in the InfluxDB 2 container log is an authentication rejection, not a connectivity fault: the write arrived, and the token string it carried matched no authorization. On the reported setup — InfluxDB 2.0.4 in Docker, Telegraf installed separately on Windows as a service — two faults sat in one line. The config referenced the token as "$INFLUX_TOKEN", a form Telegraf does not substitute, and the variable had been assigned only in a separate CMD window, so the service's environment never contained it. Write the line as token = "${INFLUX_TOKEN}", put the value where the service reads it at start, restart the service, and the Unauthorized lines and the empty bucket clear together.
What the log line rejects #
The line to match in the container log is:
ts=2021-04-19T12:53:51.723912Z lvl=info msg=Unauthorized log_id=0TbU2Hs0000 error="authorization not found"
InfluxDB 2 maps each API token to an authorization, a recorded set of permissions. This message means the string presented in the request resolved to no authorization at all — empty, literal, or revoked — so the write was refused before the bucket was touched. Three consequences, in the order you should use them:
- Requests are reaching the database, so the container's published port and
urls = ["http://localhost:8086"]are doing their job. - The refusal happens at the authorization step, so no change to
inputs.pingcan alter the outcome. - The bucket
testdb_1is empty because writes are refused, not because the input is quiet.
One scoping fact before you touch anything: tokens are listed in the UI under Load Data → API Tokens, and the InfluxDB issue tracker records that the 2.x UI could not display an existing token's value again. If you did not copy the token at creation, generate a new one with write permission on the bucket and carry that value from here on.
Timing the Unauthorized lines against the 10 s flush interval #
Inputs, each with its source:
- Four consecutive log lines from the container log of the reported case, at 12:53:51.723912Z, 12:54:01.736049Z, 12:54:11.742796Z and 12:54:21.745119Z.
- The agent settings of the same
telegraf.conf:interval = "10s",flush_interval = "10s",flush_jitter = "0s",collection_jitter = "0s".
Rule, in words: with both jitters at zero, the agent collects once per interval and attempts one flush per flush_interval, so InfluxDB should record exactly one rejected write per 10 s. A measured gap equal to the flush interval proves the service is running, the config is parsed, and the path to the database is open.
Arithmetic:
12:54:01.736049 - 12:53:51.723912 = 10.012137 s
12:54:11.742796 - 12:54:01.736049 = 10.006747 s
12:54:21.745119 - 12:54:11.742796 = 10.002323 s
mean gap = (10.012137 + 10.006747 + 10.002323) / 3 = 30.021207 / 3 = 10.007069 s
Result: every gap lands between 10.002 s and 10.013 s, within 0.013 s of the configured flush interval.
Decision: gaps within roughly 0.02 s of flush_interval mean the agent and the route to InfluxDB are healthy, and the entire fault is the token — fix the token line next. Gaps far longer than the flush interval, or no Unauthorized lines at all, would point upstream instead: agent stopped, output URL wrong, or the path blocked.
Two faults hiding in one token line #
The reported output block read:
[[outputs.influxdb_v2]]
urls = ["http://localhost:8086"]
token = "$INFLUX_TOKEN"
organization = "My Test Organization"
bucket = "testdb_1"
Fault one is the reference form. Telegraf substitutes environment variables enclosed in ${} before it parses the file, and the config's own header gives the string form quoted, as in "${STR_VAR}". A bare $INFLUX_TOKEN inside quotes is not substituted; the literal characters are sent to InfluxDB, where they match no authorization. The corrected line is token = "${INFLUX_TOKEN}".
Fault two is delivery. The variable was assigned in a separate CMD window, and that assignment exists only inside that window's process tree. The service, running under the Windows service host, read a different environment at its start — one with no token in it.
Keep organization and bucket exactly as the token was issued against: in the reported case the token carried read/write permission on the new bucket, so once an intact value arrived the write succeeded. The input plugin does not matter to this rule — the same output block serves a ping input or a pipeline that stores MQTT messages in InfluxDB with Telegraf.
Delivering the variable to the Windows service #
Pick one of two delivery paths:
- Production path: define
INFLUX_TOKENat machine scope in the Windows environment settings, then restart the Telegraf service. A service reads its environment once, at start, so the restart is part of the fix, not an option. - Diagnostic path: paste the token value directly between the quotes in
token = "...". This immediately resolved the reported case, and it splits the fault cleanly — if the direct token writes and the variable reference does not, the token and its permissions are good and the only remaining fault is delivery or substitution.
The diagnostic path leaves a live credential in the config file. If you keep it, restrict that file to the service account and administrators, and move the value into the machine-level variable once the fault is proven. On a Linux host the same principle surfaces as package upgrades rewriting configured files, and keeping INFLUX_TOKEN in the environment across package upgrades covers where the value belongs there.
Fix and verify, step by step #
- In the InfluxDB UI, open Load Data → API Tokens. If the existing token's value cannot be shown, generate a new token with write permission on
testdb_1and copy it now. - Change the output line to
token = "${INFLUX_TOKEN}". - Make the value visible to the service: machine-scope variable, or the direct paste from the diagnostic path.
- Restart the Telegraf service.
- Watch the container log: the Unauthorized entries must stop within one flush interval.
- In Data Explorer, select bucket
testdb_1with a time range that covers the restart;pingmeasurements should appear within the first interval or two.
When the errors stop but data does not appear #
At that point authentication is no longer the fault, and the search moves to the input and the query:
- Run
telegraf -config telegraf.conf -test, the check named in the config file's own header, to confirm the input produces metrics. A test run from your session proves the input only; it does not prove the service's environment. - Widen the Data Explorer time range before concluding anything, because the first points land at the restart moment.
- If Telegraf consumes MQTT and connects but nothing lands, the fault is on the consumer side, the case traced in Telegraf MQTT consumer connects but writes no data to InfluxDB.
- If writes to a database on another machine time out rather than get rejected, that is a network fault, not a token fault — the split shows up the same way when Node-RED writes to InfluxDB on another PC time out.
Questions asked
Why does the rejection repeat exactly every 10 seconds?
Because interval and flush_interval are both 10s with collection_jitter and flush_jitter at 0s, InfluxDB sees one write attempt per 10 s and logs one rejection per attempt. Raise flush_interval to 30s as a probe: the rejections should space out to 30 s, and if they do not, something other than this agent is generating the requests.
Can the Telegraf Windows service read INFLUX_TOKEN set in a CMD window?
No. A variable assigned in an interactive CMD window lives in that window's process tree and disappears with it. The service runs under the Windows service host with the environment it captured at start, so give it the value at machine scope or in the configuration, and restart the service after the value exists.
Why braces in ${INFLUX_TOKEN} rather than $INFLUX_TOKEN?
Telegraf replaces variables enclosed in ${} before parsing the configuration, and the file's own header shows the string form in quotes. Without the braces, the characters $INFLUX_TOKEN travel to InfluxDB as literal text and match no authorization, which produces exactly the authorization not found line you are chasing.
Is it acceptable to leave the token directly in the configuration file?
As a diagnostic, yes: the direct value is what proved the token and its permissions were valid in the reported case. As a permanent arrangement it puts a live credential in a text file, so restrict the file to the service account and administrators, and prefer the machine-level environment variable once delivery is proven.
The Unauthorized lines stopped but the bucket still looks empty. What next?
Check the Data Explorer time range first, because it must cover the restart moment for the first points to show. Then run telegraf -config telegraf.conf -test to confirm the input produces metrics. If both pass, read the Telegraf service log for output errors; authentication is no longer the active fault.