zabbix 硬盘健康监控
#!/bin/sh function sh { sd=`ls /dev/ | grep '^sd' |grep -v '[0-9]$'` echo '' > /usr/local/zabbix/scripts/disk sed -i '1'd /usr/local/zabbix/scripts/disk num=0 for i in ${sd[@]} do b=`smartctl -H /dev/$i | grep -iE "FAILURE PREDICTION THRESHOLD EXCEEDED|FAILURE|ERROR"` if [[ -n $b ]];then data[$num]="/dev/$i $b" num=$[$num+1]; fi done if [ "$num" == '0' ];then echo "ok" >> /usr/local/zabbix/scripts/disk else echo "$data" >> /usr/local/zabbix/scripts/disk fi df=`df -P ` data=`echo "$df" | sed '1'd | awk '{print $NF}' | grep -Ev '^/sys'` date=`date +"%Y%m%d%H%M%S"` for i in $data do ok=`echo "$date" > $i/disktest && echo 'ok'` info=`cat $i/disktest` if [ "ok" != "$ok" ];then tmp=`echo "$df" | grep "$i" | awk '{print $1}'` sed -i 's/ok/read-only/g' /usr/local/zabbix/scripts/disk; echo -e "$tmp $i read-only $info" >> /usr/local/zabbix/scripts/disk; fi done } function healthy { cat /usr/local/zabbix/scripts/disk } function help { echo "sh 获取磁盘信息" } $1
0.添加到任务计划,使用root账号执行
#zabbix
*/5 * * * * root cd /usr/local/zabbix/scripts/;./disk.sh sh >/dev/null 2>&1
1.编辑模板
2.触发器配置
3.报警信息