Continue checking cert from other sources if error occurs (#5381)

This commit is contained in:
Greg 2019-02-05 18:38:04 -07:00 committed by Daniel Nelson
parent 1a81e49d05
commit 1137fa50ad
2 changed files with 6 additions and 5 deletions

View File

@ -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 {

View File

@ -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
}