首页 > 编程知识 正文

微信自带监控功能,微信骂人能报警吗

时间:2023-05-03 09:59:43 阅读:261591 作者:960

1,申请企业微信,即以前的企业公众号,https://work.weixin.qq.com/然后“应用与小程序”里增加应用

2,获取的的agentId,secret,“我的企业”里的企业ID三项

3,zabbix我是通过官网的rpm包安装的,配置文件默认位置在/ etc / zabbix / zabbix_server.conf里找到AlertScriptsPath = / usr / lib / zabbix / alertscripts把微信监控脚本放到此目录里,脚本有大神在github上开源了

https://github.com/X-Mars/Zabbix-Alert-WeChat   

或者用如下的脚本,网上找的,测试过可以使用

[root@localhost alertscripts]# cat weixin.py 
#!/usr/义气的花瓣/env python
#-*- coding: utf-8 -*-
#author: 甜美的豆芽
#date: 2018-04-20
#comment: zabbix接入微信报警脚本

import requests
import sys
import os
import json
import logging

logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s',
                datefmt = '%a, %d %b %Y %H:%M:%S',
                filename = os.path.join('/usr/lib/zabbix/alertscripts','weixin.log'),
                filemode = 'a')

corpid='wwc066******ffb1d4'                        #企业自己的id 

appsecret='tgI9z5fkL************MHQ2skWI5SE'    #填企业自己的id
agentid=1000005
#获取accesstoken
token_url='https://qyapi.weixin.qq.com/cgi-义气的花瓣/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']

#发送消息
msgsend_url='https://qyapi.weixin.qq.com/cgi-义气的花瓣/message/send?access_token=' + accesstoken

touser=sys.argv[1]
subject=sys.argv[2]
#toparty='3|4|5|6'
message=sys.argv[3]

params={
        "touser": touser,
#       "toparty": toparty,
        "msgtype": "text",
        "agentid": agentid,
        "text": {
                "content": message
        },
        "safe":0
}

req=requests.post(msgsend_url, data=json.dumps(params))

logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message)
 

4,然后就是zabbix里创建媒体,用户,增加动作了。

 

 

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。