钉钉告警可以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 (
|
import (
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -163,12 +164,22 @@ func sendImByDingTalkRobot(message *dataobj.Message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for tokenUser := range set {
|
req := regexp.MustCompile("^1[0-9]{10}$")
|
||||||
err := dingtalk.RobotSend(tokenUser, message.Content)
|
var atUser []string
|
||||||
if err != nil {
|
var tokenUser []string
|
||||||
logger.Warningf("im dingtalk_robot send to %s fail: %v", tokenUser, err)
|
for user := range set {
|
||||||
|
if req.MatchString(user){
|
||||||
|
atUser = append(atUser, user)
|
||||||
} else {
|
} 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 {
|
type dingReqData struct {
|
||||||
Msgtype string `json:"msgtype"`
|
Msgtype string `json:"msgtype"`
|
||||||
Text *textContent `json:"text"`
|
Text *textContent `json:"text"`
|
||||||
|
At *atContent `json:"at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type textContent struct {
|
type textContent struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type atContent struct {
|
||||||
|
AtMobiles []string `json:"atMobiles"`
|
||||||
|
IsAtAll bool `json:"isAtAll"`
|
||||||
|
}
|
||||||
|
|
||||||
// RobotSend robot发送信息
|
// 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
|
url := "https://oapi.dingtalk.com/robot/send?access_token=" + tokenUser
|
||||||
|
|
||||||
dingReqData := new(dingReqData)
|
dingReqData := new(dingReqData)
|
||||||
|
@ -31,6 +37,10 @@ func RobotSend(tokenUser, sendContent string) error {
|
||||||
reqContent := new(textContent)
|
reqContent := new(textContent)
|
||||||
reqContent.Content = sendContent
|
reqContent.Content = sendContent
|
||||||
dingReqData.Text = reqContent
|
dingReqData.Text = reqContent
|
||||||
|
reqAtContent := new(atContent)
|
||||||
|
reqAtContent.IsAtAll = false
|
||||||
|
reqAtContent.AtMobiles = atUser
|
||||||
|
dingReqData.At = reqAtContent
|
||||||
|
|
||||||
content, err := json.Marshal(dingReqData)
|
content, err := json.Marshal(dingReqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue