• 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 <result.txt
    
  • 相关阅读:
    CodeForcesGym 100524A Astronomy Problem
    ZOJ 2567 Trade
    HDU 3157 Crazy Circuits
    CodeForcesGym 100212E Long Dominoes
    UVALive 6507 Passwords
    [转]
    java socket
    Spark RDD Operations(2)
    Spark cache 和 persist
    vim 基础命令
  • 原文地址:https://www.cnblogs.com/Dev0ps/p/7834832.html
Copyright © 2020-2023  润新知