Nagios飞信linux短信报警脚本配置
1.编写发送脚本
-
vi sendsms.sh
-
-
#!/bin/bash
-
-
fetionDir=/usr/local/fetion/
-
-
cd $fetionDir
-
-
DIR=`pwd`
-
-
user=13724506486
-
-
pwd=gjb88888
-
-
for phone in `cat $DIR/phonelist.txt`
-
-
do
-
-
echo "$phone" | sed ‘/^[ \t]*$/d’ | sed ‘s/^[ \t]*//’ | sed ‘s/[ \t]*$//’ | grep ‘^1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]‘
-
-
if (($? == 0 ));then
-
-
if [[ -f $DIR/msg.txt ]];then
-
-
echo "================" >> msg.txt
-
-
fi
-
-
phone=`echo "$phone" | sed ‘s/^[ \t]*//’ | sed ‘s/[ \t]*$//’`
-
-
echo "sms $phone $1" >> $DIR/msg.txt
-
-
echo "quit" >> $DIR/msg.txt
-
-
$fetionDir/fetion –mobile=$user –pwd=$pwd –to=$phone –msg-utf8="$1"
-
-
else
-
-
continue
-
-
fi
-
-
done
-
2.接收者电话号码Nagios飞信
-
vi /usr/local/fetion/phonelist.txt
-
-
#hugwww
-
-
13724506486
-
3.修改飞信目录权限(否则运行Nagios的用户不能写入信息内容到/usr/local/fetion/msg.txt)
-
chown -R nagios.nagios /usr/local/fetion
-
-
chmod +x /usr/local/fetion/sendsms.sh
-
4.配置Nagios飞信
-
vi commands.cfg
-
-
###################################################################
-
-
#
-
-
# notify-host-by-sendmsg/notify-service-by-sendmsg //定义发送飞信报警的命令
-
-
#
-
-
###################################################################
-
-
define command {
-
-
command_name notify-host-by-fetion
-
-
command_line /usr/local/fetion/sendsms.sh "Host $HOSTSTATE$ alert for $HOSTNAME$($HOSTADDRESS$) on $TIME$."
-
-
}
-
-
define command {
-
-
command_name notify-service-by-fetion
-
-
command_line /usr/local/fetion/sendsms.sh ""$TIME$":$SERVICEDESC$($HOSTADDRESS$) is $SERVICESTATE$."
-
-
}
-
5.Nagios飞信定义联系人
-
vi contacts.cfg
-
-
define contact {
-
-
contact_name admin
-
-
alias system admin
-
-
host_notification_period 24×7
-
-
service_notification_period 24×7
-
-
host_notification_options d,r
-
-
service_notification_options w,u,c,r
-
-
service_notification_commands notify-service-by-email,notify-service-by-fetion
-
-
host_notification_commands notify-host-by-email,notify-host-by-fetion
-
-
email hugwww@115.com
-
-
pager 13724506486
-
-
}
-
6.测试Nagios飞信故障时是否能够触发短信报警
-
/usr/local/fetion/sendsms.sh "nagios Host alert"
-
Nagios飞信linux短信报警脚本配置完成!
(责任编辑:IT) |