forked from webclinic017/FinHack-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalert.py
More file actions
executable file
·42 lines (38 loc) · 1.39 KB
/
alert.py
File metadata and controls
executable file
·42 lines (38 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import datetime
import requests
from library.config import config
class alert:
def send(module,title,content):
cfgAlert=config.getConfig('alert')
title=cfgAlert['key']+module+":"+title
if(cfgAlert['enable']=='True'):
if 'api' in cfgAlert['dingtalk_webhook']:
alert.sendDingTalk(cfgAlert['dingtalk_webhook'],title,content)
if 'api' in cfgAlert['feishu_webhook']:
alert.sendFeishu(cfgAlert['feishu_webhook'],title,content)
def sendFeishu(url,title,content):
data_json = json.dumps({
"msg_type": "post",
"content":
{"post":
{"zh_cn":
{"title": title,
"content": [[
{"tag": "text",
"text": content
},
]]}}}})
r = requests.post(url, data_json)
print(r)
def sendDingTalk(url,title,content):
msg=title+"\n"+content
headers = {'Content-Type': 'application/json;charset=utf-8'}
data = {
"msgtype": "text", # 发送消息类型为文本
"text": {
"content": msg, # 消息正文
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)