leonheart 发表于 2019-1-12 15:08:50

nagios被监控机安装脚本

  #!/bin/bash
groupadd nagios
useradd nagios -g nagios
chmod 755 check_cpu.sh check_mem.sh
yum -y install openssl openssl-devel gcc gcc-c++ xinetd
tar -zxf nrpe-2.12.tar.gz
tar -zxf nagios-plugins-2.1.1.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd

if ! [ `cat /etc/services | grep NRPE| wc -l` -ge 1 ]
then
      echo "nrpe            5666/tcp                        # NRPE">>/etc/services
fi
cd ../nagios-plugins-2.1.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
/bin/cp ../check_mem.sh /usr/local/nagios/libexec/
/bin/cp ../check_cpu.sh /usr/local/nagios/libexec/
/bin/cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg.default

cat >>/usr/local/nagios/etc/nrpe.cfg/etc/xinetd.d/nrpe> ${TMPFILE}
    echo "old_user[${a}]=${user[${a}]}" >> ${TMPFILE}
    echo "old_nice[${a}]=${nice[${a}]}" >> ${TMPFILE}
    echo "old_iowait[${a}]=${iowait[${a}]}" >> ${TMPFILE}
    echo "old_irq[${a}]=${irq[${a}]}" >> ${TMPFILE}
    echo "old_softirq[${a}]=${softirq[${a}]}" >> ${TMPFILE}
    echo "old_idle[${a}]=${idle[${a}]}" >> ${TMPFILE}
    echo "old_used[${a}]=${used[${a}]}" >> ${TMPFILE}
    echo "old_total[${a}]=${total[${a}]}" >> ${TMPFILE}
done
}

read_tmpfile() {
if [ -e ${TMPFILE} ]; then
    source ${TMPFILE}            # include the vars from the tmp file
fi
(( DEBUG )) && cat ${TMPFILE}
}

########################
# MAIN
########################

parse_options $@

read_tmpfile

procstat=$(cat /proc/stat 2>&1)
(( DEBUG )) && echo "$procstat"
cpucount=$(( $(grep -i cpu
页: [1]
查看完整版本: nagios被监控机安装脚本