成都创新互联网站制作重庆分公司

关于nagios_nrpe的参数传递-创新互联

第一段文档简单写了如何搭建nagios/pnp4nagios/

成都地区优秀IDC服务器托管提供商(成都创新互联).为客户提供专业的电信内江机房,四川各地服务器托管,电信内江机房、多线服务器托管.托管咨询专线:18980820575
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
src=/home/nagios/src
mkdir ${src}
cd ${src}
wget http://ar2.php.net/distributions/php-5.5.9.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.1.tar.gz
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.7.tar.gz
wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.0.tar.gz
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.3.tar.gz
wget http://jaist.dl.sourceforge.net/project/mysql.mirror/MySQL%205.6.16/mysql-5.6.16.tar.gz
wget http://mirrors.neusoft.edu.cn/epel/6Server/x86_64/epel-release-6-8.noarch.rpm
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.8.tar.gz
wget http://cznic.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.21.tar.gz
rpm -ivh epel-release-6-8.noarch.rpm
#FOR RHEL5/CENTOS5x86_64
#DOWNLOAD URL IS http://mirrors.neusoft.edu.cn/epel/5Server/x86_64/epel-release-5-4.noarch.rpm
yum -y install wget mhash mcrypt libmcrypt-devel cmake cpan make autoconf automake curl curl-devel gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel gd gd-devel kernel keyutils patch perl-core kernel-headers compat* mpfr cpp glibc glibc-common libgomp libstdc++-devel pplcloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-develkrb5-devel libXpm* freetype freetype-devel libjpeg* libpng libpng-devel php-common php-gd ncurses* libtool* libxml2 libxml2-devel
packagelist=`ls ${src}/*.tar.gz`
for package in $packagelist;do tar xvf $package;done
cd cd ${src}/apr-1.5.0
./configure
make && make install
cd ${src}
cd cd ${src}/apr-util-1.5.3
./configure --with-apr=/usr/local/apr
make && make install
cd ${src}
chown -R nagios. ${src}
su - nagios
cd ${src}/httpd-2.4.7
./configure --prefix=/home/nagios/httpd  --enable-ssl=shared --enable-module=most --enable-shared=most --enable-rewrite
make && make install
cd modules/generators/
~/httpd/bin/apxs -i -a -c mod_cgi.c
~/httpd/bin/apxs -i -a -c mod_cgid.c
cd ${src}/mysql-5.6.16
cmake -DCMAKE_INSTALL_PREFIX=/home/nagios/mysql
make && make install
cd /home/nagios/mysql/
./scripts/mysql_install_db -basedir=/home/nagios/mysql -datadir=/home/nagios/mysql/data --user=nagios
/home/nagios/mysql/bin/mysqld_safe &
./bin/mysqladmin -u root password $password
cat >>~/.bash_profile<
#    DirectoryIndex index.html index.php
#
rm -rf ~/httpd/htdocs/index.html
cat >>~/httpd/htdocs/index.php<;
EOF
cd ${src}/nagios-4.0.2
./configure --prefix=/home/nagios/nagios --enable-embedded-perl --with-command-group=nagcmd
make all
make install
#must_be_root
make install-init
make install-config
make install-commandmode
cat sample-config/httpd.conf>>~/httpd/conf/httpd.conf
~/httpd/bin/htpasswd -c /home/nagios/nagios/etc/htpasswd.users nagios
cd ${src}/nagios-plugins-1.5
 ./configure --prefix=/home/nagios/nagios/ --with-nagios-user=nagios --with-nagios-group=nagios --enable-libtap --enable-extra-opts --enable-perl-modules
make && make install
sed -i "s/nagiosadmin/nagiosadmin,nagios/g" ~/nagios/etc/cgi.cfg
#启动nagios:~/nagios/bin/nagios -d ~/nagios/etc/nagios.cfg
exit
echo "#BACK TO ROOOT#"
yum -y install cjkuni*
yum -y install cairo-devel pango pango-devel net-snmp* php-snmp libart_lgpl-devel
#install_rrdtool #must_be_root
cd ${src}/rrdtool-1.4.8
./configure --prefix=/home/nagios/rrdtool --enable-perl-site-install
make && make install
chown -R nagios. /home/nagios/rrdtool
#install pnp4nagios
su - nagios
cd ${src}/pnp4nagios
./configure --prefix=/home/nagios/pnp --with-rrdtool=/home/nagios/rrdtool/bin/rrdtool  --with-base-url=/pnp  --with-httpd-conf=/home/nagios/httpd/conf
make all
make install
make install-webconf
make install-config
echo "include conf/pnp4nagios.conf">>~/httpd/conf/httpd.conf
#vim ~/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 ~/nagios/etc/objects/commands.cfg
define command{
        command_name    process-host-perfdata
        command_line    /usr/bin/perl /home/nagios/pnp/libexec/process_perfdata.pl -d HOSTPERFDATA
        }
define command{
        command_name    process-service-perfdata
        command_line    /usr/bin/perl /home/nagios/pnp/libexec/process_perfdata.pl
        }
mv /home/nagios/pnp/share/install.php /home/nagios/pnp/share/install.php.`date +%Y%m%d`
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata

第二部分关于nrpe的安装

#!/bin/bash
#INSTALL NRPE DAEMON#
src=/home/nagios/src
nagios_home=/home/nagios/nagios
yum install openssl openssl-devel
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
echo "5cr8xOW7DF"|passwd --stdin nagios
su - nagios
mkdir ${src}
cd ${src}
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
wget http://jaist.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
echo "##INSTALL NAGIOS-PLUGINS##"
tar xvf nagios-plugins-2.0.tar.gz
cd nagios-plugins-2.0
./configure --prefix=${nagios_home} --enable-perl-modules
make && make install
cd ${src}
echo "##INSTALL NRPE##"
tar xvf nrpe-2.15.tar.gz
cd nrpe-2.15
#编译启用参数传递
./configure --prefix=${nagios_home} --with-nrpe-user=nagios --with-nrpe-group=nagios --enable-command-args
make all
make install-plugin
make install-daemon
make install-daemon-config
exit
cd ${src}/nrpe-2.15/
make install-xinetd
sed -i 's/127.0.0.1/192.168.28.241/g' /etc/xinetd.d/nrpe
echo "nrpe            5666/tcp        # NRPE" >>/etc/services
chown nagios. /etc/xinetd.d/nrpe
service xinetd restart
lsof -i:5666

nrpe.cfg配置文件简单如下

log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
server_address=127.0.0.1
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1
                                                                                                                                     
dont_blame_nrpe=1
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/home/nagios/nagios//libexec/check_users -w $ARG1$ -c $ARG2$
command[check_load]=/home/nagios/nagios//libexec/check_load -w $ARG1$ -c $ARG2$
command[check_disk]=/home/nagios/nagios//libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
command[check_procs]=/home/nagios/nagios//libexec/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$

其中server_address/allow_address注意根据实际修改,dont_blame_nrpe=1(默认为0,1为开启参数传递)

nagios server端command.cfg需另外define一个check_remote_nrpe的command

define command{
        command_name    check_remote_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$
        }

这样监控服务,如客户端环境改变需调整参数的话只需要在nagios服务端修改参数即可,例如

define service{
        use                     linux-service
        hostgroup_name          97f5eafb7a
        service_description     check partition /
        check_command           check_remote_nrpe!check_disk!20%!10%!/
        }

第三部分,如果以后添加新监控点,则需去修改每台客户机的nrpe.cfg文件去define command,这样太麻烦了。所以再添加这样一个脚本来传递整个命令,客户端如需添加新监控点只需上传监控脚本,nagios服务端define service即可

#!/bin/sh
while getopts "a:c:" arg
do
        case $arg in
             a)
                arg_a=$OPTARG;
                ;;
             c)
                arg_c=$OPTARG;
                ;;
             ?)
            echo "unkonw argument"
            echo "only -c -a argument"
            exit 1
            ;;
        esac
done
if [[ "$arg_c" =~ "$HOME/" ]];then
    if [ ! -x $arg_c ];then
        echo "[$arg_c] not execute";
        exit 3;
    fi
                                                   
    $arg_c $arg_a;
    exit $?;
else
    echo "cannt execute $arg_c,not allow execute [$HOME] outside scripts";
    exit 3;
fi

nagios的command文件需添加如下

define command{
        command_name    check_nrpe_exec
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
        }

客户端nrpe.cfg配置文件command部分只需要有

command[exec_command]=/home/nagios/nagios//libexec/exec_command -c exec_command -a "$ARG1$"

添加监控点例子,只需修改exec_command后的监控脚本命令

define service{
        use                     linux-service
        host_name               887a34d257
        service_description     check_swap
        check_command           check_nrpe_exec!"/home/nagios/nagios/libexec/check_swap -w 50% -c 30%"
        }

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:关于nagios_nrpe的参数传递-创新互联
网站URL:http://cxhlcq.com/article/dpiihd.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部