Skip to content

Commit 2e157ad

Browse files
committed
fix(agent): Add authorization and user-agent when watching remote configs
1 parent 01c633f commit 2e157ad

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cmd/telegraf/telegraf.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,20 @@ func (*Telegraf) watchRemoteConfigs(ctx context.Context, signals chan os.Signal,
273273
return
274274
case <-ticker.C:
275275
for _, configURL := range remoteConfigs {
276-
resp, err := http.Head(configURL) //nolint:gosec // user provided URL
276+
req, err := http.NewRequest("HEAD", configURL, nil)
277277
if err != nil {
278-
log.Printf("W! Error fetching config URL, %s: %s\n", configURL, err)
278+
log.Printf("W! Creating request for fetching config from %q failed: %v\n", configURL, err)
279+
continue
280+
}
281+
282+
if v, exists := os.LookupEnv("INFLUX_TOKEN"); exists {
283+
req.Header.Add("Authorization", "Token "+v)
284+
}
285+
req.Header.Set("User-Agent", internal.ProductToken())
286+
287+
resp, err := http.DefaultClient.Do(req)
288+
if err != nil {
289+
log.Printf("W! Fetching config from %q failed: %v\n", configURL, err)
279290
continue
280291
}
281292
resp.Body.Close()

0 commit comments

Comments
 (0)