From 2e6f7055cb2c10c11e49d6c357a223f5e080a066 Mon Sep 17 00:00:00 2001 From: Bob Shannon Date: Mon, 26 Jun 2017 18:23:53 -0400 Subject: [PATCH] Fix panic in elasticsearch input if cannot determine master (#2954) (cherry picked from commit a7595c918a0ef6022355672dfca1fba979580375) --- plugins/inputs/elasticsearch/elasticsearch.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/elasticsearch/elasticsearch.go b/plugins/inputs/elasticsearch/elasticsearch.go index c11bfdd2f..5bf3d1c63 100644 --- a/plugins/inputs/elasticsearch/elasticsearch.go +++ b/plugins/inputs/elasticsearch/elasticsearch.go @@ -169,7 +169,10 @@ func (e *Elasticsearch) Gather(acc telegraf.Accumulator) error { if e.ClusterStats { // get cat/master information here so NodeStats can determine // whether this node is the Master - e.setCatMaster(s + "/_cat/master") + if err := e.setCatMaster(s + "/_cat/master"); err != nil { + acc.AddError(fmt.Errorf(mask.ReplaceAllString(err.Error(), "http(s)://XXX:XXX@"))) + return + } } // Always gather node states @@ -353,7 +356,7 @@ func (e *Elasticsearch) setCatMaster(url string) error { // NOTE: we are not going to read/discard r.Body under the assumption we'd prefer // to let the underlying transport close the connection and re-establish a new one for // future calls. - return fmt.Errorf("status-code %d, expected %d", r.StatusCode, http.StatusOK) + return fmt.Errorf("elasticsearch: Unable to retrieve master node information. API responded with status-code %d, expected %d", r.StatusCode, http.StatusOK) } response, err := ioutil.ReadAll(r.Body)