Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dingtalk #326

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions app/horus/core/alert/dingtalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ import (

const Title = "钉钉机器人"

type content struct {
Content string `json:"content"`
}

type at struct {
AtMobiles []string `json:"atMobiles"`
}

type Message struct {
MessageType string `json:"messageType"`
Text content `json:"text"`
At at `json:"at"`
}

type T struct {
At struct {
AtMobiles []string `json:"atMobiles"`
Expand All @@ -52,23 +38,37 @@ type T struct {
Msgtype string `json:"msgtype"`
}

type content struct {
Content string `json:"content"`
}

type at struct {
AtMobiles []string `json:"atMobiles"`
}

type Message struct {
MsgType string `json:"msgtype"`
Text content `json:"text"`
At at `json:"at"`
}

func DingTalkSend(dk *config.DingTalkConfiguration, msg string) {
dtm := Message{MessageType: "text"}
dtm := Message{MsgType: "text"}
dtm.Text.Content = fmt.Sprintf("%s\n"+
"【日志详细信息:%s】", Title, msg)
"【日志:%s】", Title, msg)
dtm.At.AtMobiles = dk.AtMobiles
bs, err := json.Marshal(dtm)
if err != nil {
klog.Errorf("dingTalk json marshal err:%v\n msg:%v\n", err, msg)
klog.Errorf("dingTalk json marshal err:%v\n dtm:%v\n", err, dtm)
return
}
res, err := http.Post(dk.WebhookUrl, "application/json", bytes.NewBuffer(bs))
if err != nil {
klog.Errorf("push dingTalk err:%v\n msg:%v\n", err, msg)
klog.Errorf("send dingTalk err:%v\n msg:%v\n", err, msg)
}
if res.StatusCode != 200 && res != nil {
klog.Errorf("push dingTalk status code err:%v\n code:%v\n msg:%v\n", err, res.StatusCode, msg)
if res != nil && res.StatusCode != 200 {
klog.Errorf("send dingTalk status code err:%v\n code:%v\n msg:%v\n", err, res.StatusCode, msg)
return
}
klog.Infof("push dingTalk success code:%v\n msg:%v\n", res.StatusCode, msg)
klog.Infof("send dingTalk success code:%v\n msg:%v\n", res.StatusCode, msg)
}
6 changes: 3 additions & 3 deletions deploy/horus/horus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ mysql:
debug: false

dingTalk:
webhookUrl: "https://oapi.dingtalk.com/robot/send?access_token=aa2f3f74d7a2504653ca89b7a673707ba1d04b6d9d320c3572e5464d8f81471e"
title: "工单通知处理"
webhookUrl: ~
title: ~
atMobiles:
- 1500000000
- 1500000000

slack:
webhookUrl: ~
Expand Down
Loading