Nagios飞信linux短信报警脚本配置

1.编写发送脚本
vi sendsms.sh

[php]
#!/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

[/php]


2.接收者电话号码
vi /usr/local/fetion/phonelist.txt
#hugwww
13724506486

3.修改飞信目录权限(否则运行Nagios的用户不能写入信息内容到/usr/local/fetion/msg.txt)

[php]
chown -R nagios.nagios /usr/local/fetion
chmod +x /usr/local/fetion/sendsms.sh
[/php]

4.配置Nagios
vi commands.cfg

[php]
###################################################################
#
# 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$."
}
[/php]

5.定义联系人
vi contacts.cfg

[php]
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
}
[/php]

测试故障时是否能够触发短信报警
/usr/local/fetion/sendsms.sh "nagios Host alert"

完成!

还没有评论,快来抢沙发!

发表评论

  • 😉
  • 😐
  • 😡
  • 😈
  • 🙂
  • 😯
  • 🙁
  • 🙄
  • 😛
  • 😳
  • 😮
  • emoji-mrgree
  • 😆
  • 💡
  • 😀
  • 👿
  • 😥
  • 😎
  • ➡
  • 😕
  • ❓
  • ❗
  • 69 queries in 0.437 seconds