目录
1.选择创建媒介类型
??
注:
密码为qq邮箱的授权密码,要去邮箱获取?
2.测试
成功!!
1.钉钉群添加机器人?并复制webhook
2.在zabbix节点上编写zabbix server钉钉报警脚本?
vi dingding.py
#!/usr/bin/env python3
#coding:utf-8
#zabbix钉钉报警
import requests,json,sys,os,datetime
webhook="************" ?????#说明:这里改为自己创建的机器人的webhook的值
user=sys.argv[1]
text=sys.argv[3]
data={
????"msgtype": "text",
????"text": {
????????"content": text
????},
????"at": {
????????"atMobiles": [
????????????user
????????],
????????"isAtAll": False
????}
}
headers = {'Content-Type': 'application/json'}
x=requests.post(url=webhook,data=json.dumps(data),headers=headers)
if os.path.exists("/usr/local/zabbix/log/dingding.log"):
????f=open("/usr/local/zabbix/log/dingding.log","a+")
else:
????f=open("/usr/local/zabbix/log/dingding.log","w+")
f.write("\n"+"--"*30)
if x.json()["errcode"] == 0:
????f.write("\n"+str(datetime.datetime.now())+" ???"+str(user)+" ???"+"发送成功"+"\n"+str(text))
????f.close()
else:
????f.write("\n"+str(datetime.datetime.now()) + " ???" + str(user) + " ???" + "发送失败" + "\n" + str(text))
????f.close()
3.将脚本移动到zabbix脚本目录
mv dingding.py /usr/lib/zabbix/alertscripts
4.?创建日志目录
mkdir /usr/local/zabbix
mkdir /usr/local/zabbix/log
touch /usr/local/zabbix/log/dingding.log
chown zabbix.zabbix /usr/local/zabbix/log/dingding.log
5.赋可执行权限?
chmod +x /usr/lib/zabbix/alertscripts/dingding.py
6.安装python的requests模块
① 安装python3
yum install -y python3
② 安装request模块
pip3 install requests
7.测试脚本是否能够报警
cd /usr/lib/zabbix/alertscripts
./dingding.py test gaojing "报警"
8.打开zabbix server界面,在管理菜单,找到报警媒介类型,创建媒体类型
?脚本参数
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}?
?