feat(inputs.prometheus): Add support for custom header (#12050)
This commit is contained in:
parent
6f407c5949
commit
d4eda21742
|
|
@ -98,6 +98,9 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
|||
# username = ""
|
||||
# password = ""
|
||||
|
||||
## Optional custom HTTP headers
|
||||
# headers = {"X-Special-Header" = "Special-Value"}
|
||||
|
||||
## Specify timeout duration for slower prometheus clients (default is 3s)
|
||||
# response_timeout = "3s"
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ type Prometheus struct {
|
|||
Username string `toml:"username"`
|
||||
Password string `toml:"password"`
|
||||
|
||||
HTTPHeaders map[string]string `toml:"http_headers"`
|
||||
|
||||
ResponseTimeout config.Duration `toml:"response_timeout"`
|
||||
|
||||
MetricVersion int `toml:"metric_version"`
|
||||
|
|
@ -298,6 +300,12 @@ func (p *Prometheus) gatherURL(u URLAndAddress, acc telegraf.Accumulator) error
|
|||
req.SetBasicAuth(p.Username, p.Password)
|
||||
}
|
||||
|
||||
if p.HTTPHeaders != nil {
|
||||
for key, value := range p.HTTPHeaders {
|
||||
req.Header.Add(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
var resp *http.Response
|
||||
if u.URL.Scheme != "unix" {
|
||||
//nolint:bodyclose // False positive (because of if-else) - body will be closed in `defer`
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@
|
|||
# username = ""
|
||||
# password = ""
|
||||
|
||||
## Optional custom HTTP headers
|
||||
# headers = {"X-Special-Header" = "Special-Value"}
|
||||
|
||||
## Specify timeout duration for slower prometheus clients (default is 3s)
|
||||
# response_timeout = "3s"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue