feat(inputs.elasticsearch): Add support for custom headers (#15544)

This commit is contained in:
Rob Sears 2024-06-24 15:31:29 -05:00 committed by GitHub
parent 78cbf533d2
commit 27eee98eca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 13 deletions

View File

@ -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"

View File

@ -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

View File

@ -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"