From 6a601ceb975dead75481324254c5714f1e2ace4a Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Fri, 12 Feb 2016 17:00:11 -0700 Subject: [PATCH] Add support for specifying SSL config for influxdb output closes #191 --- plugins/outputs/influxdb/influxdb.go | 23 +++++++++++++++++++++++ plugins/outputs/mqtt/mqtt.go | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/plugins/outputs/influxdb/influxdb.go b/plugins/outputs/influxdb/influxdb.go index c11484a48..52fd8039b 100644 --- a/plugins/outputs/influxdb/influxdb.go +++ b/plugins/outputs/influxdb/influxdb.go @@ -28,6 +28,15 @@ type InfluxDB struct { Timeout internal.Duration UDPPayload int `toml:"udp_payload"` + // 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"` + // Use SSL but skip chain & host verification + InsecureSkipVerify bool + conns []client.Client } @@ -52,6 +61,13 @@ var sampleConfig = ` # user_agent = "telegraf" ### Set UDP payload size, defaults to InfluxDB UDP Client default (512 bytes) # udp_payload = 512 + + ### 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 + # insecure_skip_verify = false ` func (i *InfluxDB) Connect() error { @@ -66,6 +82,12 @@ func (i *InfluxDB) Connect() error { urls = append(urls, i.URL) } + tlsCfg, err := internal.GetTLSConfig( + i.SSLCert, i.SSLKey, i.SSLCA, i.InsecureSkipVerify) + if err != nil { + return err + } + var conns []client.Client for _, u := range urls { switch { @@ -94,6 +116,7 @@ func (i *InfluxDB) Connect() error { Password: i.Password, UserAgent: i.UserAgent, Timeout: i.Timeout.Duration, + TLSConfig: tlsCfg, }) if err != nil { return err diff --git a/plugins/outputs/mqtt/mqtt.go b/plugins/outputs/mqtt/mqtt.go index efa20944b..d28a04d72 100644 --- a/plugins/outputs/mqtt/mqtt.go +++ b/plugins/outputs/mqtt/mqtt.go @@ -5,11 +5,12 @@ import ( "strings" "sync" - paho "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal" "github.com/influxdata/telegraf/plugins/outputs" "github.com/influxdata/telegraf/plugins/serializers" + + paho "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git" ) var sampleConfig = `