Add basic auth to prometheus input plugin (#6062)
This commit is contained in:
parent
5bad2c3a43
commit
f7e85ebac2
|
@ -33,6 +33,11 @@ in Prometheus format.
|
||||||
## OR
|
## OR
|
||||||
# bearer_token_string = "abc_123"
|
# bearer_token_string = "abc_123"
|
||||||
|
|
||||||
|
## HTTP Basic Authentication username and password. ('bearer_token' and
|
||||||
|
## 'bearer_token_string' take priority)
|
||||||
|
# username = ""
|
||||||
|
# password = ""
|
||||||
|
|
||||||
## Specify timeout duration for slower prometheus clients (default is 3s)
|
## Specify timeout duration for slower prometheus clients (default is 3s)
|
||||||
# response_timeout = "3s"
|
# response_timeout = "3s"
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,10 @@ type Prometheus struct {
|
||||||
BearerToken string `toml:"bearer_token"`
|
BearerToken string `toml:"bearer_token"`
|
||||||
BearerTokenString string `toml:"bearer_token_string"`
|
BearerTokenString string `toml:"bearer_token_string"`
|
||||||
|
|
||||||
|
// Basic authentication credentials
|
||||||
|
Username string `toml:"username"`
|
||||||
|
Password string `toml:"password"`
|
||||||
|
|
||||||
ResponseTimeout internal.Duration `toml:"response_timeout"`
|
ResponseTimeout internal.Duration `toml:"response_timeout"`
|
||||||
|
|
||||||
tls.ClientConfig
|
tls.ClientConfig
|
||||||
|
@ -75,6 +79,11 @@ var sampleConfig = `
|
||||||
## OR
|
## OR
|
||||||
# bearer_token_string = "abc_123"
|
# bearer_token_string = "abc_123"
|
||||||
|
|
||||||
|
## HTTP Basic Authentication username and password. ('bearer_token' and
|
||||||
|
## 'bearer_token_string' take priority)
|
||||||
|
# username = ""
|
||||||
|
# password = ""
|
||||||
|
|
||||||
## Specify timeout duration for slower prometheus clients (default is 3s)
|
## Specify timeout duration for slower prometheus clients (default is 3s)
|
||||||
# response_timeout = "3s"
|
# response_timeout = "3s"
|
||||||
|
|
||||||
|
@ -251,6 +260,8 @@ func (p *Prometheus) gatherURL(u URLAndAddress, acc telegraf.Accumulator) error
|
||||||
req.Header.Set("Authorization", "Bearer "+string(token))
|
req.Header.Set("Authorization", "Bearer "+string(token))
|
||||||
} else if p.BearerTokenString != "" {
|
} else if p.BearerTokenString != "" {
|
||||||
req.Header.Set("Authorization", "Bearer "+p.BearerTokenString)
|
req.Header.Set("Authorization", "Bearer "+p.BearerTokenString)
|
||||||
|
} else if p.Username != "" || p.Password != "" {
|
||||||
|
req.SetBasicAuth(p.Username, p.Password)
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
|
|
Loading…
Reference in New Issue