importoracledbimportrequestsimportjson# 配置区 请自行修改 db_host192.168.1.100db_port1521db_servicedb_userdb_pwd#飞书机器人Webhook 地址FEISHU_WEBHOOKhttps://# # 扩展后的SQL新增 用户名、任务状态 两个字段一共6个字段sql SELECT 1 AS 任务表名, 1 AS 用户名, 1 AS 存储过程包名, 1 as 存储过程名, 1 AS 执行日期, 1 AS 任务状态 FROM test WHERE IS_SUCCESS 失败 defsend_feishu_msg(text):data{msg_type:text,content:{text:text}}headers{Content-Type:application/json}resprequests.post(FEISHU_WEBHOOK,datajson.dumps(data),headersheaders)print(飞书推送结果:,resp.text)defmain():dsnoracledb.makedsn(db_host,db_port,service_namedb_service)connoracledb.connect(userdb_user,passworddb_pwd,dsndsn)curconn.cursor()cur.execute(sql)rowscur.fetchall()cur.close()conn.close()ifnotrows:print(✅ 今日无失败BI任务无需告警)return# 长分割线msg【BI任务失败告警】\n\ntask_index1max_task15show_listrows[:max_task]iflen(rows)max_task:msgf⚠️ 共{len(rows)}条失败任务仅展示前{max_task}条\n\nforrowinshow_list:# 6个字段对应解包col1,col2,col3,col4,col5,col6row msgf{task_index}\nmsgf数据表{col1}\nmsgf执行用户{col2}\nmsgf程序包{col3}\nmsgf存储过程{col4}\nmsgf执行日期{col5}\nmsgf任务状态{col6}\n\ntask_index1print(组装完成告警消息\n,msg)send_feishu_msg(msg)if__name____main__:main()