Nagio增加pnp4nagios图表显示

前面的文章介绍了如何安装Nagios,但是只安装官方的监控程序和插件看历史记录和一段时间发送的情况不是很清楚,所以我们还需要增加一个图表显示功能。

安装必要环境

首先用yum把一些必要的环境安装好:

yum -y install pango* perl-ExtUtils-MakeMaker perl-Time-HiRes cairo-devel ?librrds-perl

Nagio增加pnp4nagios图表显示

安装rrdtool

接下来下载rrdtool软件,这是一个绘图引擎,以后图表显示需要靠它。

wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.5.4.tar.gz

下完以后进行安装:

tar zxvf rrdtool-1.5.4.tar.gz

cd rrdtool-1.5.4

./configure --prefix=/usr/local/rrdtool

make && make install

Nagio增加pnp4nagios图表显示

pnp4nagios版本介绍

接下来就可以安装pnp4nagios了。在安装以前建议大家可以先去官方网站的一些说明文件看一下,pnp-0.6和pnp-0.4已经完全不同了,我发现很多网上的资料还是按照pnp-0.4来介绍的.

http://docs.pnp4nagios.org/pnp-0.6/upgrade

下面就是0.4和0.6版本官方的安装说明的介绍:

Summary of a PNP 0.4.14 installation

./configure
...
*** Configuration summary for pnp 0.4.14 05-02-2009 ***

General Options:
------------------------- -------------------
Nagios user/group: nagios nagios
Install directory: /usr/local/nagios
HTML Dir: /usr/local/nagios/share/pnp
Config Dir: /usr/local/nagios/etc/pnp
Location of rrdtool binary: /usr/bin/rrdtool Version 1.3.1
RRDs Perl Modules: FOUND (Version 1.3001)
RRD Files stored in: /usr/local/nagios/share/perfdata
process_perfdata.pl Logfile: /usr/local/nagios/var/perfdata.log
Perfdata files (NPCD) stored in: /usr/local/nagios/var/spool/perfdata/
Summary of a PNP 0.6.0 installation

./configure
...
*** Configuration summary for pnp4nagios-0.6.25 03-01-2015 ***

General Options:
------------------------- -------------------
Nagios user/group: nagios nagios
Install directory: /usr/local/pnp4nagios
HTML Dir: /usr/local/pnp4nagios/share
Config Dir: /usr/local/pnp4nagios/etc
Location of rrdtool binary: /usr/local/rrdtool/bin/rrdtool Version 1.5.4
RRDs Perl Modules: FOUND (Version 1.5001)
RRDs Perl search path: /usr/local/rrdtool/lib/perl/5.10.1/i386-linux-thread-multi
RRD Files stored in: /usr/local/pnp4nagios/var/perfdata
process_perfdata.pl Logfile: /usr/local/pnp4nagios/var/perfdata.log
Perfdata files (NPCD) stored in: /usr/local/pnp4nagios/var/spool

Web Interface Options:
------------------------- -------------------
HTML URL: http://localhost/pnp4nagios
Apache Config File: /etc/httpd/conf.d/pnp4nagios.conf
Review the options above for accuracy. If they look okay,
type 'make all' to compile.

pnp4nagios配置及安装

下面是专门针对0.6版本的配置,大家可以到网站上去看官方的配置。其实最主要的就是0.6的Bulk Mode输出了。

http://docs.pnp4nagios.org/pnp-0.6/config

下面就是安装的命令。先下载解压。

wget http://jaist.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.25.tar.gz
tar zxvf pnp4nagios-0.6.25.tar.gz
cd pnp4nagios-0.6.25

Nagio增加pnp4nagios图表显示

然后对pnp4nagios环境配置

./configure --prefix=/usr/local/pnp4nagios ?--with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perl_lib_path=/usr/local/rrdtool/lib/perl/5.10.1/i386-linux-thread-multi

Nagio增加pnp4nagios图表显示

最后安装。

make all
make fullinstall
make install-webconf
make install-config
make install-init

安装完毕后还需要把模板文件复制进去。

cd /usr/local/pnp4nagios/etc
mv misccommands.cfg-sample misccommands.cfg
mv nagios.cfg-sample nagios.cfg
mv rra.cfg-sample rra.cfg
mv pages/web_traffic.cfg-sample pages/web_traffic.cfg
mv check_commands/check_all_local_disks.cfg-sample check_commands/check_all_local_disks.cfg
mv check_commands/check_nrpe.cfg-sample check_commands/check_nrpe.cfg
mv check_commands/check_nwstat.cfg-sample check_commands/check_nwstat.cfg

接下来修改Apache的配置文件,增加以下内容

Alias /pnp4nagios "/usr/local/pnp4nagios/share"

<Directory "/usr/local/pnp4nagios/share">
AllowOverride None
Order allow,deny
Allow from all
#
# Use the same value as defined in nagios.conf
#
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
Options symLinksIfOwnerMatch
# Installation directory
RewriteBase /pnp4nagios/
# Protect application and system files from being viewed
RewriteRule "^(?:application|modules|system)/" - [F]
# Allow any files or directories that exist to be displayed directly
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteCond "%{REQUEST_FILENAME}" !-d
# Rewrite all other URLs to index.php/URL
RewriteRule "^.*$" "index.php/$0" [PT]
</IfModule>
</Directory>

接下来就是设置权限

chown -R nagios:nagios /usr/local/pnp4nagios

修改nagios配置文件

修改pnp4nagios的日志配置

一个是日志位置,一个是日志级别。如果认为不需要可以忽略。

vi /usr/local/pnp4nagios/process_perfdata.cfg
这里将日志级别改为2,即为debug模式。
LOG_FILE = /usr/local/nagios/var/perfdata.log
# Loglevel 0=silent 1=normal 2=debug
LOG_LEVEL = 2

 

修改nagios.cfg

vi /usr/local/pnp4nagios/nagios.cfg

找到如下几项,去掉注释,修改后信息如下:

process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata

增加pnp4nagios图例标识

vi /usr/local/nagios/etc/objects/templates.cfg

让所有主机和服务调用pnp
修改templates.cfg文件中主机、以及服务的定义如:

define host{
name linux-server
use generic-host,host-pnp
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period workhours
notification_interval 120
notification_options d,u,r
contact_groups admins
register 0
}

define service{
name local-service
use generic-service,srv-pnp
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
register 0
}

并增加

define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}

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

修改commands.cfg ? 最后两项按照如下进行配置。

# 'process-host-perfdata' command definition

define command{
command_name process-service-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/service-perfdata
}

define command{
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-perfdata
}

修改完毕后重新启动nagios

service nagios restart

这时就会看到下面的标识的图标。

Nagio增加pnp4nagios图表显示

第一次打开图标时,显示的Test页面,只有这个页面提示没有错误才能正常使用。确认无误后按照页面提示的把这个/usr/local/pnp4nagios/share/install.php文件删除或是重命名。

Nagio增加pnp4nagios图表显示

最后正确的应该是如此显示。

Nagio增加pnp4nagios图表显示

Nagio增加pnp4nagios图表显示:等您坐沙发呢!

发表评论

表情
还能输入210个字