1,釘釘上添加機(jī)器人,復(fù)制webhook

image.png
2,找一下zabbix server 上定義的告警腳本目錄
[root@zabbix-server ~]# grep alertscripts /etc/zabbix/zabbix_server.conf
[root@zabbix-server ~]# AlertScriptsPath=/usr/lib/zabbix/alertscripts
3,在/usr/lib/zabbix/alertscripts 目錄創(chuàng)建dingding.py,內(nèi)容如下:
#!/usr/bin/python
# coding: utf-8
import requests
import json
import sys
import os
headers = {'Content-Type': 'application/json;charset=utf-8'}
#api_url后跟告警機(jī)器人的webhook
api_url = "https://oapi.dingtalk.com/robot/send?access_token=*********************"
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)
4, 給ding.py執(zhí)行權(quán)限,并測(cè)試一下:
[root@zabbix-server ~]# chmod +x dingding.py
[root@zabbix-server ~]# python ./dingding.py test
群里面也能收到測(cè)試消息:

image.png
如果報(bào)錯(cuò)

image.png
這原因是沒有安裝python中的requests模塊
安裝requests
yum -y install epel-release
yum -y install python-pip
pip install requests
yum clean all
5, 在zabbix-serve頁面中添加媒介

image.png
6, 創(chuàng)建用戶,并為用戶添加報(bào)警媒介,記得授權(quán),沒有權(quán)限接收不到報(bào)警消息

image.png

image.png
7,添加動(dòng)作,
配置動(dòng)作-創(chuàng)建動(dòng)作 ,事件源觸發(fā)器
報(bào)警信息動(dòng)作

image.png
恢復(fù)操作信息發(fā)送

image.png
8,觸發(fā)報(bào)警后,得到

image.png