update at 2019-11-21 16:52:42 by ehlxr

This commit is contained in:
ehlxr 2019-11-21 16:52:42 +08:00
parent 1aa3e391b0
commit 7dda8a09c3
2 changed files with 18 additions and 8 deletions

16
main.go
View File

@ -32,7 +32,8 @@ GoVersion: %s
opts struct { opts struct {
File string `short:"f" long:"monitor-file" env:"MONITOR_FILE" description:"The file to be monitored" required:"true"` 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:"Key word to be search for" default:"ERRO"` KeyWord string `short:"k" long:"search-keyword" env:"SEARCH_KEYWORD" description:"Keyword to be search for" 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"` Version bool `short:"v" long:"version" description:"Show version info"`
Robot robot `group:"DingTalk Robot Options" namespace:"robot" env-namespace:"ROBOT" ` Robot robot `group:"DingTalk Robot Options" namespace:"robot" env-namespace:"ROBOT" `
} }
@ -61,13 +62,22 @@ func main() {
if err != nil { if err != nil {
log.Fatal("Tail file %+v", err) log.Fatal("Tail file %+v", err)
} }
log.Info("monitor file %s...", opts.File) log.Info("monitor file <%s>, filter by <%s>, ignore case <%v>...",
opts.File,
opts.KeyWord,
opts.KeyWordIgnoreCase)
dingTalk := dt.NewRobot(opts.Robot.Token, opts.Robot.Secret) dingTalk := dt.NewRobot(opts.Robot.Token, opts.Robot.Secret)
if opts.KeyWordIgnoreCase {
opts.KeyWord = strings.ToLower(opts.KeyWord) opts.KeyWord = strings.ToLower(opts.KeyWord)
}
for line := range tf.Lines { for line := range tf.Lines {
text := strings.ToLower(line.Text) text := line.Text
if opts.KeyWordIgnoreCase {
text = strings.ToLower(text)
}
if ok, _ := regexp.Match(opts.KeyWord, []byte(text)); ok { if ok, _ := regexp.Match(opts.KeyWord, []byte(text)); ok {
err = dingTalk.SendTextMessage(line.Text, opts.Robot.AtMobiles, opts.Robot.IsAtAll) err = dingTalk.SendTextMessage(line.Text, opts.Robot.AtMobiles, opts.Robot.IsAtAll)
if err != nil { if err != nil {

View File

@ -1 +1 @@
v0.0.2 v0.0.3