上一篇中nagios基本框架可以显示,现在需要再配置一下监控端。
 
nagios调用我的理解就是:
 
host.cfg/service.cfg--->引用模板templete.cfg--->调用command.cfg的命令---->依据worktime及报警设置----->向contact_host.cfg的人发送邮件。
 
报警的条件设置可以在templete.cfg中统一定制,也可单独写入每项服务中去,那样就不需要写 use 个条件设置了。
 
一、nagios 主配置文件修改

PATH=/usr/local/nagios/etc/nagios.cfg
定义配置文件名称及路径
cfg_file=/usr/local/nagios/etc/objects/commands.cfg \\命令定义
#cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/contact_group.cfg \\联系人分组
cfg_file=/usr/local/nagios/etc/objects/contact_host.cfg \\联系人定义
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg \\监控时间定义
cfg_file=/usr/local/nagios/etc/objects/templates.cfg \\监控模板文件
cfg_file=/usr/local/nagios/etc/objects/host.cfg \\被监控端设置
cfg_file=/usr/local/nagios/etc/objects/service.cfg \\被监控服务定义
二、各个配置文件配置
(只摘出必要部分)
command.cfg配置
\\定义nrpe命令
# 'check_nrpe' command definition
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -c $ARG1$
        }

 
contact_host.cfg 配置
define contact{
        contact_name                    nagiosadmin            
        use                             generic-contact     \\使用template.cfg中的对应名字为模板
       alias                           Nagios Admin       
       email                           [email protected]   
        }

 
contact_group.cfg配置
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin
        }

hosts.cfg
检查客户端是否alive
define host{
        use                     linux-server                                                        
        host_name               192.168.0.20
        alias                   192.168.0.20
        address                 192.168.0.20
        }
 
service.cfg
检查服务的状态
define service{
        use                             local-service         
        host_name                       localhost
        service_description             Root Partition
        check_command                   check_local_disk!20%!10%!/
        }
define service{
        use                             generic-service  \\使用的模板
        host_name                       192.168.0.20  \\监控页面中host 列显示的名字
        service_description             web  \\监控也没中service列显示的名字
        check_command                   check_nrpe!check_http_1  \\详细见被监控端配置
        }
define service{
        use                             generic-service
        host_name                       192.168.0.20
        service_description             mysql
        check_command                   check_nrpe!check_mysql_1   \\详细见被监控端配置
        }
 
timeperiod.cfg配置
 
define timeperiod{
        timeperiod_name 24x7
        alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
        monday          00:00-24:00
        tuesday         00:00-24:00
        wednesday       00:00-24:00
        thursday        00:00-24:00
        friday          00:00-24:00
        saturday        00:00-24:00
        }
 
template.cfg配置
 
(仅以服务调用的模板为例,几乎未做修改)
define service{
        name                            generic-service        
        active_checks_enabled           1                      
        passive_checks_enabled          1                      
        parallelize_check               1                       
        obsess_over_service             1                      
        check_freshness                 0                     
        notifications_enabled           1                    
        event_handler_enabled           1                      
        flap_detection_enabled          1                      
        failure_prediction_enabled      1                      
        process_perf_data               1                     
        retain_status_information       1                      
        retain_nonstatus_information    1                      
        is_volatile                     0                      
        check_period                    24x7                   
        max_check_attempts              3                       
        normal_check_interval           1                      
        retry_check_interval            2                       
        contact_groups                  admins  \\联系组                
        notification_options            w,u,c,r      \\报警选项           
        notification_interval           60      \\单位:分            
        notification_period             24x7                   
         register                        0                      
        }