Skip to content

Instantly share code, notes, and snippets.

@UlricQin
Created September 14, 2022 07:59
Show Gist options
  • Save UlricQin/81b5faaf479fae1d2e23e42a387dfed5 to your computer and use it in GitHub Desktop.
Save UlricQin/81b5faaf479fae1d2e23e42a387dfed5 to your computer and use it in GitHub Desktop.
1. 修改webapi.conf,具体调整如下:
修改企微机器人那个NotifyChannels,把“企微机器人”换成“企微用户”
新增一个 NotifyChannels:
[[NotifyChannels]]
Label = "企微机器人"
Key = "webot"
修改 ContactKeys,修改这个:
[[ContactKeys]]
Label = "Wecom Robot Token"
Key = "wecom_robot_token"
改成:
[[ContactKeys]]
Label = "企微个人账号"
Key = "wecom_robot_token"
增加一个新的 ContactKeys:
[[ContactKeys]]
Label = "企微Bot密钥"
Key = "webot_token"
2. 修改报警发送脚本,增加一个 send_webot 函数,类似如下的代码:
@classmethod
def send_webot(cls, payload):
users = payload.get('event').get("notify_users_obj")
content = payload.get('tpls').get("wecom.tpl", "wecom.tpl not found")
tokens = {}
if not users:
return
for u in users:
contacts = u.get("contacts")
if contacts.get("webot", ""):
tokens[contacts.get("webot", "")] = 1
if not tokens:
return
for t in tokens:
url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={}".format(t)
header = {
"Content-Type": "application/json"
}
form_data = {
"msgtype": "markdown",
"markdown": {
"content": content
}
}
rep = requests.post(url, data=json.dumps(form_data).encode('utf-8'), headers=header)
if rep.status_code != 200:
print("webot response status code not 200")
print(rep.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment