温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

关于nagios_nrpe的参数传递

发布时间:2020-07-19 17:48:29 来源:网络 阅读:1255 作者:heymra 栏目:移动开发

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

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<<EOF
export PATH=$HOME/mysql/bin
EOF
cd ${src}/php-5.5.9
./configure --prefix=/home/nagios/php \
--with-apxs2=/home/nagios/httpd/bin/apxs \
--with-mysql=/home/nagios/mysql \
--with-mysqli=/home/nagios/mysql/bin/mysql_config \
--with-zlib-dir \
--with-gd \
--with-libxml-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-mhash \
--with-mcrypt \
--with-iconv \
--with-openssl \
--with-gettext \
--enable-bcmath \
--enable-shmop \
--enable-fpm \
--enable-mbstring \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-static \
--enable-zend-signals \
--enable-inline-optimization \
--enable-sockets \
--enable-soap \
--enable-ftp \
--enable-zip \
--enable-session \
--with-curl \
--disable-ipv6
make && make install
cp php.ini-production ~/php/etc/php.ini
#vim ~/httpd/conf/httpd.conf
#replace User/Group to nagios
#ServerName注释127.0.0.1
#修改默认80端口
#AddType application/x-httpd-php .php
#<IfModule dir_module>
#    DirectoryIndex index.html index.php
#</IfModule>
rm -rf ~/httpd/htdocs/index.html
cat >>~/httpd/htdocs/index.php<<EOF
<?php
phpinfo();
?>;
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%"
        }


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI