#!/usr/bin/bash
#site:www.jb200.com
#
if [ $succ_ping -gt $((ping_count-1)) ];then
if [ -f ./alarm_file/alarm_$host ];then
rm -rf ./alarm_file/alarm_$host
#发送故障消除短信通知--调用insert_table
messages="$host
服务器通迅恢复正常`date "+%Y%m%d %H:%M:%S"`"
echo "$messages" >>./log/ping_err_recover.log
insert_table
else
echo "本次检测结果---->$host服务器ping检测正常"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器ping检测正常,ping次数$ping_count,接收$succ_ping" >>./log/ping_log
fi
else
echo "本次检测结果---->$host服务器有丢包现象,丢包率为:$loss_ping"
messages="`date "+%Y%m%d %H:%M:%S"`--->$host服务器有丢包现象,丢包率为:$loss_ping"
#对警次数进行处理,超过2次将不告警
#格式host a(告警次数)
#已经出现告警的次数加1
echo "告警服务器为$host"
if [ -f ./alarm_file/alarm_$host ];then
#取出当前的告警次数并加1
a=`
linuxjishu/13830.html target=_blank class=infotextkey>awk '{print$2}' ./alarm_file/alarm_$host`
b=$(($a+1))
echo "$host $b" >./alarm_file/alarm_$host
alarm_count=`awk '{print$2}' ./alarm_file/alarm_$host`
if [ $alarm_count -gt $sms_count ];then
echo "超过2次不发送短信"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器有丢包现象,接收$succ_ping,丢包率为:$loss_ping,超过二次不发送。" >>./log/ping_err_log
else
#未超过2次调用insert_table函数发送短信
echo "未超过2次"
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器有丢包现象,接收$succ_ping,丢包率为:$loss_ping">>./log/ping_err_log
insert_table
fi
else
#第一次告警
echo "第一次告警"
echo "$host 1" >./alarm_file/alarm_$host
insert_table
echo "`date "+%Y%m%d %H:%M:%S"`--->$host服务器有丢包现象,接收$succ_ping,丢包率为:$loss_ping" >>./log/ping_err_log
fi
fi
done