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

  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. 创建企业群聊天机器人
    使用企业微信新建一个群,添加群机器人
    image
    image
    image
    记录webhook信息
    image
    如果忘记机器人的Webhook信息使用以下方式查看
    image

  2. 设置微信告警脚本
    在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"}'

同时微信群会发送消息
image

  1. 设置告警媒介
    image

image
image

  1. 设置告警用户和用户组
    设置告警用户
    image
    本次我们选择管理员用户Admin进行设置
    image
    image
    添加一个告警媒介
    image
    image

  2. 设置监控项
    本次设置一个监控Nginx80端口的监控项进行测试
    image

  3. 设置触发器
    image

  4. 设置触发器动作
    image
    image
    image
    设置好之后一旦触发告警则会发送至微信群
    image

posted @   minseo  阅读(80)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2019-10-24 byte类型的取值为什么是-128~127
2017-10-24 Oracle数据类型clob和blob
2017-10-24 Oracle数据类型之nchar
2017-10-24 Oracle数据类型char与varchar的对比
点击右上角即可分享
微信分享提示