一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python實現個人微信號自動監控告警的示例

Python實現個人微信號自動監控告警的示例

2021-07-30 00:10Sunny_Future Python

今天小編就為大家分享一篇Python實現個人微信號自動監控告警的示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

wechat_sender 是基于 wxpy 和 tornado 實現的一個可以將你的網站、爬蟲、腳本等其他應用中各種消息 (日志、報警、運行結果等) 發送到微信的工具。

運行環境

Python 2.7 及以上 Python 3 及以上

實現過程

安裝 pip 工具

  1. [root@server1 ~]# wget https://bootstrap.pypa.io/get-pip.py
  2. [root@server1 ~]# python get-pip.py

Python實現個人微信號自動監控告警的示例

pip 安裝模塊

  1. ##安裝依賴軟件
  2. [root@server1 ~]# yum install -y gcc python-devel
  3. ##安裝
  4. [root@server1 ~]# pip install wechat_sender

Web登錄微信發送消息

安裝web服務器

  1. [root@server1 ~]# yum install -y httpd
  2. [root@server1 ~]# systemctl start http
  3. [root@server1 ~]# systemctl stop firewalld
  1. [root@server1 ~]# cat /var/www/html/index.html
  2. <html>
  3. <head><meta http-equiv="refresh" content="2"></head>
  4. <style>
  5. body {
  6. width: 35em;
  7. margin: 0 auto;
  8. font-family: Tahoma, Verdana, Arial, sans-serif;
  9. }
  10. </style>
  11. <body>
  12. <img src="/qr.png">
  13. </body>
  14. </html>

python腳本代碼

  1. [root@server1 ~]# cat /var/www/html/sender.py
  2. #!/bin/bash/env python
  3. #coding:utf-8
  4.  
  5. from wxpy import *
  6. from wechat_sender import *
  7. from wechat_sender import Sender
  8.  
  9. #bot = Bot() ##windows直接掃
  10. #下面這個是服務器版(Linux)
  11. #bot = Bot(qr_path="qr.png")
  12. #避免重復登錄重復掃二維碼
  13. bot = Bot(qr_path="qr.png",cache_path=True)
  14. ##通過文件助手給登錄的微信號發消息
  15. bot.file_helper.send('Hello world!')

web登錄微信

  1. ##執行python腳本,占用終端,web登錄后會有提示
  2. [root@server1 ~]# cd /var/www/html/
  3. [root@server1 ~]# python sender.py
  4. Getting uuid of QR code.
  5. Downloading QR code.
  6. xdg-open: no method available for opening 'qr.png'
  7. Please scan the QR code to log in.

另一方面,打開瀏覽器輸入 ip or localhost,微信掃一掃

Python實現個人微信號自動監控告警的示例

微信登錄后,終端釋放,提示成功,消息同時發送,并且web二維碼失效

  1. Login successfully as someone

微信點擊確認

Python實現個人微信號自動監控告警的示例

查看手機助手,消息已經收到!

Python實現個人微信號自動監控告警的示例

監控80端口,自動告警

若是web服務也是80端口,請先登錄成功后,如下操作。

shell腳本

  1. [root@server1 ~]# cat /var/www/html/check_80.sh
  2. #!/bin/sh
  3.  
  4. x=$(netstat -antlp | grep '\<80\>'|awk -F' ' '{print $4}'|awk -F: '{print $2}')
  5.  
  6. if [ "$x" != 80 ];then
  7. python /var/www/html/check_80.py &
  8. else
  9. python /var/www/html/check01_80.py &
  10. fi
  11. ##添加執行權限
  12. [root@server1 ~]# chomd +x /var/www/html/check_80.sh
  1. [root@server1 ~]# cat /var/www/html/check01_80.py
  2. #!/bin/sh/env python
  3. #coding:utf-8
  4.  
  5. from wxpy import *
  6. from wechat_sender import *
  7. from wechat_sender import Sender
  8.  
  9. bot = Bot(qr_path="qr.png",cache_path=True)
  10. ##通過文件助手給登錄的微信號發消息
  11. bot.file_helper.send('port 80 nice!')
  1. [root@server1 ~]# cat /var/www/html/check_80.py
  2. #!/bin/sh/env python
  3. #coding:utf-8
  4.  
  5. from wxpy import *
  6. from wechat_sender import *
  7. from wechat_sender import Sender
  8.  
  9. bot = Bot(qr_path="qr.png",cache_path=True)
  10. ##通過文件助手給登錄的微信號發消息
  11. bot.file_helper.send('port 80 error!')
  1. [root@server1 ~]# cat /mnt/check.sh
  2. #!/bin/sh
  3.  
  4. cd /var/www/html
  5. sh check_80.sh
  1. [root@server1 ~]# chmod +x /mnt/check.sh

測試腳本

1.httpd 服務開啟時,端口 80 存在

  1. [root@server1 ~]# sh /mnt/check.sh

Python實現個人微信號自動監控告警的示例

2.httpd 服務關閉后,端口 80 不存在

  1. [root@server1 ~]# systemctl stop httpd
  1. [root@server1 ~]# sh /mnt/check.sh

Python實現個人微信號自動監控告警的示例

3.httpd 服務再次開啟,端口 80 存在

  1. [root@server1 ~]# systemctl start httpd
  1. [root@server1 ~]# sh /mnt/check.sh

Python實現個人微信號自動監控告警的示例

添加任務計劃自動監控進行告警

  1. [root@server1 ~]# crontab -e
  2. * 1 * * * sh /mnt/check.sh

投入使用

添加任務計劃后,妥善修改腳本,避免頻繁告警。

以上這篇Python實現個人微信號自動監控告警的示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持我們。

原文鏈接:https://blog.csdn.net/Sunny_Future/article/details/81545327

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产主播福利在线观看 | 亚洲 综合 自拍 精品 在线 | 天天色天天综合 | 欧美久久久久久久一区二区三区 | 久久综合狠狠综合狠狠 | 成人精品一级毛片 | 侮辱丰满美丽的人妻 | 免费看国产一级片 | avav一区| 人人九九| 四虎1515hhh co m | 国产在线三级 | 青青在线国产视频 | 色偷偷亚洲男人 | 小早川怜子息梦精在线播放 | 成人免费视频大全 | japaneseles女同专区 | 韩国美女vip内部2020 | 我的奶头被客人吸的又肿又红 | 国产98在线| 国产在视频线在精品 | 被黑人同学彻底征服全文小说阅读 | 成人小视频在线观看免费 | 精品在线视频一区 | 办公室里被迫高h | 99九九国产精品免费视频 | 51国产午夜精品免费视频 | 亚洲AV精品一区二区三区不卡 | 大又大又粗又爽女人毛片 | 天美麻豆| 北条麻妃黑人 | 国产成人综合一区人人 | 亚洲福利精品电影在线观看 | 99毛片| 香蕉久久夜色精品国产尤物 | 欧美最猛性xxxxx男男 | 校草太大了h | 草莓视频在线观看免费 | 日韩中文字幕视频在线观看 | 日本中文字幕一区二区有码在线 | 日日操天天爽 |