diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index ff4f9cf73002..c311722ee30e 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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* diff --git a/libbeat/autodiscover/builder/helper_test.go b/libbeat/autodiscover/builder/helper_test.go index 31b138ebd0bd..e64fe5484156 100644 --- a/libbeat/autodiscover/builder/helper_test.go +++ b/libbeat/autodiscover/builder/helper_test.go @@ -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", @@ -92,6 +94,8 @@ func TestGenerateHints(t *testing.T) { "module": "prometheus", "period": "15s", "metrics_path": "/metrics/prometheus", + "username": "user", + "password": "pass", }, }, }, diff --git a/metricbeat/autodiscover/builder/hints/metrics.go b/metricbeat/autodiscover/builder/hints/metrics.go index f46161c4b960..c10b39967c4a 100644 --- a/metricbeat/autodiscover/builder/hints/metrics.go +++ b/metricbeat/autodiscover/builder/hints/metrics.go @@ -44,6 +44,8 @@ const ( timeout = "timeout" ssl = "ssl" metricspath = "metrics_path" + username = "username" + password = "password" defaultTimeout = "3s" defaultPeriod = "1m" @@ -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, @@ -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()) @@ -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 diff --git a/metricbeat/docs/autodiscover-hints.asciidoc b/metricbeat/docs/autodiscover-hints.asciidoc index 08d2cd0570a3..e12754d3313b 100644 --- a/metricbeat/docs/autodiscover-hints.asciidoc +++ b/metricbeat/docs/autodiscover-hints.asciidoc @@ -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.*`