统计告警脚本
脚本内容:
[root@localhost alertscripts]# cat ./count.sh
#!/bin/sh
### ## 版本:V1.0 2019-2-21 22:28
#------------------------------
## array1 普通信息
## array2 警告信息
## array3 一般问题
## array4 严重问题
## array5 灾难
#-----------------------------
now=`date +%s`
fix=`expr $now - 86400`
today=`date +%Y-%m-%d-%H:%M:%S `
yesterday=`date +%Y-%m-%d-%H:%M:%S --date="-1 day"`
myconn="mysql -uzabbix -ppassword zabbix"
result=`${myconn} -e "SELECT objectid FROM events WHERE value=1 AND objectid >10000 AND clock>=${fix} AND clock<=${now} ORDER BY clock DESC LIMIT 100" | grep -v "objectid"`
i=0
for trid in ${result};do
PRO=`${myconn} -e "SELECT priority FROM triggers t WHERE ((t.triggerid BETWEEN 000000000000000 AND 099999999999999)) AND (t.triggerid IN(${trid}))"| grep -v priority`
case $PRO in
1) array1[$i]=${PRO};;
2) array2[$i]=${PRO};;
3) array3[$i]=${PRO};;
4) array4[$i]=${PRO};;
5) array5[$i]=${PRO};;
*) error[$i]=${PRO};;
esac
i=`expr $i + 1`
done
message="
|灾难问题:${#array5[@]}个
|严重问题:${#array4[@]}个
|一般问题:${#array3[@]}个
|警告信息:${#array2[@]}个
|普通信息:${#array1[@]}个"
echo "从$yesterday 至 $today
服务器监控总结如下:
$message" | mail -s "192.168.3.128监控总结" 794705253@qq.com >>/tmp/mailx.log 2>&1
#################################################################
设置定时任务
脚本效果展示