nagios邮件报警设置:
当监控的设备出现异常的时候,报警是很有必要的。下面介绍下nagios的邮件报警机制。
cd /etc/nagios/objects
vim contact.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values fromgeneric-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagiosadmin@localhost ;<<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
这是nagios默认的机制,提前编写好的报警机制应用了 generic-contact模板,在email处填写好接受报警邮件的地址。contact_name为收件人是谁。
vim templates.cfg
define contact{
name generic-contact
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
register 0
}
上面是nagios定义好的模板,其中包括报警的时间,什么情况下报警,以及报警使用的命令都有介绍。
vim command.cfg
#'notify-host-by-email' command definition
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" | /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\nAdditionalInfo:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **"$CONTACTEMAIL$
}
上面是nagios定义好的报警信息应该怎么发送。我们可以在上面的情况下进行简单的修改即可。