Nagios飞信linux短信报警脚本配置
Author:gaojinbo
Time:2010-8-3
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.接收者电话号码
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.定义联系人
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
}
测试故障时是否能够触发短信报警
/usr/local/fetion/sendsms.sh "nagios Host alert"
完成!
八月 6th, 2010 at 00:59
不错
八月 6th, 2010 at 14:32
这边的博客不是一般的专业….很久没有来逛你的博客了.. 看着你的更新真多啊…
八月 25th, 2010 at 15:30
我是个菜鸟 最近在linux搞nagios 看到您的文章
发现其中有msg.txt 这个文件 很是奇怪 不知道您用飞信那个版本的 我下的飞信没有这个文件
这个文件是干什么的呢
八月 25th, 2010 at 15:42
msg.txt 这个文件是在 1.编写发送脚本 里面生成的,用于记录报警信息。
飞信不包含这个文件。
八月 26th, 2010 at 10:36
我按照您的照打了一遍 提示语法错误13行
./sms-1.sh “哈哈”
./sms-1.sh: line 13: syntax error near unexpected token `then’
./sms-1.sh: line 13: ` if[[ -f $DIR/msg.txt ]];then’
我记得vb中如果if then 是以end if结尾吧 我不知道linux下是如何的
$DIR这个变量似乎前面没有定义啊 您说msg.txt是在下自动生成的,那应该在哪里呢。
我比较菜 望大大不惜赐教 谢谢了
八月 26th, 2010 at 10:41
我用的是rhes5.3版本
八月 26th, 2010 at 10:43
linux下shell里面的if语句,是使用fi结束
十二月 14th, 2010 at 16:08
[...] 参考:http://www.gaojinbo.com/nagios%E9%A3%9E%E4%BF%A1linux%E7%9F%AD%E4%BF%A1%E6%8A%A5%E8%AD%A6%E8%84%9A%E… [...]
六月 28th, 2011 at 16:14
按照上面修改了路径,电话号码及密码,不能成功。提示host_notification_period 24×7
service_notification_period 24×7 没有设置。
请告知怎么设置;?
另外,使用飞信发送短信发布出来。也不提示错误。
七月 10th, 2011 at 22:49
Gems form the internet…
[...]very few websites that happen to be detailed below, from our point of view are undoubtedly well worth checking out[...]……
八月 18th, 2011 at 11:03
Cool sites……
[...]we came across a cool site that you might enjoy. Take a look if you want[...]………