Skip to content

Commit

Permalink
Add username/password in Metricbeat autodiscover hints (#15349) (#15417)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7d08f9b)
  • Loading branch information
ChrsMark authored Jan 9, 2020
1 parent 8718160 commit de4ea3f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix `docker.container.size` fields values {issue}14979[14979] {pull}15224[15224]
- Make `kibana` module more resilient to Kibana unavailability. {issue}15258[15258] {pull}15270[15270]
- Make `logstash` module more resilient to Logstash unavailability. {issue}15276[15276] {pull}15306[15306]
- Add username/password in Metricbeat autodiscover hints {pull}15349[15349]

*Packetbeat*

Expand Down
4 changes: 4 additions & 0 deletions libbeat/autodiscover/builder/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func TestGenerateHints(t *testing.T) {
"co.elastic.metrics/module": "prometheus",
"co.elastic.metrics/period": "10s",
"co.elastic.metrics/metrics_path": "/metrics/prometheus",
"co.elastic.metrics/username": "user",
"co.elastic.metrics/password": "pass",
"co.elastic.metrics.foobar/period": "15s",
"co.elastic.metrics.foobar1/period": "15s",
"not.to.include": "true",
Expand All @@ -92,6 +94,8 @@ func TestGenerateHints(t *testing.T) {
"module": "prometheus",
"period": "15s",
"metrics_path": "/metrics/prometheus",
"username": "user",
"password": "pass",
},
},
},
Expand Down
18 changes: 18 additions & 0 deletions metricbeat/autodiscover/builder/hints/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
timeout = "timeout"
ssl = "ssl"
metricspath = "metrics_path"
username = "username"
password = "password"

defaultTimeout = "3s"
defaultPeriod = "1m"
Expand Down Expand Up @@ -112,6 +114,8 @@ func (m *metricHints) CreateConfig(event bus.Event) []*common.Config {
sslConf := m.getSSLConfig(hints)
procs := m.getProcessors(hints)
metricspath := m.getMetricPath(hints)
username := m.getUsername(hints)
password := m.getPassword(hints)

moduleConfig := common.MapStr{
"module": mod,
Expand All @@ -130,6 +134,12 @@ func (m *metricHints) CreateConfig(event bus.Event) []*common.Config {
if metricspath != "" {
moduleConfig["metrics_path"] = metricspath
}
if username != "" {
moduleConfig["username"] = username
}
if password != "" {
moduleConfig["password"] = password
}

logp.Debug("hints.builder", "generated config: %v", moduleConfig.String())

Expand Down Expand Up @@ -198,6 +208,14 @@ func (m *metricHints) getMetricPath(hints common.MapStr) string {
return builder.GetHintString(hints, m.Key, metricspath)
}

func (m *metricHints) getUsername(hints common.MapStr) string {
return builder.GetHintString(hints, m.Key, username)
}

func (m *metricHints) getPassword(hints common.MapStr) string {
return builder.GetHintString(hints, m.Key, password)
}

func (m *metricHints) getPeriod(hints common.MapStr) string {
if ival := builder.GetHintString(hints, m.Key, period); ival != "" {
return ival
Expand Down
10 changes: 10 additions & 0 deletions metricbeat/docs/autodiscover-hints.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ The time interval for metrics retrieval, ie: 10s

Metrics retrieval timeout, default: 3s

[float]
===== `co.elastic.metrics/username`

The username to use for authentication

[float]
===== `co.elastic.metrics/password`

The password to use for authentication. It is recommended to retrieve this sensitive information from an ENV variable or a keystore and avoid placing passwords in plain text

[float]
===== `co.elastic.metrics/ssl.*`

Expand Down

0 comments on commit de4ea3f

Please sign in to comment.