nagios4.1.1 + pnp4nagios 0.6.25 的集成 生成图表

参考 
1. http://www.aboutmonitoring.com/nagios4-check_mk-pnp4nagios-nagvis/ 
2. http://blog.csdn.net/TCH8502/article/details/22151525 
3. https://docs.pnp4nagios.org/pnp-0.6/verify_pnp_config 
4. http://blog.chinaunix.net/uid-261392-id-2138990.html 
5. 官方文档 https://docs.pnp4nagios.org/pnp-0.6/start (重要)

需要 rrtool 支持 
yum install rrdtool gd gd-devel php-gd

(1)安装 
#tar -zxvf php4nagios-*.tar.gz 
#cd php4nagios 
#./configure –with-nagios-user=nagios –with-nagios-group=nagios (如果单独编译安装的rrdtoool,则使用–with-rrdtool=/usr/local/rrdtool-1.2.xx/bin/rrdtool这样的形式) 
#make all 
#make install 
#make install-webconf 
#make install-config 
#make install-init 

#make fullinstall
(使用这条命令替换所有的make命令, make fullinstall) 
#service httpd restart

(2)配置
pnp4nagios有5种模式,配置方法分别如下
  • Synchronous Mode: (不讨论,参考官网https://docs.pnp4nagios.org/pnp-0.6/config)
  • Bulk Mode:(不讨论,参考官网https://docs.pnp4nagios.org/pnp-0.6/config)
  • Bulk Mode with NPCD:(我使用这种模式)
  • Bulk Mode with NPCD and npcdmod(不讨论,参考官网https://docs.pnp4nagios.org/pnp-0.6/config)
  • Gearman Mode(不讨论,参考官网https://docs.pnp4nagios.org/pnp-0.6/config)
Bulk Mode with NPCD模式的详细配置过程
  1. vim /usr/local/nagios/etc/nagios.cfg
    • 修改内容

      •  process_performance_data=0

         process_performance_data=1				
    • 增加内容
      #
      # service performance data
      #
      service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
      service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
      service_perfdata_file_mode=a
      service_perfdata_file_processing_interval=15
      service_perfdata_file_processing_command=process-service-perfdata-file
      
      #
      # host performance data starting with Nagios 3.0
      # 
      host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
      host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
      host_perfdata_file_mode=a
      host_perfdata_file_processing_interval=15
      host_perfdata_file_processing_command=process-host-perfdata-file
  2. vim /usr/local/nagios/etc/objects/commands.cfg

    增加command

    define command{
           command_name    process-service-perfdata-file
           command_line    /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
    }
    
    define command{
           command_name    process-host-perfdata-file
           command_line    /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
    }
  3. 启动npcd

    /usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg
  4. 重启nagios

    systemctl restart nagios
  5. 检查数据文件是否存在

    ls -la /usr/local/pnp4nagios/var/service-perfdata
  6. 下载verify_pnp_config

    wget http://verify.pnp4nagios.org/verify_pnp_config
  7. 检查pnp4nagios 在bulk+npcd模式下 是否配置正确

    perl /home/nagios/verify_pnp_config --mode bulk+npcd --config=/usr/local/nagios/etc/nagios.cfg --pnpcfg=/usr/local/pnp4nagios/etc
    
    
    输出内容:
    
    [root@nagios_server objects]# perl /home/nagios/verify_pnp_config --mode bulk+npcd --config=/usr/local/nagios/etc/nagios.cfg --pnpcfg=/usr/local/pnp4nagios/etc
    [INFO]  ========== Starting Environment Checks ============
    [INFO]  My version is: verify_pnp_config-0.6.25-R.40
    [INFO]  Start Options: /home/nagios/verify_pnp_config --mode bulk+npcd --config=/usr/local/nagios/etc/nagios.cfg --pnpcfg=/usr/local/pnp4nagios/etc
    [INFO]  Reading /usr/local/nagios/etc/nagios.cfg
    [OK  ]  Running product is 'nagios'
    [OK  ]  object_cache_file is defined
    [OK  ]  object_cache_file=/usr/local/nagios/var/objects.cache
    [INFO]  Reading /usr/local/nagios/var/objects.cache
    [OK  ]  resource_file is defined
    [OK  ]  resource_file=/usr/local/nagios/etc/resource.cfg
    [INFO]  Reading /usr/local/nagios/etc/resource.cfg
    [INFO]  Reading /usr/local/pnp4nagios/etc/process_perfdata.cfg
    [INFO]  Reading /usr/local/pnp4nagios/etc/pnp4nagios_release
    [OK  ]  Found PNP4Nagios version "0.6.25"
    [OK  ]  ./configure Options '--with-nagios-user=nagios' '--with-nagios-group=nagios'
    [OK  ]  Effective User is 'nagios'
    [OK  ]  User nagios exists with ID '1001'
    [OK  ]  Effective group is 'nagios'
    [OK  ]  Group nagios exists with ID '1001'
    [INFO]  ========== Checking Bulk Mode + NPCD Config  ============
    [OK  ]  process_performance_data is 1 compared with '/1/'
    [OK  ]  service_perfdata_file is defined
    [OK  ]  service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
    [OK  ]  service_perfdata_file_template is defined
    [OK  ]  service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
    [OK  ]  PERFDATA template looks good
    [OK  ]  service_perfdata_file_mode is defined
    [OK  ]  service_perfdata_file_mode=a
    [OK  ]  service_perfdata_file_processing_interval is defined
    [OK  ]  service_perfdata_file_processing_interval=15
    [OK  ]  service_perfdata_file_processing_command is defined
    [OK  ]  service_perfdata_file_processing_command=process-service-perfdata-file
    [OK  ]  host_perfdata_file is defined
    [OK  ]  host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
    [OK  ]  host_perfdata_file_template is defined
    [OK  ]  host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
    [OK  ]  PERFDATA template looks good
    [OK  ]  host_perfdata_file_mode is defined
    [OK  ]  host_perfdata_file_mode=a
    [OK  ]  host_perfdata_file_processing_interval is defined
    [OK  ]  host_perfdata_file_processing_interval=15
    [OK  ]  host_perfdata_file_processing_command is defined
    [OK  ]  host_perfdata_file_processing_command=process-host-perfdata-file
    [INFO]  Nagios config looks good so far
    [INFO]  ========== Checking config values ============
    [OK  ]  npcd daemon is running
    [OK  ]  /usr/local/pnp4nagios/etc/npcd.cfg is used by npcd and readable
    [INFO]  Reading /usr/local/pnp4nagios/etc/npcd.cfg
    [OK  ]  perfdata_spool_dir is defined
    [OK  ]  perfdata_spool_dir=/usr/local/pnp4nagios/var/spool
    [OK  ]  1 files found in /usr/local/pnp4nagios/var/spool
    service_perfdata_file_processing_command at /home/nagios/verify_pnp_config line 462.
    [OK  ]  Command process-service-perfdata-file is defined
    [OK  ]  '/bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$'
    [OK  ]  Command looks good
    host_perfdata_file_processing_command at /home/nagios/verify_pnp_config line 462.
    [OK  ]  Command process-host-perfdata-file is defined
    [OK  ]  '/bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$'
    [OK  ]  Command looks good
    [OK  ]  Script /usr/local/pnp4nagios/libexec/process_perfdata.pl is executable
    [INFO]  ========== Starting global checks ============
    [OK  ]  status_file is defined
    [OK  ]  status_file=/usr/local/nagios/var/status.dat
    [INFO]  host_query =
    [INFO]  service_query =
    [INFO]  Reading /usr/local/nagios/var/status.dat
    [INFO]  ==== Starting rrdtool checks ====
    [OK  ]  RRDTOOL is defined
    [OK  ]  RRDTOOL=/bin/rrdtool
    [OK  ]  /bin/rrdtool is executable
    [OK  ]  RRDtool 1.4.8  Copyright 1997-2013 by Tobias Oetiker <[email protected]>
    [OK  ]  USE_RRDs is defined
    [OK  ]  USE_RRDs=1
    [OK  ]  Perl RRDs modules are loadable
    [INFO]  ==== Starting directory checks ====
    [OK  ]  RRDPATH is defined
    [OK  ]  RRDPATH=/usr/local/pnp4nagios/var/perfdata
    [OK  ]  Perfdata directory '/usr/local/pnp4nagios/var/perfdata' exists
    [WARN]  2 hosts/services are not providing performance data
    [WARN]  'process_perf_data 1' is set for 3 hosts/services which are not providing performance data!
    [OK  ]  'process_perf_data 1' is set for 77 of your hosts/services
    [INFO]  ==== System sizing ====
    [OK  ]  76 hosts/service objects defined
    [INFO]  ==== Check statistics ====
    [WARN]  Warning: 2, Critical: 0
    [WARN]  Checks finished...
    

(3)集成到nagios的web页面中

  • 在/usr/local/nagios/etc/objects/templates.cfg 模板中加入
    define host{
            name   host-pnp
            register   0
            action_url    /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_
            }
  • 在被监控主机对应的cfg文件中,在define host use 一下模板中定于的 host-pnp 就会 在web上显示一个图表的标记
例如:
vim /usr/local/nagios/etc/objects/oa_server.cfg 

define host{
 use    windows-server,host-pnp; Inherit default values from a template, host-pnp 就是调用在templates.cfg 中定于的显示图像的功能
 ...
}



(4)配置apache

pnp4nagios4.10版本apache至此不需要做任何配置,直接就可以访问了,升级到0.6后发现必须rewrite了

安装pnp4nagios 时使用make install-webconf
这个会在/etc/httpd/ conf.d/中生成pnp4nagios.conf文件将其引入到/usr/local/apach2/conf/http.conf文件中

# 使用 pnp4nagios
Include /etc/httpd/conf.d/pnp4nagios.conf


访问http://server_ip/pnp4nagios  (所有红色的内容都要修正成绿色)
nagios4.1.1 + pnp4nagios 0.6.25 的集成 生成图表_第1张图片

你可能感兴趣的:(nagios4.1.1 + pnp4nagios 0.6.25 的集成 生成图表)