From 1fceecbd841b0714949dae88ec0170404c2d7125 Mon Sep 17 00:00:00 2001 From: positivelong Date: Thu, 18 May 2023 10:50:12 +0800 Subject: [PATCH 1/2] feature: Redis supports password retrieval from files --- filebeat/input/redis/config.go | 2 ++ filebeat/input/redis/input.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/filebeat/input/redis/config.go b/filebeat/input/redis/config.go index b5829b6defc4..58c9b14c8e12 100644 --- a/filebeat/input/redis/config.go +++ b/filebeat/input/redis/config.go @@ -30,6 +30,7 @@ var defaultConfig = config{ Network: "tcp", MaxConn: 10, Password: "", + PasswordFile: "", } type config struct { @@ -39,4 +40,5 @@ type config struct { Network string `config:"network"` MaxConn int `config:"maxconn" validate:"min=1"` Password string `config:"password"` + PasswordFile string `config:"password_file"` } diff --git a/filebeat/input/redis/input.go b/filebeat/input/redis/input.go index 4466ca2c0173..5ddcf432659f 100644 --- a/filebeat/input/redis/input.go +++ b/filebeat/input/redis/input.go @@ -18,6 +18,7 @@ package redis import ( + "os" "time" rd "github.com/garyburd/redigo/redis" @@ -58,6 +59,22 @@ func NewInput(cfg *common.Config, outletFactory channel.Connector, context input return nil, err } + // 读取文件内容 + var content = "" + if config.PasswordFile != "" { + info, err := os.ReadFile(config.PasswordFile) + if err != nil { + logp.Err("Read Password File Error") + } else { + content = string(info) + } + } + + // 将文件内容赋值给 config.Password + if content != "" { + config.Password = content + } + outlet, err := outletFactory(cfg, context.DynamicFields) if err != nil { return nil, err From 6e82b6c91f8d253964b1c84495ebff5078a4aa6b Mon Sep 17 00:00:00 2001 From: positivelong Date: Wed, 17 May 2023 19:27:40 +0800 Subject: [PATCH 2/2] feature: add error log print --- filebeat/input/redis/input.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filebeat/input/redis/input.go b/filebeat/input/redis/input.go index 5ddcf432659f..5b49fa9b7069 100644 --- a/filebeat/input/redis/input.go +++ b/filebeat/input/redis/input.go @@ -64,7 +64,7 @@ func NewInput(cfg *common.Config, outletFactory channel.Connector, context input if config.PasswordFile != "" { info, err := os.ReadFile(config.PasswordFile) if err != nil { - logp.Err("Read Password File Error") + logp.Err("Read Password File Error: %s", err) } else { content = string(info) }