钉钉机器人的设置参见钉钉官方文档 ,这里就不赘述了
https://open.dingtalk.com/document/robots/custom-robot-access
1.查看zabbix server配置文件/etc/zabbix/zabbix_server.conf获取告警脚本存放路径AlertScriptsPath=/usr/lib/zabbix/alertscripts
[root@zabbix ~]# cat /etc/zabbix/zabbix_server.conf | grep 'Alert'
### Option: StartAlerters
# Alerters send the notifications created by action operations.
# StartAlerters=3
### Option: AlertScriptsPath
# AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/usr/lib/zabbix/alertscripts
2.在/usr/lib/zabbix/alertscripts添加dingding.sh脚本
[root@zabbix alertscripts]# pwd
/usr/lib/zabbix/alertscripts
[root@zabbix alertscripts]# more dingding.sh
#!/bin/bash
to=$1
subject=$2
text=$3
# url请填写实际设置的钉钉api
curl 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxx' \
-H 'Content-Type: application/json' \
-d '
{
"msgtype": "text",
"text": {
"content": "'"$text"'"
}
}'
3.添加报警媒介
名称:钉钉告警 (自定义)
类型:脚本
脚本名称:dingding.sh(上一步编写的脚本dingding.sh)
脚本参数:
{ALERT.SENDTO}:消息接收人
{ALERT.SUBJECT}:告警标题
{ALERT.MESSAGE}:告警内容
4.admin用户绑定告警媒介
类型:钉钉告警(第3步的报警媒介名称)
收件人:自定义
5.添加动作触发告警
定义动作名称和触发动作的条件
触发动作后的操作(关联钉钉告警并定义发送的消息内容)
具体操作设置 :
恢复操作设置: