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

八月 3rd, 2010 Posted in WEB架构 | 阅读次数: 779 次

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"

 

完成!

相关日志:

Tags: ,

11 Responses to “Nagios飞信linux短信报警脚本配置”

  1. very Says:

    不错


  2. 虫虫博客 Says:

    这边的博客不是一般的专业….很久没有来逛你的博客了.. 看着你的更新真多啊…


  3. 罗霄 Says:

    我是个菜鸟 最近在linux搞nagios 看到您的文章

    发现其中有msg.txt 这个文件 很是奇怪 不知道您用飞信那个版本的 我下的飞信没有这个文件

    这个文件是干什么的呢


  4. gaojinbo Says:

    msg.txt 这个文件是在 1.编写发送脚本 里面生成的,用于记录报警信息。

    飞信不包含这个文件。


  5. 罗霄 Says:

    我按照您的照打了一遍 提示语法错误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是在下自动生成的,那应该在哪里呢。

    我比较菜 望大大不惜赐教 谢谢了


  6. 罗霄 Says:

    我用的是rhes5.3版本


  7. gaojinbo Says:

    linux下shell里面的if语句,是使用fi结束


  8. nagios+139邮件短信通知报警文档v1.1 | [高进波]博客 - 零起点一步配置你的linux服务器 - UNIX LINUX 服务器快速配置 - LINUX服务器配置文档 -WEB架构 Says:

    [...] 参考: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… [...]


  9. mutitty Says:

    按照上面修改了路径,电话号码及密码,不能成功。提示host_notification_period 24×7
    service_notification_period 24×7 没有设置。
    请告知怎么设置;?

    另外,使用飞信发送短信发布出来。也不提示错误。


  10. mobile apps Says:

    Gems form the internet…

    [...]very few websites that happen to be detailed below, from our point of view are undoubtedly well worth checking out[...]……


  11. hotel in zurich Says:

    Cool sites……

    [...]we came across a cool site that you might enjoy. Take a look if you want[...]………


留下您的脚印