Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation regarding collecting invalid certs #6139

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/inputs/x509_cert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This plugin provides information about X509 certificate accessible via local
file or network connection.

In order to always fetch cert information, it is suggested that you use `insecure_skip_verify = true` as telegraf fails to collect information on invalid certs without it.


### Configuration

Expand Down
32 changes: 32 additions & 0 deletions plugins/inputs/x509_cert/x509_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
_tls "github.com/influxdata/telegraf/internal/tls"
"github.com/influxdata/telegraf/testutil"
)

Expand Down Expand Up @@ -52,6 +53,7 @@ func TestGatherRemote(t *testing.T) {
{name: "successful https", server: "https://example.org:443", timeout: 5},
{name: "successful file", server: "file://" + tmpfile.Name(), timeout: 5},
{name: "unsupported scheme", server: "foo://", timeout: 5, error: true},
{name: "expired certificate", server: "https://expired.badssl.com:443", timeout: 5},
{name: "no certificate", timeout: 5, unset: true, error: true},
{name: "closed connection", close: true, error: true},
{name: "no handshake", timeout: 5, noshake: true, error: true},
Expand Down Expand Up @@ -272,3 +274,33 @@ func TestGatherCert(t *testing.T) {

assert.True(t, acc.HasMeasurement("x509_cert"))
}

func TestGatherExpiredCert(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}

m := &X509Cert{
Sources: []string{"https://expired.badssl.com:443"},
}

var acc testutil.Accumulator
err := m.Gather(&acc)
require.NoError(t, err)

assert.False(t, acc.HasMeasurement("x509_cert"))

m = &X509Cert{
Sources: []string{"https://expired.badssl.com:443"},
ClientConfig: _tls.ClientConfig{
InsecureSkipVerify: true,
},
}

acc = testutil.Accumulator{}
err = m.Gather(&acc)
require.NoError(t, err)

assert.True(t, acc.HasMeasurement("x509_cert"))

}