脚本写在zabbix-server端
安装钉钉和添加群还有机器人
shell脚本(记住token;关键字测试脚本要用)
#!/bin/bash
source /etc/profile
#PHONE=$1
#SUBJECT=$2
MESSAGE=$1
#echo "redis-> ${MESSAGE}" > /tmp/dingding.log
/usr/bin/curl -X "POST" 'https://oapi.dingtalk.com/robot/send?access_token=6b515c1c0e88282ce7af6bc8cac7ddbf111404a04952537dec02e0dd136a6456' \
-H 'Content-Type: application/json' \
-d '{"msgtype": "text",
"text": {
"content": "'${MESSAGE}'"
}
}'
python脚本
#!/usr/bin/python3
import sys
import requests
import json
#钉钉告警:
def info(msg):
url = 'https://oapi.dingtalk.com/robot/send?access_token=6b515c1c0e88282ce7af6bc8cac7ddbf111404a04952537dec02e0dd136a6456'
headers = {
'Content-Type': 'application/json;charset=utf-8'
}
formdata = {
"msgtype": "text",
"text": {"content":str(msg)}
}
#print(formdata)
requests.post(url=url, data=json.dumps(formdata),headers=headers)
info(sys.argv[1])
管理—》创建媒介类型—》用户—》媒介报警—》配置—》动作
{ALERT.MESSAGE}
【万博集团】北京业务故障服务器:{HOST.NAME},IP:{HOSTNAME1},详情:{ITEM.NAME},{ITEM.VALUE}
这里起到了分层发送告警
【万博集团】北京业务恢复服务器:{HOST.NAME},IP:{HOSTNAME1},详情:{ITEM.NAME},{ITEM.VALUE}
web界面报错
思路:如果监控报错没有发送先在本机echo检查在脚本添加
echo "redis-> ${MESSAGE}" > /tmp/dingding.log
|