手机版
你好,游客 登录 注册
背景:
阅读新闻

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

[日期:2017-09-25] 来源:Linux社区  作者:jim123 [字体: ]

最近一段时间应为需要大量的调整修改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

总之来说还是比较简单的,其中有使用到系统的functions,可以参看:http://www.linuxidc.com/Linux/2017-09/147058.htm,其中要注意的一点是,把文件上传至/etc/init.d目录后需要授予执行权,然后用chkconfig加入系统中使service能管理到,如果是Linux/CentOS 7的系统还要使用systemctl daemon-reload重载一次:
[root@localhost init.d]# chmod +x nrped
[root@localhost init.d]# chkconfig --add nrped
chkconfig --list nrped
 
systemctl daemon-reload[root@localhost init.d]# chkconfig --list nrped
nrped          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
[root@localhost init.d]# /etc/init.d/nrped restart
Stopting nrpe                                              [确定]
Starting nrpe                                              [确定]
[root@localhost init.d]# service nrped restart
Stopting nrpe                                              [确定]
Starting nrpe                                              [确定]

CentOS 7下安装配置Nagios监控图文详解  http://www.linuxidc.com/Linux/2017-05/143886.htm

Nagios邮件报警配置简述  http://www.linuxidc.com/Linux/2017-02/140834.htm

Nagios本机及其他主机监控安装部署详解  http://www.linuxidc.com/Linux/2017-03/141600.htm

Nagios 系统监控基本安装配置过程详解  http://www.linuxidc.com/Linux/2017-01/139758.htm

Linux下Nagios+PNP4Nagios的安装与配置  http://www.linuxidc.com/Linux/2016-09/135534.htm

CentOS7安装Nagios并配置出图详解  http://www.linuxidc.com/Linux/2015-12/125777.htm

Linux下Nagios安装配置详解  http://www.linuxidc.com/Linux/2017-05/144032.htm

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

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-09/147057.htm

linux
相关资讯       Nagios 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款