作者:mobiledu2502924307 | 来源:互联网 | 2023-09-15 16:41
zabbix-微信告警目录zabbix-微信告警安装Python写py脚本添加执行权限测试脚本创建报警媒介创建动作给用户添加报警媒介安装Python##安装pip[root@db0
zabbix-微信告警
目录
- zabbix-微信告警
- 安装Python
- 写py脚本
- 添加执行权限
- 测试脚本
- 创建报警媒介
- 创建动作
- 给用户添加报警媒介
安装Python
## 安装pip
[root@db02 ~]# yum install python-pip -y
## 安装requests模块
[root@db02 ~]# pip install requests -i https://pypi.douban.com/simple/
写py脚本
## 进入zabbix告警脚本存放目录
[root@db02 ~]# cd /usr/lib/zabbix/alertscripts
[root@db02 alertscripts]# cat weixin.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 = "xxxxx" #这个是企业微信机器人生成的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)
添加执行权限
[root@db02 alertscripts]# chmod +x weixin.py
测试脚本
[root@db02 alertscripts]# ./weixin.py test
{"errcode":0,"errmsg":"ok"}
创建报警媒介
# 脚本参数
{ALERT.MESSAGE}
![image-20211028192247911](https://img2.php1.cn/3cdc5/3af5/cd5/536f8c8e7014317b.png)
创建动作
![image-20211028193714060](https://img2.php1.cn/3cdc5/3af5/cd5/e19f603505daa682.png)
给用户添加报警媒介
![image-20211029154427545](https://img2.php1.cn/3cdc5/3af5/cd5/befcc67dbdfbcedf.png)