Skip to content

Commit a6d38d0

Browse files
lcharkiewiczotherpirate
authored andcommitted
Add SSL/TLS support to Redis input (influxdata#4236)
1 parent 70edc75 commit a6d38d0

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

Godeps

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ github.com/golang/snappy 7db9049039a047d955fe8c19b83c8ff5abd765c7
2828
github.com/go-ole/go-ole be49f7c07711fcb603cff39e1de7c67926dc0ba7
2929
github.com/google/go-cmp f94e52cad91c65a63acc1e75d4be223ea22e99bc
3030
github.com/gorilla/mux 53c1911da2b537f792e7cafcb446b05ffe33b996
31-
github.com/go-redis/redis 73b70592cdaa9e6abdfcfbf97b4a90d80728c836
31+
github.com/go-redis/redis 83fb42932f6145ce52df09860384a4653d2d332a
3232
github.com/go-sql-driver/mysql 2e00b5cd70399450106cec6431c2e2ce3cae5034
3333
github.com/hailocab/go-hostpool e80d13ce29ede4452c43dea11e79b9bc8a15b478
3434
github.com/hashicorp/consul 5174058f0d2bda63fa5198ab96c33d9a909c58ed

plugins/inputs/redis/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
## If no servers are specified, then localhost is used as the host.
1515
## If no port is specified, 6379 is used
1616
servers = ["tcp://localhost:6379"]
17+
18+
## Optional TLS Config
19+
# tls_ca = "/etc/telegraf/ca.pem"
20+
# tls_cert = "/etc/telegraf/cert.pem"
21+
# tls_key = "/etc/telegraf/key.pem"
22+
## Use TLS but skip chain & host verification
23+
# insecure_skip_verify = true
1724
```
1825

1926
### Measurements & Fields:

plugins/inputs/redis/redis.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import (
1313

1414
"github.com/go-redis/redis"
1515
"github.com/influxdata/telegraf"
16+
"github.com/influxdata/telegraf/internal/tls"
1617
"github.com/influxdata/telegraf/plugins/inputs"
1718
)
1819

1920
type Redis struct {
2021
Servers []string
22+
tls.ClientConfig
2123

2224
clients []Client
2325
initialized bool
@@ -56,6 +58,13 @@ var sampleConfig = `
5658
## If no servers are specified, then localhost is used as the host.
5759
## If no port is specified, 6379 is used
5860
servers = ["tcp://localhost:6379"]
61+
62+
## Optional TLS Config
63+
# tls_ca = "/etc/telegraf/ca.pem"
64+
# tls_cert = "/etc/telegraf/cert.pem"
65+
# tls_key = "/etc/telegraf/key.pem"
66+
## Use TLS but skip chain & host verification
67+
# insecure_skip_verify = true
5968
`
6069

6170
func (r *Redis) SampleConfig() string {
@@ -109,12 +118,18 @@ func (r *Redis) init(acc telegraf.Accumulator) error {
109118
address = u.Host
110119
}
111120

121+
tlsConfig, err := r.ClientConfig.TLSConfig()
122+
if err != nil {
123+
return err
124+
}
125+
112126
client := redis.NewClient(
113127
&redis.Options{
114-
Addr: address,
115-
Password: password,
116-
Network: u.Scheme,
117-
PoolSize: 1,
128+
Addr: address,
129+
Password: password,
130+
Network: u.Scheme,
131+
PoolSize: 1,
132+
TLSConfig: tlsConfig,
118133
},
119134
)
120135

0 commit comments

Comments
 (0)