Fix segfault in x509_cert (#4874)
This commit is contained in:
parent
f10de93da4
commit
48745c3171
|
@ -10,7 +10,7 @@ file or network connection.
|
||||||
# Reads metrics from a SSL certificate
|
# Reads metrics from a SSL certificate
|
||||||
[[inputs.x509_cert]]
|
[[inputs.x509_cert]]
|
||||||
## List certificate sources
|
## List certificate sources
|
||||||
sources = ["/etc/ssl/certs/ssl-cert-snakeoil.pem", "https://example.org"]
|
sources = ["/etc/ssl/certs/ssl-cert-snakeoil.pem", "https://example.org:443"]
|
||||||
|
|
||||||
## Timeout for SSL connection
|
## Timeout for SSL connection
|
||||||
# timeout = "5s"
|
# timeout = "5s"
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
[[inputs.x509_cert]]
|
||||||
|
sources = ["https://www.influxdata.com:443"]
|
||||||
|
|
||||||
|
[[outputs.file]]
|
||||||
|
files = ["stdout"]
|
|
@ -80,7 +80,10 @@ func (c *X509Cert) getCert(location string, timeout time.Duration) ([]*x509.Cert
|
||||||
}
|
}
|
||||||
defer ipConn.Close()
|
defer ipConn.Close()
|
||||||
|
|
||||||
tlsCfg.ServerName = u.Host
|
if tlsCfg == nil {
|
||||||
|
tlsCfg = &tls.Config{}
|
||||||
|
}
|
||||||
|
tlsCfg.ServerName = u.Hostname()
|
||||||
conn := tls.Client(ipConn, tlsCfg)
|
conn := tls.Client(ipConn, tlsCfg)
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -203,3 +205,19 @@ func TestStrings(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGatherCert(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("Skipping integration test in short mode")
|
||||||
|
}
|
||||||
|
|
||||||
|
m := &X509Cert{
|
||||||
|
Sources: []string{"https://www.influxdata.com:443"},
|
||||||
|
}
|
||||||
|
|
||||||
|
var acc testutil.Accumulator
|
||||||
|
err := m.Gather(&acc)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.True(t, acc.HasMeasurement("x509_cert"))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue