#!/bin/bash
#Author by fengzhanhai
#It used by mon web service and net and host living
#It was created on 2012-8-9
#webdate=`date -d "today" +"%Y-%m-%d %H:%M:%S"`
webdate=`date -d "today" +"%H:%M:%S"`
#记录系统故障发生时间点
#echo $webdate
webinfo="The service's 80 port error!"
Hostinfo="The mon has been checked your PCserver power off or Disaster"
#记录检查到的故障现象 此处由于笔者改了好几版 暂时没有用到
myphone=youphone
mypwd=yourpassword
#飞信号及口令
sendsmsweb() {
cd /root/mon
for iphone in `cat smspphone`
do
#echo $iphone
LD_LIBRARY_PATH=. ./fetion --mobile=$myphone --pwd=$mypwd --to=$iphone --msg-utf8="$webinfo $webdate" >>smsp.log
done
}
#发送web类故障告警短信模块 此处笔者在调用时直接套用没有引用之
sendsmshost(){
cd /root/mon
for iphone in `cat smspphone`
do
LD_LIBRARY_PATH=. ./fetion --mobile=$myphone --pwd=$mypwd --to=$iphone --msg-utf8="$webinfo $webdate" >>smsp.log
done
}
#发送主机类故障短信告警模块 此处笔者在调用时直接套用没有引用之
CheckHost() {
cd /root/mon
for webip in `cat smspip|awk -F : '{print $1}'`
#此处smspip是一个文本文件其格式如下192.168.163.110:80
#使用awk命令去其域的第一部份即ip部分
#当然你也可以直接在smspip文本文件内只存ip那么语句改成
# 这样for webip in `cat smspip`既可
do
ping -c 1 $webip > /dev/null 2>&1
if [ $? != 0 ] && ! [ -f smsp.lock ]
#告警完毕后上锁以防多次告警影响工程师的情绪 呵呵
then
# sendsmshost
cd /root/mon
for iphone in `cat smspphone`
do
#touch ./smsp.lock
#echo $iphone
LD_LIBRARY_PATH=. ./fetion --mobile=$myphone --pwd=$mypwd --to=$iphone --msg-utf8="The $webip can not connect at $webdate" >>smsp.log
done
touch ./smsp.lock
fi
done
}
##以上为主机故障检测模块
CheckWeb1() {
status=`telnet 192.168.202.45 80 < /dev/null 2>/dev/null | grep '\^' | wc -l`
#此处由于只有两台web服务器需要检测所以没有模块化 需要的同学可以#自行编写一下下啦
if [ $status != 1 ] && ! [ -f smsp1.lock ]
then
#sendsmsweb
cd /root/mon
for iphone in `cat smspphone`
do
#echo $iphone
LD_LIBRARY_PATH=. ./fetion --mobile=$myphone --pwd=$mypwd --to=$iphone --msg-utf8="The smsp.allook.cn Web Service has been down at $webdate" >>smsp.log
done
touch ./smsp1.lock
fi
}
CheckWeb2() {
status=`telnet 192.168.202.46 9001 < /dev/null 2>/dev/null | grep '\^' | wc -l`
#此处由于只有两台web服务器需要检测所以没有模块化 需要的同学可以自#行编写一下下啦
if [ $status != 1 ] && ! [ -f smsp2.lock ]
then
#sendsmsweb
cd /root/mon
for iphone in `cat smspphone`
do
#echo $iphone
LD_LIBRARY_PATH=. ./fetion --mobile=$myphone --pwd=$mypwd --to=$iphone --msg-utf8="The sms gw 192.168.202.46 has been down at $webdate" >>smsp.log
done
touch ./smsp2.lock
fi
}
##Running the monapp
CheckHost
CheckWeb1
CheckWeb2