Nagios中用于nrpe的启动管理脚本

最近一段时间应为需要大量的调整修改Nagios的监控策略所以需要反复的重启nrpe,但是在Nagios安装后是没有提供nrpe的启动脚本,所以就自己顺手写了一个用于平时nrpe的重启:

#!/bin/sh
#The startup script for nrpe
#Author:jim
#processname:nrped
# chkconfig:  2345 97 03
#description:This is a daemon used for nrpe startup management in Nagios
 
#source functions library
if [ -f /etc/rc.d/init.d/functions ]; then
    . /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
    . /etc/init.d/functions
elif [ -f /lib/lsb/init-functions ]; then
    . /lib/lsb/init-functions
fi
 
prefix="/usr/local/nagios"
nrpe_bin="${prefix}/bin/nrpe"
nrpe_config_file="${prefix}/etc/nrpe.cfg"
nrpe_num=$(ps aux | grep /bin/nrpe | grep -v grep | wc -l)
nrpe_pid=$(ps aux | grep /bin/nrpe | grep -v grep | awk '{print $2}')
RETVAL=0
 
start() 
{
  if [ $nrpe_num -eq 1 ];then
 
      echo_warning
      echo "nrpe is running "
  else
      ${nrpe_bin} -c ${nrpe_config_file} -d
      echo_success
      echo "Starting nrpe "
  fi
}
 
stop()
{
  if [ $nrpe_num -eq 1 ];then
      kill -9 $nrpe_pid
      echo_success
      echo "Starting nrpe "
  else
      echo_failure
      echo "nrpe is stoping "
  fi
}
 
restart()
{
  if [ $nrpe_num -eq 1 ];then
      kill -9 $nrpe_pid
      echo_success
      echo "Stopting nrpe "
      ${nrpe_bin} -c ${nrpe_config_file} -d
      echo_success
      echo "Starting nrpe "
  else
      echo_failure
      echo "nrpe is stoping "
      ${nrpe_bin} -c ${nrpe_config_file} -d
      echo_success
      echo "Starting nrpe "
  fi
}
 
case $1 in
 start)
      start
      ;;
 stop)
      stop
      ;;
 restart)
      restart
      ;;
      *)
      echo_failure
      echo "Usage: $0 {start|stop|restart}"
      RETVAL=2
esac
 
exit $RETVAL

Nagios 的详细介绍请点这里
Nagios 的下载地址请点这里

猜你喜欢

转载自www.linuxidc.com/Linux/2017-09/147057.htm