亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

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

系統 4797 0

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

運行環境

Python 2.7 及以上 Python 3 及以上

實現過程

安裝 pip 工具

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

Python實現個人微信號自動監控告警的示例_第1張圖片

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


            
            
            
          

python腳本代碼

            
[root@server1 ~]# cat /var/www/html/sender.py
#!/bin/bash/env python
#coding:utf-8

from wxpy import *
from wechat_sender import *
from wechat_sender import Sender

#bot = Bot()  ##windows直接掃
#下面這個是服務器版(Linux)
#bot = Bot(qr_path="qr.png")
#避免重復登錄重復掃二維碼
bot = Bot(qr_path="qr.png",cache_path=True)
##通過文件助手給登錄的微信號發消息
bot.file_helper.send('Hello world!')

          

web登錄微信

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

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

Python實現個人微信號自動監控告警的示例_第2張圖片

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

            
Login successfully as someone
          

微信點擊確認

Python實現個人微信號自動監控告警的示例_第3張圖片

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

Python實現個人微信號自動監控告警的示例_第4張圖片

監控80端口,自動告警

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

shell腳本

            
[root@server1 ~]# cat /var/www/html/check_80.sh 
#!/bin/sh

x=$(netstat -antlp | grep '\<80\>'|awk -F' ' '{print $4}'|awk -F: '{print $2}')

if [ "$x" != 80 ];then
 python /var/www/html/check_80.py &
else
 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
#coding:utf-8

from wxpy import *
from wechat_sender import *
from wechat_sender import Sender

bot = Bot(qr_path="qr.png",cache_path=True)
##通過文件助手給登錄的微信號發消息
bot.file_helper.send('port 80 nice!')

          
            
[root@server1 ~]# cat /var/www/html/check_80.py 
#!/bin/sh/env python
#coding:utf-8

from wxpy import *
from wechat_sender import *
from wechat_sender import Sender

bot = Bot(qr_path="qr.png",cache_path=True)
##通過文件助手給登錄的微信號發消息
bot.file_helper.send('port 80 error!')

          
            
[root@server1 ~]# cat /mnt/check.sh 
#!/bin/sh

cd /var/www/html
sh check_80.sh

          
            
[root@server1 ~]# chmod +x /mnt/check.sh 
          

測試腳本

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

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

Python實現個人微信號自動監控告警的示例_第5張圖片

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

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

Python實現個人微信號自動監控告警的示例_第6張圖片

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

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

Python實現個人微信號自動監控告警的示例_第7張圖片

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

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

投入使用

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

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


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产亚洲精品久久精品6 | 色噜噜亚洲精品中文字幕 | 成人毛片18女人毛片免费96 | 欧美在线成人免费国产 | 国产精品久久久久久久久久日本 | 四虎影视国产永久免费 | 五月激情婷婷综合 | 久久www免费人成_看 | 四虎国产精品免费视 | 欧美夜色 | 国产720刺激i在线视频 | 夜夜操网站 | 99久久精品国产麻豆 | 免费一级毛片不卡不收费 | 久久精品伊人波多野结 | 橘梨纱视频一区二区在线观看 | 国产麻豆高清视频在线第一页 | 韩国办公室激情 | 99精品免费在线观看 | 按摩毛片 | 日本3p视频在线看高清 | 一级特黄特色aa大片 | 国产精品自在线拍 | 永久福利视频 | 久久在线免费观看视频 | 9191精品国产费久久 | 日韩欧美精品一区二区 | 天天色天天草 | 免费乱理伦片在线观看老妇 | a级毛片在线观看 | 国内外成人在线视频 | 怡红院成人永久免费看 | 欧美成人伦理 | 久久青青草原精品影院 | 天天操夜夜摸 | 欧美成人午夜视频免看 | 中文字幕日本精品一区二区三区 | 中文字幕在线观看一区二区 | 成人a毛片视频免费看 | 亚洲午夜久久久久中文字幕久 | 色色网视频 |