lenf 发表于 2013-3-13 09:39:54

Nagios(七)——Nagios 邮件,短信告警

Nagios 除了监控功能很强大之外,它的报警功能也很不错。从运维的角度来讲,报警一般就是邮件和短信报警这两种方式,这次实验实现的是Nagios 的邮件报警功能。 1、安装sendmail 组件 这里要确保sendmail 相关组件的完整安装,# yum install sendmail* mailx安装完成后重启sendmail 服务# service sendmail restartShutting down sendmail:                                 Starting sendmail:                                        Starting sm-client:                                        测试sendmail 发信情况# /bin/mail -s "`date +%Y-%m-%d` Server SMS Test" 159158*****@163.comhelloadmin.EOT 2、邮件报警的配置一般而言,如果在整个系统中只有一个管理员,那么只需要在contact.cfg文件中,添加一下管理员的邮箱即可。但如果监控的内容中服务器有单独的管理员,那就需要定义多个contact(联系人),然后再通过contactgroup(联系组)对各个contact 进行分组。(1)    修改contact.cfg# vim /usr/local/nagios/etc/objects/contacts.cfg                define contact{      contact_name                  nagios      use                            generic-contact      alias                           Nagios      email                        159158*****@163.com,159158*****@139.com          // 改为自己的邮箱地址即可      } define contactgroup{      contactgroup_name       admins      alias                   Nagios Administrators      members               nagios      } (2)    设置报警方式# vim /usr/local/nagios/etc/objects/templates.cfgdefine contact{      name                     generic-contact             ; The name of this contact template      service_notification_period   24x7                      ; service notifications can be sent anytime      host_notification_period      24x7                     ; host notifications can be sent anytime      service_notification_options    w,u,c,r,f,s                  ; send notifications for all service states, flapping events, and scheduled downtime events      host_notification_options       d,u,r,f,s                   ; send notifications for all host states, flapping events, and scheduled downtime events      service_notification_commands   notify-service-by-email   ; send service notifications via email      host_notification_commands      notify-host-by-email       ; send host notifications via email      register                        0                      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!      } (3)    修改commands.cfg# vim /usr/local/nagios/etc/objects/commands.cfg# 'notify-host-by-email' command definitiondefine 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 definitiondefine 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$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$      } 看到这里已经默认配置好,我们不用修改直接调用就行了。 (4)    通过-v参数检查配置无误之后,重启nagios# service nagios restartRunning configuration check...done.Stopping nagios: .done.Starting nagios: done. (5)    邮箱设置这里以139邮箱为例,设置收信点击左上角“设置”可以看到这个版块


点击“手机通知”,打开邮箱到达通知,设置接收时间段,设置完保存。

返回到这个版块,点击“白名单设置”,将服务器域名设置进白名单

(6)    测试收信情况可以随便关闭客户机上的一个服务做测试

设置邮件到达提醒后,还可以收到告警短信,效果如下:(需要设置成长短信的形式)

PS:139邮箱的短信报警免费是好,但是有时延,这里提供另外一种方式报警——微信告警
可以QQ邮箱将域名设置进白名单,然后微信设置QQ邮箱推送即可(由于设置简单,这里就不演示了)效果如下:


0 发表于 2013-3-17 18:16:44

我抢、我抢、我抢沙发~

jxwjq 发表于 2013-5-16 08:30:05

恋爱就是无数个饭局,结婚就是一个饭局。

ls0398 发表于 2013-5-17 13:14:11

解释就系掩饰,掩饰等于无出色,无出色不如回家休息!!!

wangwengwu 发表于 2013-5-18 16:47:20

睡眠是一门艺术——谁也无法阻挡我追求艺术的脚步!

24cun_cn 发表于 2013-5-19 21:55:44

只有假货是真的,别的都是假的!

52037317 发表于 2013-5-21 00:41:27

人生自古谁无死,啊个拉屎不用纸!
页: [1]
查看完整版本: Nagios(七)——Nagios 邮件,短信告警