一个nagios客户端部署脚本

发布时间:2020-05-01编辑:脚本学堂
一个nagios客户端部署脚本,有需要的朋友可以参考下。

一个nagios客户端部署脚本,有需要的朋友可以参考下。
 

复制代码 代码如下:

#!/bin/bash
echo 'tdjm v1.0 client by linuxhost'
echo '#---------------------------------------'
echo ''
clear
SOFTWARE_PATH=$(cd ~;pwd)
NAGIOS_PATH=/usr/local/nagios
PACKAGE1=gcc
PACHAGE2=glibc
PACKAGE3=xinetd
PACKAGE4=openssl
NAGIOS_SERVER=192.168.10.163      #插件位于nagios服务端的ftp上
. /etc/rc.d/init.d/functions
/usr/sbin/useradd -s /sbin/nologin nagios
######DownLoad The Client Package from Ftp Server######
download(){
echo 'DownLoad The Client Package from Ftp Server'
lftp $NAGIOS_SERVER <<EOF
cd /pub/
mget nagios-p.tar.gz
close
bye
EOF
}

#-------------Installing The Client Package Of The Nagios-Plugins------------------
nagios-plugins() {
echo 'Installing The Client Package Of The Nagios-Plugins....'
tar -zxf nagios-p.tar.gz
echo "$SOFTWARE_PATH"
cd $SOFTWARE_PATH/nagios-p
tar zxvf nagios-plugins-1.4.15.tar.gz
cd $SOFTWARE_PATH/nagios-p/nagios-plugins-1.4.15
./configure
make all
make install
}
#-------------Installing The Client Package Of The Nrpe And IO-plu----------------
install-nrpe(){
echo 'Installing The Client Package Of The Nrpe'
cd $SOFTWARE_PATH/nagios-p
tar zxf nrpe-2.12.tar.gz
cd $SOFTWARE_PATH/nagios-p/nrpe-2.12
./configure
make all
make install-daemon
make install-daemon-config
make install-xinetd
if [ -f /etc/xinetd.d/nrpe ];then
sed -i "s/127.0.0.1/127.0.0.1 $NAGIOS_SERVER/g" /etc/xinetd.d/nrpe
else
echo 'NRPE requrie xinetd server!'
exit
fi
echo 'nrpe            5666/tcp           # nrpe' >> /etc/services

#install vmio
cd $SOFTWARE_PATH/nagios-p
tar -zxf VMIO.tar.gz
cp Nagios_VIMO_Plugin/check_vmio.sh $NAGIOS_PATH/libexec

#chenge owner
chown -R nagios:nagios $NAGIOS_PATH
}
#-----------------Add The Client Check Command--------------------
add-command() {
if [ -f $NAGIOS_PATH/etc/nrpe.cfg ];then
sed -i '/check_users/d' $NAGIOS_PATH/etc/nrpe.cfg
sed -i '/check_load/d' $NAGIOS_PATH/etc/nrpe.cfg
cat >>$NAGIOS_PATH/etc/nrpe.cfg<<EOF
#---------------------------
command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 15
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,12,10 -c 25,20,18
command[check_disk]=/usr/local/nagios/libexec/check_disk -x /ytxt/patch -x /ytxt/maintain -w 10% -c 5%
command[check_procs]=/usr/local/nagios/libexec/check_procs -w 280 -c 350
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 8% -c 4%
command[check_vmio]=/usr/local/nagios/libexec/check_vmio.sh -p PROCESS_QUEUE -w 10 -c 15
EOF

else
echo 'The Nagios-plugins Install Fail!'
exit
fi
}
main(){
for i in $PACKAGE1 $PACKAGE2 $PACKAGE3 $PACKAGE4
do
rpm -q $i >/dev/null 2>&1
if (($? != 0));then
echo "PLE chack $i package"
exit
else
echo 'The base package have installed!'
fi
done
download
nagios-plugins
install-nrpe
add-command
sed -i 's/allowed_hosts=127.0.0.1/allowed_hosts=127.0.0.1,192.168.10.163/g' /usr/local/nagios/etc/nrpe.cfg
echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d' >> /etc/rc.d/rc.local
rm -rf /etc/xinetd.d/nrpe

#restart xinetd
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
sleep 5

netstat -natuple | grep 5666 >/dev/null 2>&1
if (($? != 0));then
echo
echo
echo
echo '#---------------------------------------------------------'
echo '#Install Fail Please Check The Server And install again!#'
echo '#---------------------------------------------------------'
else
echo
echo
echo '#----------------------------------------------'
echo '#                 INSTALL SUCCESS         #'
echo '#-----------------------------------------------'
fi
}
if grep nagios /etc/passwd
then
main
else
echo 'you must add the nagios user!'
exit 0
fi