解决nagios不自动发警告邮件一例

         139邮箱挺好用的,之前用shell做监控发信到@139.com,139还真的把把短信提示送到了手机上,网上说nagios是一款强大的监控工具,于是顺利把nagios装在ubuntu上,除了Email地址没有做其它配置,浏览器也能顺利打开http://xx.xx.xx.xx/nagios 监控页面,于是把apache服务down一下,过了一会,nagios监控页面“Current Status”-“services”项显示HTTP服务CRITICAL,却没有收到告警短信,查看邮箱也没有,查看一下原来是HTTP项的Notifications处于Disabled状态,于是直接在web接口启用Http的Notifications。

       sudo /etc/init.d/nagios restart ,界面已经显示Notifications “Enable”,接着stop apache ,等了一阵,web界面显示http critical ,但仍没有发出邮件。于是mail –s “test” [email protected] <  test.conf 测试发信没有问题,网上说是mail路径设置问题,检查nagios的发信命令,/usr/bin/mail路径并没有错误。

      查看/usr/local/nagios/objects/localhost.cfg ,发现service的设置并没有启用Notifications:

define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }

# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.

define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           0
        }

     奇怪了,配置文件里面并没有启用,怎么web界面显示了Enable了呢。把这两项都改为“1”,然后restart nagios。仍然发不出信件。

   到处看看,发现nagios的/etc目录下主配置文件nagios.cfg有关预缓存的配置,说是为了nagios快速启动而设置的

   precached_object_file=/usr/local/nagios/var/objects.precache

  果然,objects.precache包含了http service项:注意下面的notifications_enabled项仍然被设置为0

define service {
        host_name       localhost
        service_description     HTTP
        check_period    24x7
        check_command   check_http
        contact_groups  admins
        notification_period     24x7
        initial_state   o
        check_interval  5.000000
        retry_interval  1.000000
        max_check_attempts      4
        is_volatile     0
        parallelize_check       1
        active_checks_enabled   1
        passive_checks_enabled  1
        obsess_over_service     1
        event_handler_enabled   1
        low_flap_threshold      0.000000
        high_flap_threshold     0.000000
        flap_detection_enabled  1
        flap_detection_options  o,w,u,c
        freshness_threshold     0
        check_freshness 0
        notification_options    u,w,c,r
        notifications_enabled   0
        notification_interval   60.000000
        first_notification_delay        0.000000
        stalking_options        n
        process_perf_data       1
        failure_prediction_enabled      1
        retain_status_information       1
        retain_nonstatus_information    1
        }

  很显然,修改了localhost.cfg之后object.precache并没有及时更新。在nagios.cfg里把 “precached_object_file”注释掉,然后restart nagios .:)Everything goes well .能收到critical,recovery等邮件了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章