feat(inputs.redis_sentinel): Allow username and password (#13864)

This commit is contained in:
Joshua Powers 2023-09-11 02:05:17 -06:00 committed by GitHub
parent d807dd3c05
commit 4a5e3a4d6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 26 deletions

View File

@ -17,10 +17,10 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
# Read metrics from one or many redis servers
[[inputs.redis]]
## specify servers via a url matching:
## [protocol://][:password]@address[:port]
## [protocol://][username:password]@address[:port]
## e.g.
## tcp://localhost:6379
## tcp://:password@192.168.99.100
## tcp://username:password@192.168.99.100
## unix:///var/run/redis.sock
##
## If no servers are specified, then localhost is used as the host.
@ -37,11 +37,11 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
# # Can be "string", "integer", or "float"
# type = "string"
## specify server password
# password = "s#cr@t%"
## specify username for ACL auth (Redis 6.0+)
# username = "default"
## Specify username and password for ACL auth (Redis 6.0+). You can add this
## to the server URI above or specify it here. The values here take
## precidence.
# username = ""
# password = ""
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"

View File

@ -26,16 +26,17 @@ import (
var sampleConfig string
type RedisCommand struct {
Command []interface{}
Field string
Type string
Command []interface{} `toml:"command"`
Field string `toml:"field"`
Type string `toml:"type"`
}
type Redis struct {
Commands []*RedisCommand
Servers []string
Username string
Password string
Commands []*RedisCommand `toml:"commands"`
Servers []string `toml:"servers"`
Username string `toml:"username"`
Password string `toml:"passowrd"`
tls.ClientConfig
Log telegraf.Logger `toml:"-"`

View File

@ -1,10 +1,10 @@
# Read metrics from one or many redis servers
[[inputs.redis]]
## specify servers via a url matching:
## [protocol://][:password]@address[:port]
## [protocol://][username:password]@address[:port]
## e.g.
## tcp://localhost:6379
## tcp://:password@192.168.99.100
## tcp://username:password@192.168.99.100
## unix:///var/run/redis.sock
##
## If no servers are specified, then localhost is used as the host.
@ -21,11 +21,11 @@
# # Can be "string", "integer", or "float"
# type = "string"
## specify server password
# password = "s#cr@t%"
## specify username for ACL auth (Redis 6.0+)
# username = "default"
## Specify username and password for ACL auth (Redis 6.0+). You can add this
## to the server URI above or specify it here. The values here take
## precidence.
# username = ""
# password = ""
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"

View File

@ -18,10 +18,10 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
# Read metrics from one or many redis-sentinel servers
[[inputs.redis_sentinel]]
## specify servers via a url matching:
## [protocol://][:password]@address[:port]
## [protocol://][username:password]@address[:port]
## e.g.
## tcp://localhost:26379
## tcp://:password@192.168.99.100
## tcp://username:password@192.168.99.100
## unix:///var/run/redis-sentinel.sock
##
## If no servers are specified, then localhost is used as the host.

View File

@ -65,9 +65,14 @@ func (r *RedisSentinel) Init() error {
return fmt.Errorf("unable to parse to address %q: %w", serv, err)
}
username := ""
password := ""
if u.User != nil {
password, _ = u.User.Password()
username = u.User.Username()
pw, ok := u.User.Password()
if ok {
password = pw
}
}
var address string
@ -88,6 +93,7 @@ func (r *RedisSentinel) Init() error {
sentinel := redis.NewSentinelClient(
&redis.Options{
Addr: address,
Username: username,
Password: password,
Network: u.Scheme,
PoolSize: 1,

View File

@ -1,10 +1,10 @@
# Read metrics from one or many redis-sentinel servers
[[inputs.redis_sentinel]]
## specify servers via a url matching:
## [protocol://][:password]@address[:port]
## [protocol://][username:password]@address[:port]
## e.g.
## tcp://localhost:26379
## tcp://:password@192.168.99.100
## tcp://username:password@192.168.99.100
## unix:///var/run/redis-sentinel.sock
##
## If no servers are specified, then localhost is used as the host.