钉钉机器人的设置,参见《钉钉机器人》
zabbix服务器监控到异常,可以通过各种方式发送报警消息。配置步骤如下:
1、创建报警脚本
root@node2 ~]# 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 = '钉钉机器人的URL' print(send_msg(url, remiders, msg)) [root@node2 ~]# chmod +x /usr/local/share/zabbix/alertscripts/dingalert.py
钉钉的url是在钉钉里面添加的钉钉机器人的webhook
@@需要安装pip 和 requests模块
yum -y install wget wget https://bootstrap.pypa.io/get-pip.py python get-pip.py pip install requests
配置文件可以在线安装
mkdir ~/.pip/ vim ~/.pip/pip.conf [global] index-url = http://pypi.douban.com/simple/ [install] trusted-host=pypi.douban.com
2、添加报警媒介
![](http://upload-images.jianshu.io/upload_images/12347101-ff595d1fa3c4e0fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
3、配置用户可以使用脚本报警
![](http://upload-images.jianshu.io/upload_images/12347101-c8316dc4d7f8a1d9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](http://upload-images.jianshu.io/upload_images/12347101-848ad677ad6412e2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](http://upload-images.jianshu.io/upload_images/12347101-5c6bc38c81bb6cec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](http://upload-images.jianshu.io/upload_images/12347101-1282fa587ca5d4b6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
4、配置触发动作
![](http://upload-images.jianshu.io/upload_images/12347101-29fa1c101b4792da.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](http://upload-images.jianshu.io/upload_images/12347101-7d7f994e64ae5bb2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](http://upload-images.jianshu.io/upload_images/12347101-64e2fc8466a23013.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](http://upload-images.jianshu.io/upload_images/12347101-057af2ba0dc5a27f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](http://upload-images.jianshu.io/upload_images/12347101-0072ce3b2511c493.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
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、查看动作日志及钉钉消息
![](http://upload-images.jianshu.io/upload_images/12347101-d3058dd3c0ee5e36.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
![](http://upload-images.jianshu.io/upload_images/12347101-a8f7eb2e0fed8447.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)