当前位置: > Linux服务器 > 监控工具 >

nagios报警设置

时间:2014-10-26 00:48来源:linux.it.net.cn 作者:it

本文介绍nagios报警设置,包括网页报警、邮件报警与飞信报警。

一、网页报警
1. 修改cgi.cfg 去掉下面几行注释
host_unreachable_sound=hostdown.wav
host_down_sound=hostdown.wav
service_critical_sound=critical.wav
service_warning_sound=warning.wav
service_unknown_sound=warning.wav
normal_sound=noproblem.wav
2. 在/usr/local/nagios/share/media/应该有相应的声音文件(这个默认没有的,需要自己添加)

二、邮件报警 (使用sendEmail 发送邮件)
# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
# tar –zxvf sendEmail-v1.55.tar.gz
# cd sendEmail-v1.56
# cp sendEmail /usr/local/bin
# chmod 0755 /usr/local/bin/sendEmail
#. /usr/local/bin/sendEmail –f –s mail.scomd.com –u “from nagios” –xu nagios –xp scomd –m nagios test
-f 表示发送者的邮箱
-t 表示接收者的邮箱
-s 表示SMTP服务器的域名或者ip
-u 表示邮件的主题
-xu 表示SMTP验证的用户名
-xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m 表示邮件的内容 
修改commands.cfg
 

复制代码代码如下:
define command{
 command_name notify-host-by-email
 command_line /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n” | /usr/local/bin/sendEmail -f -t -s mail.scomd.com -u “from nagios” -xu nagios -xp scomd ; /bin/mail -s “** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **” $CONTACTEMAIL$
 } 
# ‘notify-service-by-email’ command definition
define command{
 command_name notify-service-by-email
 command_line /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$” | /usr/local/bin/sendEmail -f -t -s mail.scomd.com -u “from nagios” -xu nagios -xp scomd
 }
 

发现一个小问题,用163测试,密码错误的竟然也可以发送。

三、飞信报警 (移动用户必须开通飞信业务)
#wget http://www.it-adv.net/fetion/downng/fetion20091117-linux.tar.gz
#tar –zxvf fetion20091117-linux.tar.gz
#cd fx
LD_LIBRARY_PATH=. ./fetion –mobile=13691515**** –pwd=mypwd –to=13691515****–msg-utf8=test
发送成功后可进行整合。
编辑commands.cfg,增加host-notify-by-fetion和service-notify-by-fetion命令的定义
 

复制代码代码如下:
define command {
 command_name host-notify-by-fetion
 command_line LD_LIBRARY_PATH=/usr/local/nagios/fx /usr/local/nagios/fx/fetion –mobile=13691515****–pwd=passwd –to=13691515**** –msg-utf8=”Host $HOSTSTATE$ alert for $HOSTNAME$! on ‘$LONGDATETIME$’” $CONTACTPAGER$

define command {
 command_name service-notify-by-fetion
 command_line LD_LIBRARY_PATH=/usr/local/nagios/fx /usr/local/nagios/fx/fetion –mobile=13691515**** –pwd= passwd –to=13691515**** –msg-utf8=”$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$” $CONTACTPAGER$

 

编辑contact.cfg,添加短信通知

复制代码代码如下:

define contact{
 contact_name nagiosadmin
 use generic-contact
 alias Nagios Admin
 email
 service_notification_commands notify-service-by-email,service-notify-by-fetion
 host_notification_commands notify-host-by-email,host-notify-by-fetion
 pager 13691515****
}
(责任编辑:IT)
------分隔线----------------------------