python监控微信报警

微信接口调用代码:

#coding=utf8
import itchat
from flask import Flask, request

itchat.auto_login(enableCmdQR=2)                         //微信登录二维码
list = itchat.search_chatrooms(name=u'服务监控')        //微信群名
toUserName = list[0]['UserName']

app = Flask(__name__)
@app.route("/wx/sendMessage")
def send_wechat_message():
	message = request.args.get('message')
	itchat.send(message, toUserName=toUserName)
	return 'message sent successfully'

if __name__ == '__main__':
	app.run(host='0.0.0.0', port='8888')

后台运行:
nohup python weixin.py &

 监控脚本:

#!/bin/sh
if [ `which fping |wc -l` -eq 0 ];then
wget --limit-rate 500k http://www.fping.org/dist/fping-3.8.tar.gz
tar zxvf fping-3.8.tar.gz && cd fping-3.8
./configure && make && make install
fi
rm -f ip.txt result.txt
for i in `seq 5 20`
do 
echo 10.254.33.$i >>ip.txt
done 
cat ip.txt |fping -u >>result.txt
while read line
do
        wget -SO /dev/null http://120.198.244.252:8888/wx/sendMessage?message=$line挂了
done 

 

转载于:https://www.cnblogs.com/Dev0ps/p/7834832.html

你可能感兴趣的:(python监控微信报警)