Commit e3fe574e authored by 李世星's avatar 李世星

fix(修改模板文件): 202301291102

parent a82297ee
......@@ -11,9 +11,9 @@ import (
const (
MARKTYPE = "markdown"
TEXTTYPE = "text"
OPEN_TEMPLE = "# 服务通知 已开启 \r\n> 运行环境:%s \r\n ###### %s"
CLOSE_TEMPLE = "# 服务通知 已关闭 \r\n> 运行环境:%s \r\n ###### %s"
STATUS_TEMPLE = "# 服务通知 \r\n> 环境:%s \r\n ###### %s"
OPEN_TEMPLE = "# 服务通知 已开启 \r\n> 运行环境: \r\n ###### %s"
CLOSE_TEMPLE = "# 服务通知 已关闭 \r\n> 运行环境: \r\n ###### %s"
STATUS_TEMPLE = "# 服务通知 \r\n> 环境: \r\n ###### %s"
MESSAGE_TYPE_OPEN = "open"
MESSAGE_TYPE_CLOSE = "close"
MESSAGE_TYPE_PLUGIN_NOTICE = "plugin"
......@@ -45,19 +45,19 @@ type DDMessage struct {
*
* @return string
*/
func CreateDingMessage(dev string, messageType string, msg interface{}, mobiles []string) DDMessage {
func CreateDingMessage(messageType string, msg interface{}, mobiles []string) DDMessage {
var message DDMessage
message.MsgType = MARKTYPE
message.Markdown.Title = "服务通知"
switch messageType {
case MESSAGE_TYPE_OPEN:
message.Markdown.Text = fmt.Sprintf(OPEN_TEMPLE, dev, time.Now().Format("2006/01/02 15:04:05"))
message.Markdown.Text = fmt.Sprintf(OPEN_TEMPLE, time.Now().Format("2006/01/02 15:04:05"))
case MESSAGE_TYPE_CLOSE:
message.Markdown.Text = fmt.Sprintf(CLOSE_TEMPLE, dev, time.Now().Format("2006/01/02 15:04:05"))
message.Markdown.Text = fmt.Sprintf(CLOSE_TEMPLE, time.Now().Format("2006/01/02 15:04:05"))
case MESSAGE_TYPE_PLUGIN_NOTICE:
message.Markdown.Text = pluginNotice(dev, msg)
message.Markdown.Text = pluginNotice(msg)
default:
message.Markdown.Text = fmt.Sprintf(STATUS_TEMPLE, dev, time.Now().Format("2006/01/02 15:04:05"))
message.Markdown.Text = fmt.Sprintf(STATUS_TEMPLE, time.Now().Format("2006/01/02 15:04:05"))
}
if len(mobiles) > 0 {
......@@ -71,11 +71,10 @@ func CreateDingMessage(dev string, messageType string, msg interface{}, mobiles
return message
}
func pluginNotice(dev string, msg interface{}) string {
func pluginNotice(msg interface{}) string {
mateData := msg.(*entity.Matedata)
templateBuff := bytes.NewBuffer([]byte{})
templateBuff.WriteString(fmt.Sprintf("# 服务通知 \r\n> 环境:%s", dev))
templateBuff.WriteString(fmt.Sprintf("\r\n> [节点]:%s", mateData.SourceAgent))
templateBuff.WriteString(fmt.Sprintf("# 服务通知 \r\n> [节点]:%s", mateData.SourceAgent))
for key, value := range mateData.Data {
templateBuff.WriteString(fmt.Sprintf("\r\n> [%s]:%s", key, value))
}
......
......@@ -25,7 +25,7 @@ func (d *Ding) HandleFunc(m *entity.Matedata) error {
for k, v := range (*m).Data {
if dingWebHook != "" && k == searchKey && (searchValue == "" || searchValue == v) {
err := ding.DingDingNotice(dingWebHook, context.Background(), ding.CreateDingMessage("dev", ding.MESSAGE_TYPE_PLUGIN_NOTICE, m, dingMobileData))
err := ding.DingDingNotice(dingWebHook, context.Background(), ding.CreateDingMessage(ding.MESSAGE_TYPE_PLUGIN_NOTICE, m, dingMobileData))
if err != nil {
log.Println(err)
}
......
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