温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

2.3 nagios 配置邮件告警

发布时间:2020-08-07 09:12:36 来源:网络 阅读:281 作者:散宜生 栏目:移动开发

       目前nagios只能在浏览器上查看各个机器各个服务的状态,当某个机器宕掉或者某个服务宕掉时,我们是不知道的,因为我们不可能时时盯着服务看。这时,就需要用到告警系统了,让它自动化,当发现问题时及时通知我们。下面配置使用发邮件的方式来实现告警。

       在服务端操作!

       首先定义邮件接受者。

[root@localhost ~]# vim /etc/nagios/objects/contacts.cfg
define contact{
        contact_name                    test1
        use                             generic-contact
        alias                           email1
        email                           test1@163.com
}
define contact{
        contact_name                    test2
        use                             generic-contact
        alias                           email2
        email                           test2@163.com
}
define contactgroup{
        contactgroup_name               common
        alias                           common
        members                         test1,test2
}

        说明:contact.cfg 里面既可以定义user也可以定义group,先定义两个user test1和test2,然后把这两个user加入到common组里面。发邮件时就发给common组就可以了,这时test1@163.com和test2@163.com都会收到邮件。

        然后在需要告警的服务里加上contactgroup

[root@localhost ~]# vim /etc/nagios/conf.d/192.168.56.128.cfg

        针对check_load服务增加告警配置

define service{
   use            generic-service
   host_name      192.168.56.128
   service_description  check_load
   check_command    check_nrpe!check_load
   max_check_attempts   5
   normal_check_interval   1
   contact_groups   common
   notifications_enabled  1
   notification_period   24x7
   notification_options  w,u,c,r
}

       说明:notifications_enabled 1 表示是否开启提醒功能。1 为开启,0 为禁用。一般,这个选项会在主配置文件(nagios.cfg)中定义,效果相同。notification_period 24x7 表示发送提醒的时间段。如果不在定义的时间段内,无论什么问题都不会发送提醒。notification_options:w,u,c,r 表示service的状态。w 为 warning,u 为unknown,c 为critical,r 为recovery。类似的还有一个host对应的状态:d,u,r,f,n。 d 状态表示DOWN,u 为UNREACHABLE,r 状态恢复为 OK,f 为flapping,n 为不发送提醒。需要加入到 host 的定义配置里生效。

      编辑完配置文件后,重启nagios服务

[root@localhost ~]# service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI