木一 发表于 2019-1-15 07:38:30

Nagios(六)——pnp4nagios 绘制图表

  之前用pnp 整合到nagios中,发现总是没数据,图表也出不来,不知道是什么原因,找了资料发现现在用的更多还是pnp4nagios ,便下载试验一下,还真的成功了,配置如下:
1.安装RRDTool
# tar zxvf rrdtool-1.4.7.tar.gz
# ./configure --prefix=/usr/local/rrdtool
编译的时候出现了2个错误:
(1)configure: error: Please fix the library issues listed above and try again.
解决办法:
# tar zxvf cgilib-0.5.tar.gz
# cd cgilib-0.5
# make
# cp libcgi.a /usr/local/lib
# cp cgi.h /usr/include

# yum -y install libart_lgpl-devel
# yum -y install pango-devel* cairo-devel*

(2)在make的时候报错:
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 1.

解决办法:
yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

安装完重新编译即可。
# ./configure --prefix=/usr/local/rrdtool
# make
# make install

2.安装pnp4nagios
# tar zxvf pnp4nagios-0.6.19.tar.gz
# cd pnp4nagios-0.6.19
# ./configure --prefix=/usr/local/pnp4nagios --with-nagios-user=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool

到这一步有一个报错:
checking for Perl Module Time::HiRes... no
configure: error: Perl Module Time::HiRes not available

解决办法:
# yum -y install perl-Time-HiRes

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

安装完成后,通过模板文件,创建配置文件
# cd /usr/local/pnp4nagios/etc/
# mv nagios.cfg-sample nagios.cfg
# mv rra.cfg-sample rra.cfg
# mv misccommands.cfg-sample misccommands.cfg
# cd pages/
# mv web_traffic.cfg-sample web_traffic.cfg
# cd ../check_commands/
# mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
# mv check_nrpe.cfg-sample check_nrpe.cfg
# mv check_nwstat.cfg-sample check_nwstat.cfg

3.编辑httpd.conf
打开httpd.conf并添加以下内容:
Alias /pnp4nagios "/usr/local/pnp4nagios/share"

AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user

# Turn on URL rewriting
RewriteEngine On
Options symLinksIfOwnerMatch
# Installation directory
RewriteBase /pnp4nagios/
# Protect application and system files from being viewed
RewriteRule "^(?:application|modules|system)/" -
# 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"


配置完成后保存退出。
重启http
# /usr/local/apache/bin/apachectl restart

4.编辑template.cfg 文件
添加以下内容:
# vim /usr/local/nagios/etc/objects/templates.cfg
define host {
namehosts-pnp
register0
action_url /pnp4nagios/graph?host=$HOSTNAME$
process_perf_data1
}
define service {
nameservices-pnp
register0
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data1
}

5.编辑hosts.cfg和services.cfg 添加小太阳标示
# vim /usr/local/nagios/etc/hosts.cfg
define host{
uselinux-server,hosts-pnp
host_namenode-1
aliaslamp
address192.168.30.110
}

# vim /usr/local/nagios/etc/services.cfg
define service{
usegeneric-service,services-pnp
host_namenode-1
service_descriptioncheck_users
check_commandcheck_nrpe!check_users
max_check_attempts 5
normal_check_interval 1
}

6.编辑commands.cfg 添加相应命令
# vim /usr/local/nagios/etc/objects/commands.cfg
# 'process-host-perfdata' command definition
define command{
command_nameprocess-host-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}

# 'process-service-perfdata' command definition

define command{
command_nameprocess-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
注意:这里为了方便管理,将process_perfdata.pl 复制到/usr/local/nagios/libexec/目录下
# cp /usr/local/pnp4nagios/libexec/process_perfdata.pl /usr/local/nagios/libexec/

7.检查并重启nagios
通过nagios –v 参数检查配置是否有错误存在。
Total Warnings: 0
Total Errors:0
确认无错误后,重启nagios
# service nagios restart
Running configuration check...done.
Stopping nagios: .done.

效果如下:
http://blog.运维网.com/attachment/201303/151825505.jpg


点击小太阳进入测试页面

http://blog.运维网.com/attachment/201303/151910422.jpg
http://blog.运维网.com/attachment/201303/151929260.jpg

注:只有在前面准备阶段把基础环境都配置好,这里的环境测试才能全部通过的。
如果提示缺少Php 相关包,可以通过yum –y php-* 进行安装

按照图中提示删除或者重命名其安装文件install.php。这里选择重命名的方式。
# mv /usr/local/pnp4nagios/share/install.php
/usr/local/pnp4nagios/share/install.php.bak

8.编辑nagios.cfg,开启数据接收功能
# vim /usr/local/nagios/etc/nagios.cfg
process_performance_data=1
enable_environment_macros=1
service_perfdata_command=process-service-perfdata
host_perfdata_command=process-host-perfdata

9.重启nagios 服务之后即可看到图表
注意:打开的时候遇到了以下的错误:

http://blog.运维网.com/attachment/201303/152011592.png
  根据提示,是权限不够的问题:
  # chmod 750 /var/lib/php/session/
  # chown nagios.nagios /var/lib/php/session/
  
  刷新网页之后即可看到有图表出现:

http://blog.运维网.com/attachment/201303/152036381.jpg



页: [1]
查看完整版本: Nagios(六)——pnp4nagios 绘制图表