Skip to content

Commit

Permalink
Mask username/password from error messages
Browse files Browse the repository at this point in the history
closes #1980
  • Loading branch information
sparrc committed Dec 20, 2016
1 parent 7fc5781 commit 7ea9e47
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions plugins/inputs/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"regexp"
"sync"
"time"

Expand All @@ -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"
Expand Down Expand Up @@ -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))

Expand All @@ -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)
}
Expand Down

0 comments on commit 7ea9e47

Please sign in to comment.