archery-工单通知飞书

一、背景

因为业务需求,需要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

Archery 定位于 SQL 审核查询平台,旨在提升 DBA 的工作效率,支持多种数据库的 SQL 上线和查询,同时支持丰富的MySQL运维功能,所有功能都兼容手机端操作。 启动: 下载 Releases文件,解压后进入docker-compose文件夹 #启动 docker-compose -f docker-compose.yml up -d #表结构初始化 docker exec -ti archery /bin/bash cd /opt/archery source /opt/venv4archery/bin/activate python3 manage.py makemigrations sql   python3 manage.py migrate #数据初始化 python3 manage.py dbshellpython3 manage.py dbshell #创建管理用户 python3 manage.py createsuperuser #重启服务 docker restart archery #日志查看和问题排查 docker logs archery -f --tail=10 logs/archery.log 访问 http://127.0.0.1:9123/     Archery SQL审核查询平台 更新日志: v1.8.1 变更说明 移除对 Inception 的审核支持,仅作为脱敏语句解析使用 在线查询,pg数据库增加会话超时设定,支持查询脱敏 慢查日志和明细列表支持按表头字段进行服务端排序 默认资源组、权限组支持多选,优化系统配置下拉选项 修复说明 解决数据库区分大小写时查看事务信息报错的问题 解决 memoryview is not JSON serializable PG脱敏-查询语句中带有别名脱敏处理 解决查询结果不展示json对象的问题 调整启动方式为wsgi,解决上版本出现访问阻塞的问题 企业微信消息推送,如果消息接受者ID为空,则不会调用企业微信官方API. fix(sendmsg/feishu): fix #1016 支持新版飞书 webhook 接口 ) Bump django from 3.1.2 to 3.1.6 add pycryptodome to requirements 易用性调整 手动执行按钮改名为“已手动完成” 安全性调整 对接受入参的SQL拼接增加参数转义,规避注入风险 使用shlex.quote()对插件参数进行过滤,规避注入风险
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值