Support passing bearer token directly in prometheus input (#5294)
This commit is contained in:
parent
a7b443c55b
commit
d759b46345
|
@ -25,8 +25,10 @@ in Prometheus format.
|
||||||
## - prometheus.io/port: If port is not 9102 use this annotation
|
## - prometheus.io/port: If port is not 9102 use this annotation
|
||||||
# monitor_kubernetes_pods = true
|
# monitor_kubernetes_pods = true
|
||||||
|
|
||||||
## Use bearer token for authorization
|
## Use bearer token for authorization. ('bearer_token' takes priority)
|
||||||
# bearer_token = /path/to/bearer/token
|
# bearer_token = "/path/to/bearer/token"
|
||||||
|
## OR
|
||||||
|
# bearer_token_string = "abc_123"
|
||||||
|
|
||||||
## 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"
|
||||||
|
|
|
@ -32,6 +32,7 @@ type Prometheus struct {
|
||||||
|
|
||||||
// Bearer Token authorization file path
|
// Bearer Token authorization file path
|
||||||
BearerToken string `toml:"bearer_token"`
|
BearerToken string `toml:"bearer_token"`
|
||||||
|
BearerTokenString string `toml:"bearer_token_string"`
|
||||||
|
|
||||||
ResponseTimeout internal.Duration `toml:"response_timeout"`
|
ResponseTimeout internal.Duration `toml:"response_timeout"`
|
||||||
|
|
||||||
|
@ -65,8 +66,10 @@ var sampleConfig = `
|
||||||
## - prometheus.io/port: If port is not 9102 use this annotation
|
## - prometheus.io/port: If port is not 9102 use this annotation
|
||||||
# monitor_kubernetes_pods = true
|
# monitor_kubernetes_pods = true
|
||||||
|
|
||||||
## Use bearer token for authorization
|
## Use bearer token for authorization. ('bearer_token' takes priority)
|
||||||
# bearer_token = /path/to/bearer/token
|
# bearer_token = "/path/to/bearer/token"
|
||||||
|
## OR
|
||||||
|
# bearer_token_string = "abc_123"
|
||||||
|
|
||||||
## 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"
|
||||||
|
@ -230,13 +233,14 @@ func (p *Prometheus) gatherURL(u URLAndAddress, acc telegraf.Accumulator) error
|
||||||
|
|
||||||
req.Header.Add("Accept", acceptHeader)
|
req.Header.Add("Accept", acceptHeader)
|
||||||
|
|
||||||
var token []byte
|
|
||||||
if p.BearerToken != "" {
|
if p.BearerToken != "" {
|
||||||
token, err = ioutil.ReadFile(p.BearerToken)
|
token, err := ioutil.ReadFile(p.BearerToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", "Bearer "+string(token))
|
req.Header.Set("Authorization", "Bearer "+string(token))
|
||||||
|
} else if p.BearerTokenString != "" {
|
||||||
|
req.Header.Set("Authorization", "Bearer "+p.BearerTokenString)
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
|
|
Loading…
Reference in New Issue