1. 确保nagios服务能成功启动和访问。并且能够监控客户端。
2.
1)安装sendmail或postfix等邮件服务(这里以sendmail为例)。
1 安装sendmail组件
首先要确保sendmail相关组件的完整安装,我们可以使用如下的命令来完成sendmail的安装:
# yum install -y sendmail*
然后重新启动sendmail服务:
# service sendmail restart
然后发送测试邮件,验证sendmail的可用性:
# echo "Hello World" | mail xxxxxxxx@139.com
最好是申请两个邮箱做测试。意为两个管理人员。
2) 配置。警报配置只需要在服务器端配置即可。需要编辑的文件有:
1./usr/local/nagios/etc/object下的contact.cfg
2./usr/local/nagios/etc/object下的commands.cfg (经测试,这个文件不用编辑,还没研究透)
如果你不放心,可以加多以下这些代码。其他不用改动。
#define command{
# command_name notify-by-email
# command_line /usr/bin/printf "%b" "***** Nagios 2.9 *****\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/sendmail -f nagios@test.com -t $CONTACTEMAIL$
-s mail.test.com -u "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu nagios -xp p#3isoda
# }
注释掉了还是能成功的,有待研究 ~~ 网上说法太不统一了
2) 成功案例配置:
[root@bogon objects]# cat contacts.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
#######################################################################################
#######################################################################################
############## SYSTEM ADMINISTRATOR MEMBERS
#######################################################################################
#######################################################################################
define contact{
contact_name li1
use generic-contact
alias li1
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,f,s
host_notification_options d,u,r,f,s
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email 15218402325@139.com
}
define contact{
contact_name li2
use generic-contact
alias li2
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,f,s
host_notification_options d,u,r,f,s
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email 15218402325@163.com
}
#######################################################################################
#######################################################################################
############## SYSTEM ADMINISTRATOR GROUP
#######################################################################################
#######################################################################################
define contactgroup{
contactgroup_name system
alias system
members li1,li2
}
[root@bogon objects]#
以上意思是将两个管理员 li1、li2放到一个组system里。有意思了,可以按组来