Simplify testing with TLS (#4095)
This commit is contained in:
@@ -20,42 +20,10 @@ via raw TCP.
|
||||
## timeout in seconds for the write connection to graphite
|
||||
timeout = 2
|
||||
|
||||
## Optional SSL Config
|
||||
# ssl_ca = "/etc/telegraf/ca.pem"
|
||||
# ssl_cert = "/etc/telegraf/cert.pem"
|
||||
# ssl_key = "/etc/telegraf/key.pem"
|
||||
## Use SSL but skip chain & host verification
|
||||
## Optional TLS Config
|
||||
# tls_ca = "/etc/telegraf/ca.pem"
|
||||
# tls_cert = "/etc/telegraf/cert.pem"
|
||||
# tls_key = "/etc/telegraf/key.pem"
|
||||
## Use TLS but skip chain & host verification
|
||||
# insecure_skip_verify = false
|
||||
```
|
||||
|
||||
Parameters:
|
||||
|
||||
Servers []string
|
||||
Prefix string
|
||||
Timeout int
|
||||
Template string
|
||||
|
||||
// Path to CA file
|
||||
SSLCA string
|
||||
// Path to host cert file
|
||||
SSLCert string
|
||||
// Path to cert key file
|
||||
SSLKey string
|
||||
// Skip SSL verification
|
||||
InsecureSkipVerify bool
|
||||
|
||||
### Required parameters:
|
||||
|
||||
* `servers`: List of strings, ["mygraphiteserver:2003"].
|
||||
* `prefix`: String use to prefix all sent metrics.
|
||||
* `timeout`: Connection timeout in seconds.
|
||||
* `template`: Template for graphite output format, see
|
||||
https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
|
||||
for more details.
|
||||
|
||||
### Optional parameters:
|
||||
|
||||
* `ssl_ca`: SSL CA
|
||||
* `ssl_cert`: SSL CERT
|
||||
* `ssl_key`: SSL key
|
||||
* `insecure_skip_verify`: Use SSL but skip chain & host verification (default: false)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
tlsint "github.com/influxdata/telegraf/internal/tls"
|
||||
"github.com/influxdata/telegraf/plugins/outputs"
|
||||
"github.com/influxdata/telegraf/plugins/serializers"
|
||||
)
|
||||
@@ -22,18 +22,7 @@ type Graphite struct {
|
||||
Template string
|
||||
Timeout int
|
||||
conns []net.Conn
|
||||
|
||||
// Path to CA file
|
||||
SSLCA string `toml:"ssl_ca"`
|
||||
// Path to host cert file
|
||||
SSLCert string `toml:"ssl_cert"`
|
||||
// Path to cert key file
|
||||
SSLKey string `toml:"ssl_key"`
|
||||
// Skip SSL verification
|
||||
InsecureSkipVerify bool
|
||||
|
||||
// tls config
|
||||
tlsConfig *tls.Config
|
||||
tlsint.ClientConfig
|
||||
}
|
||||
|
||||
var sampleConfig = `
|
||||
@@ -49,11 +38,11 @@ var sampleConfig = `
|
||||
## timeout in seconds for the write connection to graphite
|
||||
timeout = 2
|
||||
|
||||
## Optional SSL Config
|
||||
# ssl_ca = "/etc/telegraf/ca.pem"
|
||||
# ssl_cert = "/etc/telegraf/cert.pem"
|
||||
# ssl_key = "/etc/telegraf/key.pem"
|
||||
## Use SSL but skip chain & host verification
|
||||
## Optional TLS Config
|
||||
# tls_ca = "/etc/telegraf/ca.pem"
|
||||
# tls_cert = "/etc/telegraf/cert.pem"
|
||||
# tls_key = "/etc/telegraf/key.pem"
|
||||
## Use TLS but skip chain & host verification
|
||||
# insecure_skip_verify = false
|
||||
`
|
||||
|
||||
@@ -67,9 +56,7 @@ func (g *Graphite) Connect() error {
|
||||
}
|
||||
|
||||
// Set tls config
|
||||
var err error
|
||||
g.tlsConfig, err = internal.GetTLSConfig(
|
||||
g.SSLCert, g.SSLKey, g.SSLCA, g.InsecureSkipVerify)
|
||||
tlsConfig, err := g.ClientConfig.TLSConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -82,8 +69,8 @@ func (g *Graphite) Connect() error {
|
||||
|
||||
// Get secure connection if tls config is set
|
||||
var conn net.Conn
|
||||
if g.tlsConfig != nil {
|
||||
conn, err = tls.DialWithDialer(&d, "tcp", server, g.tlsConfig)
|
||||
if tlsConfig != nil {
|
||||
conn, err = tls.DialWithDialer(&d, "tcp", server, tlsConfig)
|
||||
} else {
|
||||
conn, err = d.Dial("tcp", server)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user