diff --git a/plugins/inputs/redis/README.md b/plugins/inputs/redis/README.md index e79f902b4..665b6b1ae 100644 --- a/plugins/inputs/redis/README.md +++ b/plugins/inputs/redis/README.md @@ -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" diff --git a/plugins/inputs/redis/redis.go b/plugins/inputs/redis/redis.go index 7b924358c..002269fb7 100644 --- a/plugins/inputs/redis/redis.go +++ b/plugins/inputs/redis/redis.go @@ -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:"-"` diff --git a/plugins/inputs/redis/sample.conf b/plugins/inputs/redis/sample.conf index 6f1db720d..b8fbe78ac 100644 --- a/plugins/inputs/redis/sample.conf +++ b/plugins/inputs/redis/sample.conf @@ -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" diff --git a/plugins/inputs/redis_sentinel/README.md b/plugins/inputs/redis_sentinel/README.md index 8db34a680..7289e52d7 100644 --- a/plugins/inputs/redis_sentinel/README.md +++ b/plugins/inputs/redis_sentinel/README.md @@ -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. diff --git a/plugins/inputs/redis_sentinel/redis_sentinel.go b/plugins/inputs/redis_sentinel/redis_sentinel.go index f0e065133..e30054a12 100644 --- a/plugins/inputs/redis_sentinel/redis_sentinel.go +++ b/plugins/inputs/redis_sentinel/redis_sentinel.go @@ -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, diff --git a/plugins/inputs/redis_sentinel/sample.conf b/plugins/inputs/redis_sentinel/sample.conf index ae8f89aed..0ffa2346b 100644 --- a/plugins/inputs/redis_sentinel/sample.conf +++ b/plugins/inputs/redis_sentinel/sample.conf @@ -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.