Hi,
I have the following use case for telegraf:
I want to obtain a Bearer token with the inputs.http plugin and use this token to authenticate with an API endpoint in the outputs.http plugin.
I have the following problem:
The variable ${access_token} in the outputs.http config is not replaced with the actual token. The actual token is sent to the target url in the body as a JSON object, but not in the header.
I have the following config:
[[inputs.http]]
urls = ["ip-address/api/v1.0/auth/token"]
method = "POST"
success_status_codes = [201]
headers = { "Content-Type" = "application/json" }
json_string_fields = [
"access_token",
"token_type",
]
data_format = "json"
body = '''{"name": "username","password": "password"}'''
tls_enable = true
insecure_skip_verify = true
[[outputs.http]]
url = "https://my-subdomain.requestcatcher.com/test"
method = "PUT"
data_format = "json"
tls_enable = true
insecure_skip_verify = true
[outputs.http.headers]
"Content-Type" = "application/json"
"Authorization" = "Bearer ${access_token}"
The http message that the server received looks like this:
PUT /test HTTP/1.1
Host: my-subdomain.requestcatcher.com
Accept-Encoding: gzip
Authorization: Bearer ${access_token}
Content-Length: 631
Content-Type: application/json
User-Agent: Telegraf/1.29.4-e7dd111d Go/1.21.9
{"metrics":[{"fields":{"access_token":"my-access-token-redacted","token_type":"Bearer"},"name":"http","tags":{"host":"pc-hostname-redacted","url":"ip-address/api/v1.0/auth/token"},"timestamp":1733842790}]}
Is there a way to get the token from the input into the header of the output? And can you prevent the output plugin to send the token in the body?
Help would be very much appreciated <3