- 环境查看
系统环境
# 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端口的监控项进行测试
- 设置触发器
- 设置触发器动作
- 设置好之后一旦触发告警则会发送至微信群