最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)個(gè)人微信號(hào)自動(dòng)監(jiān)控告警的示例

 更新時(shí)間:2019年07月03日 09:43:59   作者:Sunny_Future  
今天小編就為大家分享一篇Python實(shí)現(xiàn)個(gè)人微信號(hào)自動(dòng)監(jiān)控告警的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

wechat_sender 是基于 wxpy 和 tornado 實(shí)現(xiàn)的一個(gè)可以將你的網(wǎng)站、爬蟲(chóng)、腳本等其他應(yīng)用中各種消息 (日志、報(bào)警、運(yùn)行結(jié)果等) 發(fā)送到微信的工具。

運(yùn)行環(huán)境

Python 2.7 及以上 Python 3 及以上

實(shí)現(xiàn)過(guò)程

安裝 pip 工具

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

pip 安裝模塊

##安裝依賴(lài)軟件
[root@server1 ~]# yum install -y gcc python-devel
##安裝
[root@server1 ~]# pip install wechat_sender

Web登錄微信發(fā)送消息

安裝web服務(wù)器

[root@server1 ~]# yum install -y httpd
[root@server1 ~]# systemctl start http
[root@server1 ~]# systemctl stop firewalld
[root@server1 ~]# cat /var/www/html/index.html
<html>
<head><meta http-equiv="refresh" content="2"></head>
<style>
  body {
    width: 35em;
    margin: 0 auto;
    font-family: Tahoma, Verdana, Arial, sans-serif;
  }
</style>
<body>
<img src="/qr.png">
</body>
</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直接掃
#下面這個(gè)是服務(wù)器版(Linux)
#bot = Bot(qr_path="qr.png")
#避免重復(fù)登錄重復(fù)掃二維碼
bot = Bot(qr_path="qr.png",cache_path=True)
##通過(guò)文件助手給登錄的微信號(hào)發(fā)消息
bot.file_helper.send('Hello world!')

web登錄微信

##執(zhí)行python腳本,占用終端,web登錄后會(huì)有提示
[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.

另一方面,打開(kāi)瀏覽器輸入 ip or localhost,微信掃一掃

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

Login successfully as someone

微信點(diǎn)擊確認(rèn)

查看手機(jī)助手,消息已經(jīng)收到!

監(jiān)控80端口,自動(dòng)告警

若是web服務(wù)也是80端口,請(qǐng)先登錄成功后,如下操作。

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
##添加執(zhí)行權(quán)限
[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)
##通過(guò)文件助手給登錄的微信號(hào)發(fā)消息
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)
##通過(guò)文件助手給登錄的微信號(hào)發(fā)消息
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 

測(cè)試腳本

1.httpd 服務(wù)開(kāi)啟時(shí),端口 80 存在

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

2.httpd 服務(wù)關(guān)閉后,端口 80 不存在

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

3.httpd 服務(wù)再次開(kāi)啟,端口 80 存在

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

添加任務(wù)計(jì)劃自動(dòng)監(jiān)控進(jìn)行告警

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

投入使用

添加任務(wù)計(jì)劃后,妥善修改腳本,避免頻繁告警。

以上這篇Python實(shí)現(xiàn)個(gè)人微信號(hào)自動(dòng)監(jiān)控告警的示例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 淺談python迭代器

    淺談python迭代器

    這篇文章主要介紹了淺談python迭代器,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-11-11
  • Python實(shí)現(xiàn)從百度API獲取天氣的方法

    Python實(shí)現(xiàn)從百度API獲取天氣的方法

    這篇文章主要介紹了Python實(shí)現(xiàn)從百度API獲取天氣的方法,實(shí)例分析了Python操作百度API的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • python獲取糗百圖片代碼實(shí)例

    python獲取糗百圖片代碼實(shí)例

    python獲取糗百圖片代碼實(shí)例,大家參考使用吧
    2013-12-12
  • Python模擬百度登錄實(shí)例詳解

    Python模擬百度登錄實(shí)例詳解

    最近公司產(chǎn)品和百度貼吧合作搞活動(dòng),為了增加人氣,打算做個(gè)自動(dòng)簽到的小程序,接下來(lái)通過(guò)本文給大家介紹python模擬百度登錄,感興趣的朋友一起學(xué)習(xí)本段代碼吧
    2016-01-01
  • Python3.7下安裝pyqt5的方法步驟(圖文)

    Python3.7下安裝pyqt5的方法步驟(圖文)

    這篇文章主要介紹了Python3.7下安裝pyqt5的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • 用python 批量操作redis數(shù)據(jù)庫(kù)

    用python 批量操作redis數(shù)據(jù)庫(kù)

    這篇文章主要介紹了如何用python 批量操作redis數(shù)據(jù)庫(kù),幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-03-03
  • 基于Python中random.sample()的替代方案

    基于Python中random.sample()的替代方案

    這篇文章主要介紹了基于Python中random.sample()的替代方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-05-05
  • python QT界面關(guān)閉線程池的線程跟隨退出完美解決方案

    python QT界面關(guān)閉線程池的線程跟隨退出完美解決方案

    這篇文章主要介紹了python QT界面關(guān)閉,線程池的線程跟隨退出解決思路方法,本文給大家分享兩種方法結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-11-11
  • Python關(guān)于版本升級(jí)與包的維護(hù)方式

    Python關(guān)于版本升級(jí)與包的維護(hù)方式

    這篇文章主要介紹了Python關(guān)于版本升級(jí)與包的維護(hù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • python負(fù)載均衡的簡(jiǎn)單實(shí)現(xiàn)方法

    python負(fù)載均衡的簡(jiǎn)單實(shí)現(xiàn)方法

    這篇文章給大家介紹用python實(shí)現(xiàn)最簡(jiǎn)單的負(fù)載均衡方法,即將請(qǐng)求發(fā)送到未宕機(jī)的服務(wù)器上,感興趣的朋友一起看看吧
    2018-02-02

最新評(píng)論

东莞市| 德惠市| 资中县| 兴隆县| 洪湖市| 武强县| 芦山县| 新野县| 永宁县| 凤庆县| 揭阳市| 新蔡县| 封开县| 淮北市| 安阳县| 灌南县| 正定县| 白沙| 宁武县| 惠安县| 新晃| 铁岭县| 静安区| 响水县| 那坡县| 华容县| 洪江市| 彭水| 清原| 库伦旗| 黄石市| 黄大仙区| 安溪县| 马边| 北川| 古交市| 衡山县| 漳州市| 三亚市| 柘荣县| 齐河县|