1. 环境查看
    系统环境
# cat /etc/redhat-release 
CentOS Stream release 9
# uname -a
Linux CentOSStream9Zabbix203 5.14.0-391.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 28 20:35:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

软件环境

# zabbix_server --version
zabbix_server (Zabbix) 6.4.10
Revision 4da16fb82f5 13 December 2023, compilation time: Dec 13 2023 00:00:00

Copyright (C) 2023 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <https://www.gnu.org/licenses/>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/).

Compiled with OpenSSL 3.0.7 1 Nov 2022
Running with OpenSSL 3.0.7 1 Nov 2022
# zabbix_agentd --version
zabbix_agentd (daemon) (Zabbix) 6.4.10
Revision 4da16fb82f5 13 December 2023, compilation time: Dec 13 2023 00:00:00

Copyright (C) 2023 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <https://www.gnu.org/licenses/>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/).

Compiled with OpenSSL 3.0.7 1 Nov 2022
Running with OpenSSL 3.0.7 1 Nov 2022
  1. 创建企业群聊天机器人
  2. 使用企业微信新建一个群,添加群机器人
  3. Zabbix添加企业微信机器人告警_微信


  4. Zabbix添加企业微信机器人告警_GNU_02


  5. Zabbix添加企业微信机器人告警_json_03


  6. 记录webhook信息
  7. Zabbix添加企业微信机器人告警_json_04


  8. 如果忘记机器人的Webhook信息使用以下方式查看
  9. Zabbix添加企业微信机器人告警_json_05

  10. 设置微信告警脚本
    在Zabbix服务器编辑Python脚本
# cat /usr/lib/zabbix/alertscripts/wechat.py 
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import json
import sys
import os

headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<key>" #这就是先前的webhook地址
def msg(text):
    json_text= {
     "msgtype": "text",
        "text": {
            "content": text
        },
    }
    print (requests.post(api_url,json.dumps(json_text),headers=headers).content)

if __name__ == '__main__':
    text = sys.argv[1]
    msg(text)

测试脚本,需要添加发送的消息为参数
返回ok代表测试成功

# python wechat.py Hello
b'{"errcode":0,"errmsg":"ok"}'

同时微信群会发送消息

Zabbix添加企业微信机器人告警_json_06

  1. 设置告警媒介

Zabbix添加企业微信机器人告警_json_07


Zabbix添加企业微信机器人告警_GNU_08

  1. 设置告警用户和用户组
  2. 设置告警用户
  3. Zabbix添加企业微信机器人告警_json_09


  4. 本次我们选择管理员用户Admin进行设置
  5. Zabbix添加企业微信机器人告警_微信_10


  6. Zabbix添加企业微信机器人告警_GNU_11


  7. 添加一个告警媒介
  8. Zabbix添加企业微信机器人告警_GNU_12


  9. Zabbix添加企业微信机器人告警_json_13

  10. 设置监控项
  11. 本次设置一个监控Nginx80端口的监控项进行测试
  12. Zabbix添加企业微信机器人告警_json_14

  13. 设置触发器
  14. Zabbix添加企业微信机器人告警_GNU_15

  15. 设置触发器动作
  16. Zabbix添加企业微信机器人告警_微信_16


  17. Zabbix添加企业微信机器人告警_GNU_17


  18. Zabbix添加企业微信机器人告警_微信_18


  19. 设置好之后一旦触发告警则会发送至微信群
  20. Zabbix添加企业微信机器人告警_json_19