Commit 3fdf537d authored by 李世星's avatar 李世星

fix(202301301616): 1

parent e285a6fa
......@@ -3,6 +3,7 @@ package ding
import (
"bytes"
"fmt"
"log"
"time"
"github.com/y7ut/logtransfer/entity"
......@@ -73,6 +74,7 @@ func CreateDingMessage(messageType string, msg interface{}, mobiles []string) DD
func pluginNotice(msg interface{}) string {
mateData := msg.(*entity.Matedata)
log.Panicln(mateData)
templateBuff := bytes.NewBuffer([]byte{})
templateBuff.WriteString(fmt.Sprintf("# 服务通知 \r\n > [节点]:%s", mateData.SourceAgent))
for key, value := range mateData.Data {
......
......@@ -15,6 +15,7 @@ type Ding Plugin
func (d *Ding) HandleFunc(m *entity.Matedata) error {
log.Println("DINGDING:")
var dingMobileData = []string{}
var send bool
searchKey := (*d.params)["searchKey"].(string)
searchValue := (*d.params)["searchValue"].(string)
dingWebHook := (*d.params)["dingWebHook"].(string)
......@@ -22,16 +23,20 @@ func (d *Ding) HandleFunc(m *entity.Matedata) error {
if dingMobiles != "" {
dingMobileData = strings.Split(dingMobiles, ",")
}
for k, v := range (*m).Data {
if dingWebHook != "" && k == searchKey && (searchValue == "" || searchValue == v) {
send = true
break
}
}
if send {
err := ding.DingDingNotice(dingWebHook, context.Background(), ding.CreateDingMessage(ding.MESSAGE_TYPE_PLUGIN_NOTICE, m, dingMobileData))
if err != nil {
log.Println(err)
}
break
}
}
return nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment