1.创建报警脚本 vim /usr/local/share/zabbix/alertscripts/dingalert.py
#!/usr/bin/env python import json import requests import sys
def send_msg(url, remiders, msg): headers = {'Content-Type': 'application/json; charset=utf-8'} data = { "msgtype": "text", "at": { "atMobiles": remiders, "isAtAll": False, }, "text": { "content": msg, } } r = requests.post(url, data=json.dumps(data), headers=headers) return r.text if __name__ == '__main__': msg = sys.argv[1] remiders = [] url = 'https://oapi.dingtalk.com/robot/send?access_token=25d508284f88ceef20f6aa7eaf0820d0a0af67398c998463a5dbf77c189f7b6d' print(send_msg(url, remiders, msg))
2、添加报警媒介
![](http://upload-images.jianshu.io/upload_images/12347101-ff595d1fa3c4e0fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z1.png
3、配置用户可以使用脚本报警
![](http://upload-images.jianshu.io/upload_images/12347101-c8316dc4d7f8a1d9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z2.png
![](http://upload-images.jianshu.io/upload_images/12347101-848ad677ad6412e2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z3.png
![](http://upload-images.jianshu.io/upload_images/12347101-5c6bc38c81bb6cec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z4.png
![](http://upload-images.jianshu.io/upload_images/12347101-1282fa587ca5d4b6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z5.png
4、配置触发动作
![](http://upload-images.jianshu.io/upload_images/12347101-29fa1c101b4792da.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z6.png
![](http://upload-images.jianshu.io/upload_images/12347101-7d7f994e64ae5bb2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z7.png
![](http://upload-images.jianshu.io/upload_images/12347101-64e2fc8466a23013.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z8.png
![](http://upload-images.jianshu.io/upload_images/12347101-057af2ba0dc5a27f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z9.png
![](http://upload-images.jianshu.io/upload_images/12347101-0072ce3b2511c493.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
z10.png
5、触发报警条件。如,本例中/boot分区空间不足20%将会发生报警。
[root@node2 ~]# dd if=/dev/zero of=/boot/t.img bs=1M count=800
[root@node2 ~]# df -h /boot/
文件系统 容量 已用 可用 已用% 挂载点
/dev/vda1 1014M 961M 54M 95% /boot
6、查看动作日志及钉钉消息
作者:凯茜的老爸
链接:https://www.jianshu.com/p/6317121da5a4
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。