自动部署Nagios NRPE
作者:互联网
#!/bin/bash
#writed by sery(wx:formyz),in 2021-6-26
yum -y install gcc gcc-c++ make openssl openssl-devel wget net-tool
useradd nagios
chmod +x /etc/rc.d/rc.local
#install nrpe
cd
if [[ ! -f nrpe-4.0.2.tar.gz ]]
then
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.0.2/nrpe-4.0.2.tar.gz
tar zxvf nrpe-4.0.2.tar.gz
cd nrpe-4.0.2
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nrpe
make all
make install
make install-plug
make install-config
cd
fi
#install nagios-plugins
if [[ ! -f nagios-plugins-2.3.3.tar.gz ]]
then
wget --no-check-certificate https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar zxvf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nrpe
make
make install
cd
fi
#write tcpconns script
echo > /usr/local/nrpe/libexec/check_tcpconns
cat >> /usr/local/nrpe/libexec/check_tcpconns <<done
#!/bin/bash
tcp_conns=\`netstat -an|grep tcp |grep EST|wc -l\`
if [[ \$tcp_conns -lt \$1 ]]
then
echo "OK -connect count is \$tcp_conns"
exit 0
fi
if [[ \$tcp_conns -gt $1 ]] && [[ \$tcp_conns -lt $2 ]]
then
echo "WARNING -connect count is \$tcp_conns"
exit 1
fi
if [[ \$tcp_conns -gt $2 ]]
then
echo "CRITICAL -connect count is \$tcp_conns"
exit 2
fi
done
chmod +x /usr/local/nrpe/libexec/check_tcpconns
#modify nrpe.cfg
cd /usr/local/nrpe/etc
mon_ip=172.16.35.105
if [[ -f nrpe.cfg ]]
then
ipadd=$(ip add|grep eth0|grep inet | awk '{print $2}'|awk -F / '{print $1}')
sed -i "s/#server_address=127.0.0.1/server_address=${ipadd}/" nrpe.cfg
is_mon=`grep $mon_ip nrpe.cfg|grep -v grep |wc -l`
if [[ is_mon -eq 0 ]]
then
sed -i "s/allowed_hosts=127.0.0.1,/&$mon_ip,/" nrpe.cfg
fi
is_check_df=` grep check_df nrpe.cfg |grep -v grep|wc -l`
if [[ $is_check_df -eq 0 ]]
then
echo "command[check_df]=/usr/local/nrpe/libexec/check_disk -X tmpfs -X devtmpfs -w 20% -c 10%">>nrpe.cfg
fi
is_check_tcpconns=`grep check_tcpconns nrpe.cfg |grep -v grep|wc -l`
if [[ $is_check_tcpconns -eq 0 ]]
then
echo "command[check_tcpconns]=/usr/local/nrpe/libexec/check_tcpconns 800 1000">>nrpe.cfg
fi
is_check_mem=`grep check_memuse nrpe.cfg |grep -v grep|wc -l`
if [[ $is_check_mem -eq 0 ]]
then
echo "command[check_memuse]=/usr/local/nrpe/libexec/check_swap -w 40% -c 20%">>nrpe.cfg
fi
fi
#start nrpe service
cd
/usr/local/nrpe/bin/nrpe –c /usr/local/nrpe/etc/nrpe.cfg -d
is_nrpe_start=`grep nrpe /etc/rc.local |grep -v grep|wc -l`
if [[ $is_nrpe_start -eq 0 ]]
then
echo "/usr/local/nrpe/bin/nrpe –c /usr/local/nrpe/etc/nrpe.cfg -d" >>/etc/rc.local
fi
exit 0
咋没有bash
标签:grep,部署,NRPE,Nagios,nrpe,cfg,nagios,local,check 来源: https://blog.51cto.com/sery/2949890