From 17a4513c016c08dbb81efdcd41a6b414a331017c Mon Sep 17 00:00:00 2001 From: ehlxr Date: Thu, 28 Nov 2019 17:01:42 +0800 Subject: [PATCH] search key support multiple value --- main.go | 15 +++++++++------ pkg/parser.go | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 78af73e..c91be8e 100644 --- a/main.go +++ b/main.go @@ -72,12 +72,15 @@ func tailFile() { text = strings.ToLower(text) } - if ok, _ := regexp.Match(pkg.Opts.KeyWord, []byte(text)); ok { - if limiter.IsAvailable() { - sendMsg(line.Text) - } else { - log.Error("dingTalk 1 m allow send 20 msg. msg %v discarded.", - line.Text) + keys := strings.Split(pkg.Opts.KeyWord, ",") + for _, key := range keys { + if ok, _ := regexp.Match(strings.TrimSpace(key), []byte(text)); ok { + if limiter.IsAvailable() { + sendMsg(line.Text) + } else { + log.Error("dingTalk 1 m allow send 20 msg. msg %v discarded.", + line.Text) + } } } } diff --git a/pkg/parser.go b/pkg/parser.go index 4ea046b..271797a 100644 --- a/pkg/parser.go +++ b/pkg/parser.go @@ -10,7 +10,7 @@ var ( Opts struct { AppName string `short:"n" long:"monitor-app-name" env:"MONITOR_APP_NAME" description:"The name of the application being monitored, which will be added to the content before"` File string `short:"f" long:"monitor-file" env:"MONITOR_FILE" description:"The file to be monitored" required:"true"` - KeyWord string `short:"k" long:"search-keyword" env:"SEARCH_KEYWORD" description:"Keyword to be search for" default:"ERRO"` + KeyWord string `short:"k" long:"search-keyword" env:"SEARCH_KEYWORD" description:"Keyword to be search for, Multiple values separated by ','" default:"ERRO"` KeyWordIgnoreCase bool `short:"c" long:"keyword-case-sensitive" env:"KEYWORD_IGNORE_CASE" description:"Whether Keyword ignore case"` Version bool `short:"v" long:"version" description:"Show version info"` Robot Robot `group:"DingTalk Robot Options" namespace:"robot" env-namespace:"ROBOT" `