diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 1e6e669f8ed..3e30a8cc0cb 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -116,6 +116,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff] - Add experimental metricset `perfmon` to Windows module. {pull}3758[3758] - Add memcached module with stats metricset. {pull}3693[3693] - Add the `process.cmdline.cache.enabled` config option to the System Process Metricset. {pull}3891[3891] +- Adding support for custom http headers and TLS for metricbeat modules {pull}3945[3945] - Add new MetricSet interfaces for developers (`Closer`, `ReportingFetcher`, and `PushMetricSet`). {pull}3908[3908] *Packetbeat* diff --git a/metricbeat/helper/http.go b/metricbeat/helper/http.go index d103cad5d79..cc397c5b73f 100644 --- a/metricbeat/helper/http.go +++ b/metricbeat/helper/http.go @@ -8,7 +8,10 @@ import ( "io" "io/ioutil" "net/http" + "time" + "github.com/elastic/beats/libbeat/outputs" + "github.com/elastic/beats/libbeat/outputs/transport" "github.com/elastic/beats/metricbeat/mb" ) @@ -22,10 +25,42 @@ type HTTP struct { // NewHTTP creates new http helper func NewHTTP(base mb.BaseMetricSet) *HTTP { + config := struct { + TLS *outputs.TLSConfig `config:"ssl"` + Timeout time.Duration `config:"timeout"` + Headers map[string]string `config:"headers"` + }{} + if err := base.Module().UnpackConfig(&config); err != nil { + return nil + } + + if config.Headers == nil { + config.Headers = map[string]string{} + } + + tlsConfig, err := outputs.LoadTLSConfig(config.TLS) + if err != nil { + return nil + } + + var dialer, tlsDialer transport.Dialer + + dialer = transport.NetDialer(config.Timeout) + tlsDialer, err = transport.TLSDialer(dialer, tlsConfig, config.Timeout) + if err != nil { + return nil + } + return &HTTP{ - base: base, - client: &http.Client{Timeout: base.Module().Config().Timeout}, - headers: map[string]string{}, + base: base, + client: &http.Client{ + Transport: &http.Transport{ + Dial: dialer.Dial, + DialTLS: tlsDialer.Dial, + }, + Timeout: config.Timeout, + }, + headers: config.Headers, method: "GET", body: nil, }