微信报警测试

微信报警 python脚本记录   bankgui2.py

#!/usr/bin/env python
# -*- coding:utf-8 -*-

# Version20190324
import win32gui, os,time


def demo_top_windows():
    # 文件句柄警戒值
    secLine = 90
    hWndList = []
    win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), hWndList)
    print(hWndList)
    print('total window num: ', len(hWndList))
    totalwind = len(hWndList)
    if totalwind > secLine:
        from sendWC import send_msg
        send_msg('民生银行机器提示:', '文件句柄数大于' + str(secLine) + ',请确认--From电信通')
        print('句柄过多')


def portNum():
    # 端口数警戒值
    portLine = int(20)
    comandRes = os.popen('netstat -ano | findstr 8080 | find /v /c ""')
    #print(comandRes)
    portNumSum = int(comandRes.read())
    if portNumSum > portLine:
        from sendWC import send_msg
        send_msg('当前8080端口总计:' + str(portNumSum) + '个,', '无', )
    print('当前8080端口总计:', portNumSum, '个')


while True:
    if __name__ == '__main__':
        demo_top_windows()
        portNum()
    time.sleep(180)

发送报警

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Version20190324
# Author:xp
# blog_url:http://blog.csdn.net/wuxingpu5/
'''pip3 install urllib'''
import sys
import urllib
import urllib.request
import json

try:
    title = sys.argv[2]
    content = sys.argv[3]
except IndexError as e:
    pass


class Token(object):
    def __init__(self, corpid, corpsecret):
        self.baseurl = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}'.format(corpid,
                                                                                                       corpsecret)

    def get_token(self):
        token_file = urllib.request.urlopen(self.baseurl)
        token_data = token_file.read().decode('utf-8')
        token_json = json.loads(token_data)
        # print(token_json)
        token = token_json['access_token']
        return token


''' 企业微信的总id 微信报警应用的Secret'''
corpid = 'xxxx'
corpsecret = 'xxxx'


def send_msg(title, conntent):
    s_token = Token(corpid=corpid, corpsecret=corpsecret).get_token()
    send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}'.format(s_token)
    # toparty:部门ID   agentid:小程序应用id
    send_value = {
        "toparty": "12",
        "msgtype": "text",
        "agentid": "1000002",
        "text": {
            "content": str(title + ' // ' + conntent),
        },
        "safe": 0
    }
    send_data = json.dumps(send_value).encode('UTF-8')
    send_request = urllib.request.Request(send_url, send_data)
    reponse = urllib.request.urlopen(send_request)
    msg = reponse.read()
    print(msg)


if __name__ == '__main__':
    # pass
    send_msg(title, content)
    # send_msg('110report测试', '报警sendSMS2--TEST--from--wechat')

报警需要申请企业微信

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值