diff --git a/plugins/inputs/elasticsearch/README.md b/plugins/inputs/elasticsearch/README.md index fc09c1a03..e6e25aad6 100644 --- a/plugins/inputs/elasticsearch/README.md +++ b/plugins/inputs/elasticsearch/README.md @@ -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" diff --git a/plugins/inputs/elasticsearch/elasticsearch.go b/plugins/inputs/elasticsearch/elasticsearch.go index 0617a3beb..48e2d4104 100644 --- a/plugins/inputs/elasticsearch/elasticsearch.go +++ b/plugins/inputs/elasticsearch/elasticsearch.go @@ -96,19 +96,20 @@ type indexStat struct { // Elasticsearch is a plugin to read stats from one or many Elasticsearch // servers. type Elasticsearch struct { - Local bool `toml:"local"` - Servers []string `toml:"servers"` - 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"` - ClusterStats bool `toml:"cluster_stats"` - ClusterStatsOnlyFromMaster bool `toml:"cluster_stats_only_from_master"` - IndicesInclude []string `toml:"indices_include"` - IndicesLevel string `toml:"indices_level"` - NodeStats []string `toml:"node_stats"` - Username string `toml:"username"` - Password string `toml:"password"` - NumMostRecentIndices int `toml:"num_most_recent_indices"` + 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"` + ClusterStats bool `toml:"cluster_stats"` + ClusterStatsOnlyFromMaster bool `toml:"cluster_stats_only_from_master"` + IndicesInclude []string `toml:"indices_include"` + IndicesLevel string `toml:"indices_level"` + NodeStats []string `toml:"node_stats"` + Username string `toml:"username"` + Password string `toml:"password"` + NumMostRecentIndices int `toml:"num_most_recent_indices"` Log telegraf.Logger `toml:"-"` @@ -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 diff --git a/plugins/inputs/elasticsearch/sample.conf b/plugins/inputs/elasticsearch/sample.conf index 361c99e80..d8196d1a7 100644 --- a/plugins/inputs/elasticsearch/sample.conf +++ b/plugins/inputs/elasticsearch/sample.conf @@ -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"