Zabbix添加企业微信机器人告警
- 环境查看
系统环境
# 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
-
创建企业群聊天机器人
使用企业微信新建一个群,添加群机器人
记录webhook信息
如果忘记机器人的Webhook信息使用以下方式查看
-
设置微信告警脚本
在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"}'
同时微信群会发送消息
- 设置告警媒介
-
设置告警用户和用户组
设置告警用户
本次我们选择管理员用户Admin进行设置
添加一个告警媒介
-
设置监控项
本次设置一个监控Nginx80端口的监控项进行测试
-
设置触发器
-
设置触发器动作
设置好之后一旦触发告警则会发送至微信群
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享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的对比