|
NAGIOS邮件报警
NAGIOS的报警功能相当的强悍,除了丰富的监控功能外,我个人比较特别喜欢他的报警功能,对于报警而言,常用的无非就是邮件和短信报警两种方式,本文中主要是写的NAGIOS的邮件报警的功能,下面的文章里面再介绍NAGIOS的短信报警功能的配置与实现。
1 安装sendmail组件
首先要确保sendmail相关组件的完整安装,我们可以使用如下的命令来完成sendmail的安装:
# yum install -y sendmail*
然后重新启动sendmail服务:
# service sendmail restart
然后发送测试邮件,验证sendmail的可用性:
# echo "Hello World" | mail abc@abc.com
2 邮件报警的配置
我们只需要编辑/usr/local/nagios/etc/object下的contact.cfg文件,在email后添加管理员的邮箱即可。一般而言,如果监控项目的分工不是太细的话~~就是管理员可以负责所有的监控、并对其进行处理的话,可以直接将一个或者多个管理员的邮件地址写上,使用空格或者逗号隔开。
但是如果监控的内容中服务器有单独的管理员,网络有单独的管理员的话,我们就可以定义多个contact(联系人),然后再用contactgroup(联系组)对各contact进行分组。
例如管理网络的有两人,管理服务器的有两个人,我们就可以定义两个contactgroup,然后定义四个管理员的contact,如下例是当前我正在使用的contact.cfg,服务器管理员有两名,网络管理员有两名:
2.1 contact.cfg的配置
#######################################################################################
#######################################################################################
############## NETWORK ADMINISTRATOR MEMBERS
#######################################################################################
#######################################################################################
define contact{
contact_name zhang1
use generic-contact
alias zhang1
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 zhang1@text.com
}
define contact{
contact_name zhang2
use generic-contact
alias zhang2
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 zhang2@test.com
}
#######################################################################################
#######################################################################################
############## 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 li1@test.com
}
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 li2@test.com
}
#######################################################################################
#######################################################################################
############## NETWORK ADMINISTRATOR GROUP
#######################################################################################
#######################################################################################
define contactgroup{
contactgroup_name network
alias network
members zhang1,zhang2
}
#######################################################################################
#######################################################################################
############## SYSTEM ADMINISTRATOR GROUP
#######################################################################################
#######################################################################################
define contactgroup{
contactgroup_name system
alias system
members li1,li2
}
2.2 主机及监控内容的配置
相应的联系人和联系给已经创建好了,接下来的就是在被监控的服务中添加故障的联系人了,以下面定义的监控主机和服务为例
define host{
use linux-server
host_name SKLuDB1
alias skludb1
address 192.168.19.142
}
define service{
use generic-service ; Name of service template to use
host_name SKLuDB1
service_description PING
check_command check_ping!100.0,20%!500.0,60%
contact_groups network
}
define service{
use generic-service
host_name SKLuDB1
service_description Uptime
check_command check_nt!UPTIME
contact_groups system
}
如上面配置所示,当监控主机的ping出现问题的时候,nagios就会查看contact.cfg中定义的联系人组network中的联系人的信息,然后读取各联系人的邮件地址,这样的话,网络中出现故障时就可以直接给zhang1和zhang2二人发邮件了;同理,当服务器出现问题的时候就会给system组的相关人员发送邮件了
|
|