钉钉告警可以at特定指定人员 (#475)
* - add dingtalk robot @ special person should config phone number in user IM field * send msg by each robot when there are more than one robot in stra
This commit is contained in:
parent
4b22390faf
commit
9dd1f1f90b
|
@ -2,6 +2,7 @@ package cron
|
|||
|
||||
import (
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -163,12 +164,22 @@ func sendImByDingTalkRobot(message *dataobj.Message) {
|
|||
}
|
||||
}
|
||||
|
||||
for tokenUser := range set {
|
||||
err := dingtalk.RobotSend(tokenUser, message.Content)
|
||||
if err != nil {
|
||||
logger.Warningf("im dingtalk_robot send to %s fail: %v", tokenUser, err)
|
||||
req := regexp.MustCompile("^1[0-9]{10}$")
|
||||
var atUser []string
|
||||
var tokenUser []string
|
||||
for user := range set {
|
||||
if req.MatchString(user){
|
||||
atUser = append(atUser, user)
|
||||
} else {
|
||||
logger.Infof("im dingtalk_robot send to %s succ", tokenUser)
|
||||
tokenUser = append(tokenUser, user)
|
||||
}
|
||||
}
|
||||
for _, u := range tokenUser {
|
||||
err := dingtalk.RobotSend(u, message.Content, atUser)
|
||||
if err != nil {
|
||||
logger.Warningf("im dingtalk_robot send to %s fail: %v", u, err)
|
||||
} else {
|
||||
logger.Infof("im dingtalk_robot send to %s succ", u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,14 +16,20 @@ type Result struct {
|
|||
type dingReqData struct {
|
||||
Msgtype string `json:"msgtype"`
|
||||
Text *textContent `json:"text"`
|
||||
At *atContent `json:"at"`
|
||||
}
|
||||
|
||||
type textContent struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type atContent struct {
|
||||
AtMobiles []string `json:"atMobiles"`
|
||||
IsAtAll bool `json:"isAtAll"`
|
||||
}
|
||||
|
||||
// RobotSend robot发送信息
|
||||
func RobotSend(tokenUser, sendContent string) error {
|
||||
func RobotSend(tokenUser, sendContent string, atUser []string) error {
|
||||
url := "https://oapi.dingtalk.com/robot/send?access_token=" + tokenUser
|
||||
|
||||
dingReqData := new(dingReqData)
|
||||
|
@ -31,6 +37,10 @@ func RobotSend(tokenUser, sendContent string) error {
|
|||
reqContent := new(textContent)
|
||||
reqContent.Content = sendContent
|
||||
dingReqData.Text = reqContent
|
||||
reqAtContent := new(atContent)
|
||||
reqAtContent.IsAtAll = false
|
||||
reqAtContent.AtMobiles = atUser
|
||||
dingReqData.At = reqAtContent
|
||||
|
||||
content, err := json.Marshal(dingReqData)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue