From a9f03a72f5aadf198f8c4ef8a99513b0801c4050 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Tue, 20 Dec 2016 19:32:04 +0000 Subject: [PATCH] Mask username/password from error messages closes #1980 --- CHANGELOG.md | 1 + plugins/inputs/elasticsearch/elasticsearch.go | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07e589ce3..7ad357f66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ plugins, not just statsd. - [#1898](https://github.com/influxdata/telegraf/issues/1898): Support negative statsd counters. - [#1921](https://github.com/influxdata/telegraf/issues/1921): Elasticsearch cluster stats support. - [#1942](https://github.com/influxdata/telegraf/pull/1942): Change Amazon Kinesis output plugin to use the built-in serializer plugins. +- [#1980](https://github.com/influxdata/telegraf/issues/1980): Hide username/password from elasticsearch error log messages. ### Bugfixes diff --git a/plugins/inputs/elasticsearch/elasticsearch.go b/plugins/inputs/elasticsearch/elasticsearch.go index 5d5d64909..370e3fbdd 100644 --- a/plugins/inputs/elasticsearch/elasticsearch.go +++ b/plugins/inputs/elasticsearch/elasticsearch.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "regexp" "sync" "time" @@ -16,6 +17,9 @@ import ( "strings" ) +// mask for masking username/password from error messages +var mask = regexp.MustCompile(`https?:\/\/\S+:\S+@`) + // Nodestats are always generated, so simply define a constant for these endpoints const statsPath = "/_nodes/stats" const statsPathLocal = "/_nodes/_local/stats" @@ -149,7 +153,7 @@ func (e *Elasticsearch) Gather(acc telegraf.Accumulator) error { e.client = client } - errChan := errchan.New(len(e.Servers)) + errChan := errchan.New(len(e.Servers) * 3) var wg sync.WaitGroup wg.Add(len(e.Servers)) @@ -172,17 +176,26 @@ func (e *Elasticsearch) Gather(acc telegraf.Accumulator) error { // Always gather node states if err := e.gatherNodeStats(url, acc); err != nil { + err = fmt.Errorf(mask.ReplaceAllString(err.Error(), "http(s)://XXX:XXX@")) errChan.C <- err return } if e.ClusterHealth { url = s + "/_cluster/health?level=indices" - e.gatherClusterHealth(url, acc) + if err := e.gatherClusterHealth(url, acc); err != nil { + err = fmt.Errorf(mask.ReplaceAllString(err.Error(), "http(s)://XXX:XXX@")) + errChan.C <- err + return + } } if e.ClusterStats && e.isMaster { - e.gatherClusterStats(s+"/_cluster/stats", acc) + if err := e.gatherClusterStats(s+"/_cluster/stats", acc); err != nil { + err = fmt.Errorf(mask.ReplaceAllString(err.Error(), "http(s)://XXX:XXX@")) + errChan.C <- err + return + } } }(serv, acc) }