目前公司生产环境日志系统使用ELK搭建,所有的消息都汇总到统一的日志平台,异常日志一开始都是通过邮件通知发送的,考虑到消息的及时性,后期我们增加了钉钉告警。
然而钉钉的打开率是极低的,即时有消息也懒得看一眼,特别是在周末。如果告警通知可以发送的微信上那岂不是美滋滋,娱乐通知两不误。其实企业微信公众平台是可以调用API实现报警功能的,但是对于个人开发用户来说是不现实的,总不能因为这个功能,注册个公司。
很多牛逼的开发者,利用 web 版微信的协议封装成了工具类,可以通过个人微信实现登录,消息的接收和发送功能。wechat_sender 就是基于 wxpy 和 tornado 实现的一个可以将你的网站、爬虫、脚本等其他应用中各种消息 (日志、报警、运行结果等) 发给到微信的工具
pip install wechat_sender
Python 2.7 及以上 Python 3 及以上
启动 wechat.py
# coding: utf-8
from __future__ import unicode_literals
from wxpy import *
from wechat_sender import listen
bot = Bot('bot.pkl')
listen(bot)
发送 sender.py
# coding: utf-8
from __future__ import unicode_literals
from wxpy import *
import sys
# 日志告警这里有三个参数 %{type} %{path} %{message},可根据自己的日志自行配置参数
if len(sys.argv) == 4:
bot = Bot('bot.pkl')
# 关闭群主确认,否则无法找到对应的群组
alarm_group = bot.groups().search('监控报警')[0]
message = "项目名:{type}, 日志路径 {path},详细信息 {message}".format(type=sys.argv[1], path=sys.argv[2], message=sys.argv[3])
alarm_group.send(message)
把发送脚本嵌入到相应的告警脚本中:
sender.py 参数一 参数二 参数三
总的来说还是很方便的,毕竟别人已经封装好了,这里登录的是 Web 网页端,并不影响 App 端的使用。
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》