send_dingtalk_message_py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
def send_dingtalk_message(url, title, text):
data = {
'msgtype': 'markdown',
'markdown': {
'title': title,
'text': text
}
}
headers = {'Content-Type': 'application/json'}
r = requests.post(url=webhook_url, json=data, headers=headers)
if r.status_code != 200:
print("Failed to send DingTalk message")
# 在 GitLab CI/CD 失败时发送钉钉告警
if __name__ == '__main__':
webhook_url = "https://oapi.dingtalk.com/robot/send?access_token=bcdf2e90931150c5ff3492d78af2f69cdda649a757e54a46096ba4121d6a974c"
title = '测试告警'
text = "### Ob_NoteGit告警详情\n\n- 错误信息: GitLab CI/CD 失败:git@gitlab.fscloude.cn:obsidiannote/fsbook.git"
send_dingtalk_message(webhook_url, title, text)
本文由作者按照
CC BY 4.0
进行授权