Add support for self-signed certs to InfluxDB input plugin (#2773)

This commit is contained in:
Lukasz Jagiello 2017-05-08 15:20:24 -07:00 committed by Daniel Nelson
parent 1ebd1aaa41
commit 5af985ef5f
3 changed files with 34 additions and 0 deletions

View File

@ -2,6 +2,9 @@
### Release Notes ### Release Notes
### Features ### Features
- [#2773](https://github.com/influxdata/telegraf/pull/2773): Add support for self-signed certs to InfluxDB input plugin
### Bugfixes ### Bugfixes
- [#2749](https://github.com/influxdata/telegraf/pull/2749): Fixed sqlserver input to work with case sensitive server collation. - [#2749](https://github.com/influxdata/telegraf/pull/2749): Fixed sqlserver input to work with case sensitive server collation.

View File

@ -19,6 +19,16 @@ InfluxDB-formatted endpoints. See below for more information.
urls = [ urls = [
"http://localhost:8086/debug/vars" "http://localhost:8086/debug/vars"
] ]
## 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
## http request & header timeout
timeout = "5s"
``` ```
### Measurements & Fields ### Measurements & Fields

View File

@ -15,6 +15,14 @@ import (
type InfluxDB struct { type InfluxDB struct {
URLs []string `toml:"urls"` URLs []string `toml:"urls"`
// 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
Timeout internal.Duration Timeout internal.Duration
@ -37,6 +45,13 @@ func (*InfluxDB) SampleConfig() string {
"http://localhost:8086/debug/vars" "http://localhost:8086/debug/vars"
] ]
## 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
## http request & header timeout ## http request & header timeout
timeout = "5s" timeout = "5s"
` `
@ -48,9 +63,15 @@ func (i *InfluxDB) Gather(acc telegraf.Accumulator) error {
} }
if i.client == nil { if i.client == nil {
tlsCfg, err := internal.GetTLSConfig(
i.SSLCert, i.SSLKey, i.SSLCA, i.InsecureSkipVerify)
if err != nil {
return err
}
i.client = &http.Client{ i.client = &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
ResponseHeaderTimeout: i.Timeout.Duration, ResponseHeaderTimeout: i.Timeout.Duration,
TLSClientConfig: tlsCfg,
}, },
Timeout: i.Timeout.Duration, Timeout: i.Timeout.Duration,
} }