Mask username/password from error messages

closes #1980
This commit is contained in:
Cameron Sparr 2016-12-20 19:32:04 +00:00
parent 84fc621a1a
commit 8311ff9156
2 changed files with 17 additions and 3 deletions

View File

@ -42,6 +42,7 @@ plugins, not just statsd.
- [#1898](https://github.com/influxdata/telegraf/issues/1898): Support negative statsd counters. - [#1898](https://github.com/influxdata/telegraf/issues/1898): Support negative statsd counters.
- [#1921](https://github.com/influxdata/telegraf/issues/1921): Elasticsearch cluster stats support. - [#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. - [#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 ### Bugfixes

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"regexp"
"sync" "sync"
"time" "time"
@ -16,6 +17,9 @@ import (
"strings" "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 // Nodestats are always generated, so simply define a constant for these endpoints
const statsPath = "/_nodes/stats" const statsPath = "/_nodes/stats"
const statsPathLocal = "/_nodes/_local/stats" const statsPathLocal = "/_nodes/_local/stats"
@ -149,7 +153,7 @@ func (e *Elasticsearch) Gather(acc telegraf.Accumulator) error {
e.client = client e.client = client
} }
errChan := errchan.New(len(e.Servers)) errChan := errchan.New(len(e.Servers) * 3)
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(len(e.Servers)) wg.Add(len(e.Servers))
@ -172,17 +176,26 @@ func (e *Elasticsearch) Gather(acc telegraf.Accumulator) error {
// Always gather node states // Always gather node states
if err := e.gatherNodeStats(url, acc); err != nil { if err := e.gatherNodeStats(url, acc); err != nil {
err = fmt.Errorf(mask.ReplaceAllString(err.Error(), "http(s)://XXX:XXX@"))
errChan.C <- err errChan.C <- err
return return
} }
if e.ClusterHealth { if e.ClusterHealth {
url = s + "/_cluster/health?level=indices" 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 { 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) }(serv, acc)
} }