feat(inputs.elasticsearch): Add support for custom headers (#15544)
This commit is contained in:
parent
78cbf533d2
commit
27eee98eca
|
|
@ -46,6 +46,9 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
|||
## servers = ["http://user:pass@localhost:9200"]
|
||||
servers = ["http://localhost:9200"]
|
||||
|
||||
## HTTP headers to send with each request
|
||||
# headers = { "X-Custom-Header" = "Custom" }
|
||||
|
||||
## Timeout for HTTP requests to the elastic search server(s)
|
||||
## deprecated in 1.29.0; use 'timeout' instead
|
||||
http_timeout = "5s"
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ type indexStat struct {
|
|||
type Elasticsearch struct {
|
||||
Local bool `toml:"local"`
|
||||
Servers []string `toml:"servers"`
|
||||
HTTPHeaders map[string]string `toml:"headers"`
|
||||
HTTPTimeout config.Duration `toml:"http_timeout" deprecated:"1.29.0;1.35.0;use 'timeout' instead"`
|
||||
ClusterHealth bool `toml:"cluster_health"`
|
||||
ClusterHealthLevel string `toml:"cluster_health_level"`
|
||||
|
|
@ -641,6 +642,10 @@ func (e *Elasticsearch) getCatMaster(url string) (string, error) {
|
|||
req.SetBasicAuth(e.Username, e.Password)
|
||||
}
|
||||
|
||||
for key, value := range e.HTTPHeaders {
|
||||
req.Header.Add(key, value)
|
||||
}
|
||||
|
||||
r, err := e.client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -677,6 +682,10 @@ func (e *Elasticsearch) gatherJSONData(url string, v interface{}) error {
|
|||
req.SetBasicAuth(e.Username, e.Password)
|
||||
}
|
||||
|
||||
for key, value := range e.HTTPHeaders {
|
||||
req.Header.Add(key, value)
|
||||
}
|
||||
|
||||
r, err := e.client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@
|
|||
## servers = ["http://user:pass@localhost:9200"]
|
||||
servers = ["http://localhost:9200"]
|
||||
|
||||
## HTTP headers to send with each request
|
||||
# headers = { "X-Custom-Header" = "Custom" }
|
||||
|
||||
## Timeout for HTTP requests to the elastic search server(s)
|
||||
## deprecated in 1.29.0; use 'timeout' instead
|
||||
http_timeout = "5s"
|
||||
|
|
|
|||
Loading…
Reference in New Issue