1、配置zabbix推送脚本
找到zabbix脚本目录alertscripts,find / -name alertscripts,新建python脚本
vi /usr/lib/zabbix/alertscripts/wxrobot.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=70ce7757-8f9c-4da6-84c0-f76146215c86”
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)
其中 “https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=70ce7757-8f9c-4da6-84c0-f76146215c86” 为企业微信机器人获取的webhook地址

2、赋予脚本执行权限,安装python组件,测试python脚本是否能成功发送
chmod +x /usr/lib/zabbix/alertscripts/wxrobot.py
yum install -y epel-release
yum install -y python-pip
yum install -y python-requests
ubuntu:
chmod +x /usr/lib/zabbix/alertscripts/wxrobot.py
apt-get install python-pip
pip install requests
3、测试发送效果
python wxrobot.py ceshi
4、zabbix页面配置
4.1添加业务报警媒介
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}

4.2添加用户报警媒介

4.3 动作内添加报警操作

钉钉webhook配置
vi /usr/lib/zabbix/alertscripts/dingding.sh
[root@zabbix alertscripts]# cat dingding.sh
#!/bin/bash
to=$1
subject=$2
text=$3
curl -i -X POST \
-H ‘Content-type’:’application/json’ \
-d ‘
{
“msgtype”: “text”,
“text”: {
“content”: “‘warning””$text”‘”
},
“at”:{
“atMobiles”:[
“‘”$1″‘”
],
“isAtAll”:false
}
}’
赋予脚本执行权限
[root@zabbix alertscripts]# chmod +x dingding.sh
测试
[root@zabbix alertscripts]# sh dingding.sh 111
HTTP/1.1 200 OK
Server: DingTalk/1.0.0
Date: Fri, 30 Apr 2021 01:16:39 GMT
Content-Type: application/json
Content-Length: 27
Connection: keep-alive
Cache-Control: no-cache
飞书webhook配置
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import json
import sys
import os
import datetime
url = “https://open.feishu.cn/open-apis/bot/v2/hook/687333dd-e80a-4721-a7b2-be92da9bccea”
def send_message(message):
payload_message = {
“msg_type”: “text”,
“content”: {
“text”: message
}
}
headers = {
‘Content-Type’: ‘application/json’
}
response = requests.request(“POST”, url, headers=headers, data=json.dumps(payload_message))
return response
if __name__ == ‘__main__’:
text = sys.argv[1]
send_message(text)
