一、背景
因为业务需求,需要sql工单通知到飞书
二、配置
1.系统管理–>配置项管理
archery_base_url: archery服务器的ip和端口
2.系统管理–>资源组管理
2.1填写webook地址
如何获取webook请参考:
https://blog.csdn.net/line_on_database/article/details/119947755
三、遇到的问题与解决
1.问题
飞书收不到sql工单消息,日志也没有报错
2.原因
新版飞书消息格式有变化,老版本的不兼容,所以需要修改下archery的源码
3.修改代码
vi /opt/archery/common/utils/sendmsg.py
@staticmethod
def send_feishu_webhook(url, title, content):
data = {"title": title, "text": content}
if "/v2/" in url:
if "已正常结束" not in title:
data = {
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": title,
"content": [[{"tag": "text", "text": content}]],
}
}
},
}
else:
# 向飞书发送卡片模式的通知
content_new = content.split('\n')
content_new_con = content_new[:-1]
content = {}
is_split = True
for new_detail in content_new_con:
if is_split:
con_key = new_detail.split(':')
if con_key[0] != "ticket_detail":
content[con_key[0]] = con_key[1]
else:
# 这么处理是防止sql中存在特殊符号的问题以及工单有多条sql的问题
sql_all = ":".join(con_key[1:])
is_split = False
else:
sql_all += new_detail
content["ticket_detail"] = sql_all
content_all = []
for i, j in content.items():
content_text = "**" + i + "**: " + j
content_all.append({"tag": "div","text": {"content": content_text,"tag": "lark_md"}})
content_head = [{"tag": "hr"}]
content_end = [{"tag": "hr"}, {"actions": [{"tag": "button","text": {"content": "View ticket details","tag": "lark_md"},"url": content["ticket_address"],"type": "default","value": {}}],"tag": "action"}]
content_all = content_head + content_all + content_end
data = {"msg_type": "interactive","card": {"config": {"wide_screen_mode": True,"enable_forward": True},"header": {"title": {"content": title,"tag": "plain_text"}},"elements": content_all}}
4.github地址
https://github.com/hhyo/Archery/issues/1016
https://github.com/hhyo/Archery/commit/66ec48f4ac4c521722536cfdf3ce58bd442ba734