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

运维 系统运维
Nagios飞信linux短信报警脚本配置:Nagios是一个监视系统,它可以监视系统运行状态和网络信息。Nagios能监视所指定的本地、远程主机以及服务、异常通知等。本文讲述的是Nagios飞信linux短信报警脚本配置。

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

  1.编写发送脚本

  1.   vi sendsms.sh  
  2.  
  3.   #!/bin/bash  
  4.  
  5.   fetionDir=/usr/local/fetion/  
  6.  
  7.   cd $fetionDir  
  8.  
  9.   DIR=`pwd`  
  10.  
  11.   user=13724506486 
  12.  
  13.   pwd=gjb88888 
  14.  
  15.   for phone in `cat $DIR/phonelist.txt`  
  16.  
  17.   do  
  18.  
  19.   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]‘  
  20.  
  21.   if (($? == 0 ));then  
  22.  
  23.   if [[ -f $DIR/msg.txt ]];then  
  24.  
  25.   echo "================" >> msg.txt  
  26.  
  27.   fi  
  28.  
  29.   phone=`echo "$phone" | sed ‘s/^[ \t]*//’ | sed ‘s/[ \t]*$//’`  
  30.  
  31.   echo "sms $phone $1" >> $DIR/msg.txt  
  32.  
  33.   echo "quit" >> $DIR/msg.txt  
  34.  
  35.   $fetionDir/fetion –mobile=$user –pwd=$pwd –to=$phone –msg-utf8="$1" 
  36.  
  37.   else  
  38.  
  39.   continue  
  40.  
  41.   fi  
  42.  
  43.   done  
  44.  

  2.接收者电话号码Nagios飞信

  1.   vi /usr/local/fetion/phonelist.txt  
  2.  
  3.   #hugwww  
  4.  
  5.   13724506486  
  6.  

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

  1.   chown -R nagios.nagios /usr/local/fetion  
  2.  
  3.   chmod +x /usr/local/fetion/sendsms.sh  
  4.  

  4.配置Nagios飞信

  1.   vi commands.cfg  
  2.  
  3.   ###################################################################  
  4.  
  5.   #  
  6.  
  7.   # notify-host-by-sendmsg/notify-service-by-sendmsg //定义发送飞信报警的命令  
  8.  
  9.   #  
  10.  
  11.   ###################################################################  
  12.  
  13.   define command {  
  14.  
  15.   command_name notify-host-by-fetion  
  16.  
  17.   command_line /usr/local/fetion/sendsms.sh "Host $HOSTSTATE$ alert for $HOSTNAME$($HOSTADDRESS$) on $TIME$."  
  18.  
  19.   }  
  20.  
  21.   define command {  
  22.  
  23.   command_name notify-service-by-fetion  
  24.  
  25.   command_line /usr/local/fetion/sendsms.sh ""$TIME$":$SERVICEDESC$($HOSTADDRESS$) is $SERVICESTATE$."  
  26.  
  27.   }  
  28.  

  5.Nagios飞信定义联系人

  1.   vi contacts.cfg  
  2.  
  3.   define contact {  
  4.  
  5.   contact_name admin  
  6.  
  7.   alias system admin  
  8.  
  9.   host_notification_period 24×7  
  10.  
  11.   service_notification_period 24×7  
  12.  
  13.   host_notification_options d,r  
  14.  
  15.   service_notification_options w,u,c,r  
  16.  
  17.   service_notification_commands notify-service-by-email,notify-service-by-fetion  
  18.  
  19.   host_notification_commands notify-host-by-email,notify-host-by-fetion  
  20.  
  21.   email hugwww@115.com  
  22.  
  23.   pager 13724506486  
  24.  
  25.   }  
  26.  

  6.测试Nagios飞信故障时是否能够触发短信报警

  1.   /usr/local/fetion/sendsms.sh "nagios Host alert"  
  2.  

  Nagios飞信linux短信报警脚本配置完成!

【编辑推荐】

Nagios不发报警短信问题的解决

用Nagios来监控网络服务器-nagios配置

使用Nagios实现网络监控

责任编辑:zhaolei 来源: gaojinbo
相关推荐

2011-03-24 10:08:42

Nagios飞信Linux

2011-03-23 13:32:14

Nagios飞信

2011-03-24 13:00:31

Nagios飞信

2010-05-31 09:06:12

Nagios飞信

2011-03-25 13:10:08

2011-03-24 09:15:54

Nagios飞信

2011-03-23 12:55:51

NagiosMSN飞信

2011-03-23 09:07:50

Nagios短信

2011-04-06 14:24:18

2011-03-22 16:31:27

Nagios

2011-03-24 08:56:23

escalationsNagios报警

2014-03-12 16:09:21

Zabbix短信报警

2009-12-23 19:13:40

Fedora Linu

2010-03-10 12:59:08

Linux安装飞信

2011-03-24 08:56:21

Nagios邮件

2011-03-25 14:56:43

Nagiosescalations

2011-03-21 15:44:52

escalationsNagios

2011-04-01 17:01:11

Zabbix短信

2011-03-23 14:43:09

2018-08-23 08:13:20

子弹短信微信老罗
点赞
收藏

51CTO技术栈公众号