From 1137fa50ad1f038a87b137e02ff878db62d15b3a Mon Sep 17 00:00:00 2001 From: Greg <2653109+glinton@users.noreply.github.com> Date: Tue, 5 Feb 2019 18:38:04 -0700 Subject: [PATCH] Continue checking cert from other sources if error occurs (#5381) --- plugins/inputs/x509_cert/x509_cert.go | 2 +- plugins/inputs/x509_cert/x509_cert_test.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/x509_cert/x509_cert.go b/plugins/inputs/x509_cert/x509_cert.go index ba4708ea2..81bcb0d2c 100644 --- a/plugins/inputs/x509_cert/x509_cert.go +++ b/plugins/inputs/x509_cert/x509_cert.go @@ -166,7 +166,7 @@ func (c *X509Cert) Gather(acc telegraf.Accumulator) error { for _, location := range c.Sources { certs, err := c.getCert(location, c.Timeout.Duration*time.Second) if err != nil { - return fmt.Errorf("cannot get SSL cert '%s': %s", location, err.Error()) + acc.AddError(fmt.Errorf("cannot get SSL cert '%s': %s", location, err.Error())) } for _, cert := range certs { diff --git a/plugins/inputs/x509_cert/x509_cert_test.go b/plugins/inputs/x509_cert/x509_cert_test.go index a9bd80568..933676417 100644 --- a/plugins/inputs/x509_cert/x509_cert_test.go +++ b/plugins/inputs/x509_cert/x509_cert_test.go @@ -4,13 +4,14 @@ import ( "crypto/tls" "encoding/base64" "fmt" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "io/ioutil" "os" "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal" "github.com/influxdata/telegraf/testutil" @@ -115,7 +116,7 @@ func TestGatherRemote(t *testing.T) { acc := testutil.Accumulator{} err = sc.Gather(&acc) - if err != nil { + if len(acc.Errors) > 0 { testErr = true } @@ -173,7 +174,7 @@ func TestGatherLocal(t *testing.T) { acc := testutil.Accumulator{} err = sc.Gather(&acc) - if err != nil { + if len(acc.Errors) > 0 { error = true }