Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add username/password in Metricbeat autodiscover hints #15349

Merged
merged 6 commits into from
Jan 9, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick only: isn't it correct in English to use a single word "username" instead two ones "user Name"?

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