怎么使用Python实现个人微信号自动监控告警的示例

  介绍

这篇文章主要介绍了怎么使用Python实现个人微信号自动监控告警的示例,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获、下面让小编带着大家一起了解一下。

wechat_sender是基于wxpy和龙卷风实现的一个可以将你的网站,爬的虫,脚本等其他应用中各种消息(日志,报的警,运行结果等)发送到微信的工具。

<强>运行环境

Python 2.7及以上Python 3及以上

<强>实现过程

安装pip工具

[root@server1  ~] #, wget  https://bootstrap.pypa.io/get-pip.py   (root@server1  ~) #, python  get-pip。py

怎么使用Python实现个人微信号自动监控告警的示例

<强> pip安装模块

# #安装依赖软件   (root@server1  ~) #, yum  install  -y  gcc  python-devel   # #安装   [root@server1  ~) #, pip  install  wechat_sender

<强> Web登录微信发送消息

<强>安装Web服务器

[root@server1  ~] #, yum  install  -y  httpd   (root@server1  ~) #, systemctl  start  http   [root@server1  ~) #, systemctl  stop  firewalld [root@server1  ~] #, cat /var/www/html/index . html   & lt; html>   & lt; head> & lt; meta  http-equiv=皉efresh",内容=?“祝辞& lt;/head>   & lt; style>   body {才能   ,,,宽度:,35 em;   ,,,保证金:,0,汽车;   ,,,字体类型:,大河马字体,,Verdana,, Arial,,无衬线;   ,,}   & lt;/style>   & lt; body>   & lt; https://www.yisu.com/zixun/img  src="/qr.png ">      

python脚本代码

[root@server1  ~] #, cat /var/www/html/sender.py   # !/bin/bash/env  python   utf - 8编码:      得到wxpy  import  *   得到wechat_sender  import  *   得到wechat_sender  import 发送者      # bot =, Bot(),, # #窗户直接扫   #下面这个是服务器版(Linux)   # bot =, Bot (qr_path=皅r.png")   #避免重复登录重复扫二维码   bot =,机器人(qr_path=皅r.png" cache_path=True)   # #通过文件助手给登录的微信号发消息   bot.file_helper.send (& # 39; Hello 世界! & # 39;)

<强> web登录微信

# #执行python脚本,占用终端,网络登录后会有提示   (root@server1  ~) #, cd /var/www/html/(root@server1  ~) #, python  sender.py    Getting  uuid  of  QR 代码。   Downloading  QR 代码。   xdg-open: no  method  available  for  opening  & # 39; qr.png& # 39;   Please  scan 从而QR  code 用log 。

另一方面,打开浏览器输入ip或主机,微信扫一扫

怎么使用Python实现个人微信号自动监控告警的示例

微信登录后,终端释放,提示成功,消息同时发送,并且网络二维码失效

Login  successfully  as 有人

<强>微信点击确认

怎么使用Python实现个人微信号自动监控告警的示例

查看手机助手,消息已经收到!

怎么使用Python实现个人微信号自动监控告警的示例

<强>监控80端口,自动告警

若是web服务也是80端口,请先登录成功后,如下操作。

壳脚本

[root@server1  ~] #, cat /var/www/html/check_80.sh    # !/bin/sh      x=$ (netstat  -antlp  |, grep  & # 39; \ & lt; 80 \祝辞& # 39;| awk  - f # 39;, & # 39;, & # 39; {print  4美元}& # 39;| awk  - f:, & # 39; {print  $ 2} & # 39;)      if  [,“x"美元,!=,80,);   ,python /var/www/html/check_80.py 及   其他的   ,python /var/www/html/check01_80.py 及   fi   # #添加执行权限   (root@server1  ~) #, chomd  + x /var/www/html/check_80。sh [root@server1  ~] #, cat /var/www/html/check01_80.py    # !/bin/sh/env  python   utf - 8编码:      得到wxpy  import  *   得到wechat_sender  import  *   得到wechat_sender  import 发送者      bot =,机器人(qr_path=皅r.png" cache_path=True)   # #通过文件助手给登录的微信号发消息   bot.file_helper.send (& # 39; port  80,不错! & # 39;)

怎么使用Python实现个人微信号自动监控告警的示例