Skip to content

Commit

Permalink
Adding support for custom http headers and TLS for metricbeat modules (
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel authored and ruflin committed Apr 7, 2017
1 parent f3079d9 commit 3f1c7c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
41 changes: 38 additions & 3 deletions metricbeat/helper/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
}
Expand Down

0 comments on commit 3f1c7c0

Please sign in to comment.