今天收到開發反饋,archery工單不在飛群書內通知了,
從archery服務器cul 飛書群機器人webhook地址可以正常推送消息,估計是飛書接口發生了變化,
因為之前archery推送消息到飛書webhook也不行,最后去行webhook地址中的v2關鍵字才成功。
進入到archery 所在docker中查看日志,報錯在【/opt/archery/common/utils/sendmsg.py】 第212行代碼
[root@3a5c33b1a688 logs]# tail -f archery.log File "/opt/archery/sql/notify.py", line 64, in __send msg_sender.send_feishu_webhook(feishu_webhook, msg_title, msg_content) File "/opt/archery/common/utils/sendmsg.py", line 212, in send_feishu_webhook if r_json['ok']: KeyError: 'ok'
查看【send_feishu_webhook】發送消息的方法,這個並不符合飛書規范,
飛書幫助文檔:
https://open.feishu.cn/document/ukTMukTMukTM/uUjNz4SN2MjL1YzM
報錯根本原因是缺少msg_type,這個是必填項。
def send_feishu_webhook(url, title, content): data = { xxxxxx } r = requests.post(url=url, json=data) r_json = r.json() #if r_json['ok']: if r_json.get('StatusCode') == 0: logger.debug(f'飛書Webhook推送成功\n通知對象:{url}\n消息內容:{content}') else: logger.error(f"飛書Webhook推送失敗錯誤碼\n請求url:{url}\n請求data:{data}\n請求響應:{r_json}")
最后將
data = {
xxxxx
}
替換為,可以正常推送消息。
data = { "msg_type": "post", "content": { "post": { "zh_cn": { "title": title, "content": [ [ { "tag": "text", "text": content } ] ] } } } }
我們目前正在由企業微信向飛書過渡階段,webhook地址既配置了飛書,又配置了企業微信,
但archery推送消息是順序推的,先推飛書,再推企業微信,如果推飛書失敗,就退了代碼不再繼續推企業微信了。
最后看了github,才發現官方在1.8.1中修復這個問題了
https://github.com/hhyo/Archery/blob/master/common/utils/sendmsg.py
繼續優化這段代碼,如果工單審核通過后
def send_feishu_webhook(url, title, content): if "審核通過" in title or "異常" in title: data={"msg_type": "post", "content": { "post": { "zh_cn": { "title": title, "content": [ [ { "tag": "text", "text": content }, { "tag": "at", "user_id": "dba1" }, { "tag": "at", "user_id": "dba2" } ] ] } } } } else: data = { "msg_type": "post", "content": { "post": { "zh_cn": { "title": title, "content": [ [ { "tag": "text", "text": content } ] ] } } } } r = requests.post(url=url, json=data) r_json = r.json() #if r_json['ok']: if r_json.get('StatusCode') == 0: logger.debug(f'飛書Webhook推送成功\n通知對象:{url}\n消息內容:{content}') else: logger.error(f"飛書Webhook推送失敗錯誤碼\n請求url:{url}\n請求data:{data}\n請求響應:{r_json}")