update at 2019-11-21 16:52:42 by ehlxr
This commit is contained in:
parent
1aa3e391b0
commit
7dda8a09c3
14
main.go
14
main.go
@ -33,6 +33,7 @@ GoVersion: %s
|
||||
opts struct {
|
||||
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"`
|
||||
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" `
|
||||
}
|
||||
@ -61,13 +62,22 @@ func main() {
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
if opts.KeyWordIgnoreCase {
|
||||
opts.KeyWord = strings.ToLower(opts.KeyWord)
|
||||
}
|
||||
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 {
|
||||
err = dingTalk.SendTextMessage(line.Text, opts.Robot.AtMobiles, opts.Robot.IsAtAll)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user