search key support multiple value

master
ehlxr 2019-11-28 17:01:42 +08:00
parent e6869549e5
commit 17a4513c01
2 changed files with 10 additions and 7 deletions

15
main.go
View File

@ -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)
}
}
}
}

View File

@ -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" `