/ 中存储网

配置nagios系统发送邮件的方法

2014-07-13 20:28:25 来源:中存储网
nagios邮件监控可以配置sendmail,这里还是用mail命令完成。首先是编辑nagios.cfg,以前已经设置了,这里看看就行了
[root@localhost objects]# vi contacts.cfg  
define contact{  
contact_name user1  
alias Nagios Admin  
service_notification_period 24x7  
host_notification_period 24x7  
service_notification_options w,u,c,r  
host_notification_options d,r  
service_notification_commands notify-by-email  
host_notification_commands host-notify-by-email  
email xxxx@163.com  
pager 13800138000  
}  
define contactgroup{  
contactgroup_name admins  
alias Nagios Administrators  
members user1  
}  
notify-by-email和host-notify-by-email在command.cfg中定义了
#################
以下这个是在服务中单独设置
define service{  
use generic-service ; Name of service template to use  
host_name test_nrpe   
service_description apache  
is_volatile 0 #类似声音警告功能关闭  
check_period 24x7 #监控期限为24X7  
max_check_attempts 1 #最大重试次数  
normal_check_interval 1 #标准检测时间间隔 1分钟  
retry_check_interval 1 #重试时间间隔  
contact_groups admins #联系组  
notification_options w,u,c,r # w,u,c,r 发生这四种情况时,进行通告。  
notification_interval 960 # 通告间隔  
notification_period 24x7 #通告过期时间  
check_command check_http!100.0,20%!500.0,60%  
}  
在commands.cfg中用发送邮件命令用默认配置即可
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nnService: $SERVICEDESC$nHost: $HOSTALIAS$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}