Centos nagios监控windows主机并开启PNP模块

OS:centos 5.7final 32bit
Apache/2.4.2 
PHP/5.3.13
Nagios Core 3.4.1
nagios-plugins-1.4.15
rrdtool-1.4.7
pnp4nagios-0.6.17

一、安装Apache
去Apache官网下载apr和apr-util
apr
./configure --prefix=/usr/local/apr
make
make install

apr-util
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make
make install

编译安装apache
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make
make install

二、安装PHP
./configure --prefix=/usr/local/php --with-gd --enable-sockets --with-zlib --with-jpeg-dir --with-freetype-dir --with-apxs2=/usr/local/apache2/bin/apxs
make 
make install
vim /usr/local/apache2/conf/httpd.conf
找到DirectoryIndex 在后面添加index.php
并在最后增加
 <IfModule mod_php5.c>
  AddType application/x-httpd-php .php
  AddType application/x-httpd-php .php .phtml .php3
  AddType application/x-httpd-php-source .phps
  </IfModule>

#/usr/local/apache2/bin/apachectl stop
#/usr/local/apache2/bin/apachectl start
至此apache已经支持php了

三、安装nagios
#useradd -m nagios
#groupadd nagios
#usermod -a -G nagios nagios
#usermod -a -G nagios apache

编译安装nagios
./configure --prefix=/usr/local/nagios --with-httpd-conf=/usr/local/apache2/conf
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users admin  创建用户名为admin的验证文件
按要求输入密码。

#vim /usr/local/apache2/conf/httpd.conf
User deamon 改为 User nagios
Group deamon 改为 Group nagios

在最后加入Include conf/nagios.conf

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
检查nagios.cfg是否有错误

#chkconfig --add nagios
#chkconfig nagios on

安装nagios-plugins
./configure --prefix=/usr/local/nagios
make
make install

乱码问题的解决方法:
修改httpd.conf文件,并找到以下文字,去掉“#”,重启apache
#LoadModule cgid_module modules/mod_cgid.so
#LoadModule actions_module modules/mod_actions.so

#vim /usr/local/nagios/etc/cgi.cfg
修改如下:
authorized_for_system_information=nagiosadmin,admin
authorized_for_configuration_information=nagiosadmin,admin
authorized_for_system_commands=nagiosadmin,admin
authorized_for_all_services=nagiosadmin,admin
authorized_for_all_hosts=nagiosadmin,admin
authorized_for_all_service_commands=nagiosadmin,admin
authorized_for_all_host_commands=nagiosadmin,admin

#vim /usr/local/nagios /etc/nagios.cfg
找到如下字段并去掉#号,监控windows主机
cfg_file=/usr/local/nagios/etc/objects/windows.cfg
在被监控主机上需装NSClinet软件并启用服务。

#vim /usr/local/nagios /etc/pages/contacts.cfg
将email地址改为自己的邮件地址,有报警直接发送给该地址

#vim /usr/local/nagios /etc/pages/windows.cfg
将ip address改为要监控的主机


#/usr/local/apache2/bin/apachectl stop
#/usr/local/apache2/bin/apachectl start
#service nagios start

四、安装pnp4nagios
首先安装rrdtool
./configure --prefix=/usr/local/rrdtool
make
make install
cp -r /usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi/* /usr/lib/perl5/5.8.8/i386-linux-thread-multi/

安装pnp4nagios
./configure --prefix=/usr/local/pnp4nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-httpd-conf=/usr/local/apache2/conf
make all
make install
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 npcd.cfg-sample npcd.cfg
mv process_perfdata.cfg-sample  process_perfdata.cfg
mv rra.cfg-sample rra.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

vim httpd.conf
加入如下文字
Include conf/pnp4nagios.conf
去掉LoadModule rewrite_module modules/mod_rewrite.so 的#

vim /usr/local/nagios/etc/nagios.cfg
process_performance_data=0改为1
下面的2行去掉#号
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata

vim /usr/local/nagios/etc/objects/commands.cfg
修改如下
define command {
        command_name    process-host-perfdata
        command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
        }
define command {
         command_name    process-service-perfdata
         command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl
        }

vim /usr/local/nagios/etc/objects/templates.cfg
添加如下内容
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
}

vim /usr/local/nagios/etc/objects/windows.cfg
修改如下
define host{
    use     windows-server,host-pnp ; Inherit default values from a template
……
define service{
    use                     generic-service,srv-pnp
……
 check_command           check_counter!-l "\\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client])\\Bytes Sent/sec","%.f"
注意这里"%.f"必须加,不加不出图!
(%.f没有e格式,默认6位仅只小数点后面包含6位。%.2f带两位小数点)


mv /usr/local/pnp4nagios/share/install.php ii.php

至此架设nagios+rrdtool+pnp4nagios监控windows主机已经完成。

本文出自 “实用笔记” 博客,请务必保留此出处http://qiuyt.blog.51cto.com/1229789/1627324

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。