Nagios 编译安装 pnp

pnp(pnp is not PerfParse) 可以实现监控资源的图形绘制,需要有以下工具的支持:

# yum install rrdtool rrdtool-devel rrdtool-perl

下载,编译安装 pnp4nagios:

# cd /usr/local/src
# wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.13.tar.gz/download#
# tar zxvf pnp4nagios-0.6.13
# cd pnp4nagos-0.6.13
# ./configure –with-rrdtool=/usr/bin/rrdtool –with-httpd-conf=/usr/local/apache2/conf

如果 apache 是通过包管理器安装的,则不需要指明 –with-httpd-conf;如果是编译安装的,需要指明安装的 conf 或者 conf.d 目录。

编译过程中报错:

checking for Perl Module Time::HiRes… no
configure: error: Perl Module Time::HiRes not available

安装相应的模块:

# yum install perl-Time-HiRes

继续 make:

# make all
# make install
# make install-webconf
# make install-config
# make install-init

打开 http://ip/nagios,点击小太阳,报错,缺少 php-gd,安装之:

# yum install php-gd

现在页面全绿了。

Your environment passed all requirements. Remove or rename the /usr/local/pnp4nagios/share/install.php file now.

将 install.php 文件移除即可。

pnp 目前主要支持 Synchronous Mode,Bulk Mode,Bulk Mode with NPCD。这里使用的是最后一种,其工作过程可以看这里

# vi /usr/local/nagios/etc/nagiso.cfg

process_performance_data=1

service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHO
STNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVI
CEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE
::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICEST
ATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file

host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNA
ME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$H
OSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATE
TYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file

增加新的命令:

# vi /usr/local/nagios/etc/commands.cfg

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$
}

检测并开启:

#  /usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg

0.6 版本的 pnp4naigos 书写 host 和 service 的跟 0.4 的不太一样,也就是打开绘制图表的链接不一样,最简单的方式可以直接在 objects/timeperiods.cfg 中追加:

define host{

name                            generic-host           

….

action_url /pnp4nagios/graph?host=$HOSTNAME$

     …..
}

define service{

name                            generic-service

active_checks_enabled           1

action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$

}

或者中规中矩的再开一个 host,service 段:

define host {
     name       host-pnp
     register   0
     action_url /pnp4nagios/graph?host=$HOSTNAME$
}

define service {
     name       srv-pnp
     register   0
     action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
}

定义结束之后,使用 use 来继承上面的 host-pnp 和 srv-pnp。

在完成基本功能之后,点击某些小太阳会出现如下的错误:

原因请点击这里。详细的文档可以看 这里