Python监控微信报警

微信接口调用代码:

`#coding=utf``8`

`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 &`

监控脚本:

在学习过程中有什么不懂得可以加我的
python学习交流扣扣qun,784758214
群里有不错的学习视频教程、开发工具与电子书籍。
与你分享python企业当下人才需求及怎么从零基础学习好python,和学习什么内容

`#!/bin/sh`

`if [ `which fping |wc -l` -eq ``0` `];then`

`wget --limit-rate ``500``k 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 

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