feat(outputs.elasticsearch): Allow settings extra headers for elasticsearch output (#15477)

This commit is contained in:
Andrii Chubatiuk 2024-06-10 16:41:16 +03:00 committed by GitHub
parent 94a5ab60b8
commit fe092f6d08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 20 deletions

View File

@ -323,6 +323,11 @@ to use them.
## no pipeline is used for the metric.
# use_pipeline = "{{es_pipeline}}"
# default_pipeline = "my_pipeline"
#
# Custom HTTP headers
# To pass custom HTTP headers please define it in a given below section
# [outputs.elasticsearch.headers]
# "X-Custom-Header" = "custom-value"
```
### Permissions
@ -389,6 +394,8 @@ the `default_tag_value` will be used instead.
instead.
* `default_pipeline`: If dynamic pipeline names the tag does not exist in a
particular metric, this value will be used instead.
* `headers`: Custom HTTP headers, which are passed to Elasticsearch header
before each request.
## Known issues

View File

@ -47,6 +47,7 @@ type Elasticsearch struct {
Timeout config.Duration `toml:"timeout"`
URLs []string `toml:"urls"`
UsePipeline string `toml:"use_pipeline"`
Headers map[string]string `toml:"headers"`
Log telegraf.Logger `toml:"-"`
majorReleaseNumber int
pipelineName string
@ -183,6 +184,16 @@ func (a *Elasticsearch) Connect() error {
elastic.SetGzip(a.EnableGzip),
)
if len(a.Headers) > 0 {
headers := http.Header{}
for k, vals := range a.Headers {
for _, v := range strings.Split(vals, ",") {
headers.Add(k, v)
}
}
clientOptions = append(clientOptions, elastic.SetHeaders(headers))
}
authOptions, err := a.getAuthOptions()
if err != nil {
return err

View File

@ -77,3 +77,8 @@
## no pipeline is used for the metric.
# use_pipeline = "{{es_pipeline}}"
# default_pipeline = "my_pipeline"
#
# Custom HTTP headers
# To pass custom HTTP headers please define it in a given below section
# [outputs.elasticsearch.headers]
# "X-Custom-Header" = "custom-value"