zabbix安装参照zabbix4.0源码包安装,企业微信告警需要分三步走,第一步申请企业公众号,第二步撰写告警脚本,第三步配置zabbix-web界面

申请企业公众号

进入微信公众平台,选择企业微信,按照要求进行填写注册.注册完成后,登录企业微信,点击应用于与小程序,创建应用zabbix4.0企业微信告警

圈起来的都是要填写的,这里可选择部门,也可以是指定人员zabbix4.0企业微信告警

创建完成后,会转到应用管理界面,AgentID和secret是需要记录的,另外还要记录企业ID,点击我的企业,最下面有企业ID.
zabbix4.0企业微信告警
zabbix4.0企业微信告警

上面步骤企业微信号已经完成了,接下来要在zabbix-server端进行脚本编写

zabbix-server脚本配置

[[email protected] alertscripts]#  pwd
/opt/zabbix-4.1/share/zabbix/alertscript 
[[email protected] alertscripts]# cat weichat.py 
 #!/usr/bin/env python
 #-*- coding: utf-8 -*-
 #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('/data/zabbix','we
    ixin.log'),filemode = 'a')
    corpid='xx' #企业ID
    appsecret='xx'  #secret
    agentid=1000002  #AgentID
    #获取accesstoken
    token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
    req=requests.get(token_url)
    accesstoken=req.json()['access_token']
    
    #发送消息
    msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/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
        
测试,接收到消息说明ok,wechatname为企业微信应用程序中的用户ID
    [[email protected] alertscripts]# chmod +x weichat.py 
    [[email protected] alertscripts]# ./weichat.py wechatname Test "This is test message"

配置zabbix-web界面

点击管理------>报警媒介类型------>创建媒体类型------>类型选择脚本,然后填写脚本名称(和服务器上脚本名称一致),三个参数必填,分别是用户,事件,和告警内容
{ALERT.SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE}
zabbix4.0企业微信告警

配置告警接收用户

管理----->用户----->报警媒介(收件人就是部门用户,也可以设置部门ID(没测,应该可以))
zabbix4.0企业微信告警

配置告警发送条件

配置----->动作,设置触发条件
zabbix4.0企业微信告警

操作中设置发送到用户,仅送到weichat(之前创建的报警媒介类型),然后进行测试即可

zabbix4.0企业微信告警

相关文章:

  • 2021-11-20
  • 2022-12-23
  • 2021-11-13
  • 2021-10-30
  • 2021-12-15
  • 2018-11-21
  • 2021-07-12
猜你喜欢
  • 2022-02-21
  • 2021-08-09
  • 2022-01-14
  • 2021-06-04
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
相关资源
相似解决方案