nagios系列(五)之nagios图形显示的配置及自定义插件检测密码是否修改详解

nagios图形显示的配置


在服务端安装相关软件
#1、图形显示管理的依赖库
yum install cairo pango zlib zlib-devel freetype freetype-devel gd gd-devel -y


#2、rrdtools的依赖
tar xf libart_lgpl-2.3.17.tar.gz
cd libart_lgpl-2.3.17
./configure
make
make install
/bin/cp -r /usr/local/include/libart-2.0 /usr/include
cd ../


#3、rrdtools轮询的数据库,专门画图
tar xf rrdtool-1.2.14.tar.gz 
cd rrdtool-1.2.14
./configure --prefix=/usr/local/rrdtool  --disable-python  --disable-tcl
#WARNING: The RRDs Perl Modules are not found on your System
#Using RRDs will speedup things in larger Installtions.
#configure后出现上面的提示可以不用理会。
make
make install
cd ../
ls -l /usr/local/rrdtool/bin


报错:
configure: error: Please fix the library issues listed above and try again.
解决:
yum -y install pango*
yum install -y libart_lgpl-devel


#4、PNP收集数据告诉rrdtools画图,PHP负责展示
tar zxf pnp-0.4.14.tar.gz
cd pnp-0.4.14
./configure \
--with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata/
#################
#  WARNING: The RRDs Perl Modules are not found on your System
#           Using RRDs will speedup things in larger Installtions.
#####################
make all
make install
make install-config
make install-init
ll /usr/local/nagios/libexec/ |grep process
问题:configure报错(一般不会发生)
checking for linker flags for loadable modules... -shared
checking for Perl Module Time::HiRes... no
configure: error: Perl Module Time::HiRes not available
解决:
yum install perl-Time-HiRes -y


配置出图

1.vim /usr/local/nagios/etc/nagios.cfg +833
    833 process_performance_data=1<==========
    834 
    835 
    836 
    837 # HOST AND SERVICE PERFORMANCE DATA PROCESSING COMMANDS
    838 # These commands are run after every host and service check is
    839 # performed.  These commands are executed only if the
    840 # enable_performance_data option (above) is set to 1.  The command
    841 # argument is the short name of a command definition that you
    842 # define in your host configuration file.  Read the HTML docs for
    843 # more information on performance data.
    844 
    845 host_perfdata_command=process-host-perfdata<==========
    846 service_perfdata_command=process-service-perfdata<==========


2.执行编辑命令 vim /usr/local/nagios/etc/objects/commands.cfg +227,修改commands.cfg配置文件。
#修改commands.cfg 配置文件,约227-238行
#默认配置为(如果没有直接添加即可)
#-----------------------------------------------------------------   
# 'process-host-perfdata' command definition
define command{
        command_name    process-host-perfdata
        command_line    /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /usr/local/nagios/var/host-perfdata.out
        }
# 'process-service-perfdata' command definition
define command{
        command_name    process-service-perfdata
        command_line    /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /usr/local/nagios/var/service-perfdata.out
        }
修改成如下配置
# 'process-host-perfdata' command definition
define command{
        command_name    process-host-perfdata
        command_line    /usr/local/nagios/libexec/process_perfdata.pl
        }


# 'process-service-perfdata' command definition
define command{
        command_name    process-service-perfdata
        command_line    /usr/local/nagios/libexec/process_perfdata.pl
        } 
也可以用nagios变量$USER1$替代/usr/local/nagios/libexec/路径
执行检查语法命令/etc/init.d/nagios checkconfig 
Total Warnings: 0
Total Errors:   0
根据提示,配置通过。重新加载/etc/init.d/nagios reload


3、主机出图的配置,模板或主机配置里hosts.cfg或者vim templates.cfg 

action_url            /nagios/pnp/index.php?host=$HOSTNAME$

单独对hosts.cfg的配置


对 templates.cfg 的配置




4、服务出图,模板或服务配置里service.cfg、templates.cfg注意,service中的use generic-service 要和 templates中的name generic-service名称要一致

action_url            /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$

对service.cfg的配置


对templates.cfg的配置



snmp协议(cacti),客户端安装或开启SNMP
nrpe(nlient++)
网络设备(路由器,交换机),开启SNMP


自定义插件:监控密码文件是否改变


测试
# md5sum /etc/passwd
c8273759e929d37c56dbae0478bd4d3b  /etc/passwd
[root@node3 ~]# md5sum /etc/passwd >/etc/jack.md5
[root@node3 ~]# md5sum -c /etc/jack.md5
/etc/passwd: OK


①在客户端添加自定义脚本
cd /usr/local/nagios/libexec
cat check_passwd


#!/bin/bash
char=`md5sum -c /etc/jack.md5 2>/dev/null|grep "OK"|wc -l`
if [ $char -eq 1 ];then
echo "passwd is ok"
exit 0
else
echo "passwd is changed"
exit 2
fi


# chmod +x check_passwd 
[root@node3 libexec]# ll check_passwd 
-rwxr-xr-x 1 root root 166 Jul 22 21:33 check_passwd
②在客户端增加命令,并重启nrpe服务使之生效
vim /usr/local/nagios/etc/nrpe.cfg
添加check_passwd定义命令
command[check_passwd]=/usr/local/nagios/libexec/check_passwd
③在服务端测试
/usr/local/nagios/libexec/check_nrpe -H 192.168.8.41 -c check_passwd


添加服务脚本
define service{
        use generic-service
        host_name node3.chinasoft.com
        service_description   check_passwd
        check_command   check_nrpe!check_passwd
}


检测语法并重新加载service nagios checkconfig,service nagios reload
④改变性测试在客户端执行添加用户命令 useradd jack
服务端执行
/libexec/check_nrpe -H 192.168.8.41 -c check_passwd
passwd is changed
posted @ 2016-07-22 21:47  reblue520  阅读(291)  评论(0编辑  收藏  举报