微信報警測試

微信報警 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')

報警需要申請企業微信

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章