您的位置:首页 > 运维架构 > Linux

linux上nagios3 短信+邮件报警

2010-10-14 17:53 525 查看
 

前提

 

   已经架设好nagios,并且配置成功,能用邮件报警

 

我架设的是3.2.3版本,3.2.3版本的配置文件跟以前版本的位置不太一样,需要配置的大部分是在object目录下的文件。

 

邮件报警其实很简单,启动本机的sendmail服务,在联系人里将自己的邮件添加上就可以

 

 

再来说说短信报警,短信报警我使用的是 飞信机器人 http://www.it-adv.net/ ,可以直接用命令行发短信

 

一。 下载飞信机器人 解压到/usr/local/sms/目录 ,并在此目录编写一脚本duanxin.sh

 

#!/bin/sh
LD_LIBRARY_PATH=/usr/local/sms /usr/local/sms/fetion --mobile=135xxxx2225 --pwd=xxxxxxxx --to=$1 --msg-gb=$2


此脚本的作用是将收短信人的手机号和短信作为参数,具体飞信机器人的命令参数,查看文档。

写好脚本后测试下,如果能受到短信,说明配置成功。

 

 

二。飞信机器人配置好后,开始配置nagios,配置文件位置在/usr/local/nagios/etc/object下

 

    首先配置command.cfg

 

    在mail报警代码下边新添加

 

   
#mobile
define command {
command_name      host-notify-by-sms
command_line      /usr/local/sms/duanxin.sh 15012345678  "Host $HOSTSTATE$ alert for $HOSTNAME$! on '$DATETIME$' " $CONTACTPAGER$
}
define command {
command_name     service-notify-by-sms
command_line     /usr/local/sms/duanxin.sh 15012345678 "$HOSTNAME$/$HOSTADDRESS$/$SERVICEDESC$/$SERVICESTATE$"
}


 

 

其中15012345678 是收短信的手机号吗, 第二个参数可以自己随便定制,  但是不要有空格存在,空格可以用/代替

这样command.cfg就配置好了

 

接着再配置 templates.cfg

找到 define contact {。。。} 在默认的“notify-service-by-email ” 和notify-host-by-email 前面 添加command里面配置的 command_name

 

define contact{
name                            generic-contact         ; The name of this contact template
service_notification_period     24x7                    ; service notifications can be sent anytime
host_notification_period        24x7                    ; host notifications can be sent anytime
service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands   service-notify-by-sms,notify-service-by-email   ; send service notifications via email
host_notification_commands      notify-host-by-sms,notify-host-by-email    ; send host notifications via email
register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}


 

这样就配置完成,重启nagios,有问题就可以收到短信了。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息