Nagios中用於nrpe的啟動管理指令碼

來源:互聯網
上載者:User

標籤: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 libraryif [ -f /etc/rc.d/init.d/functions ]; then    . /etc/rc.d/init.d/functionselif [ -f /etc/init.d/functions ]; then    . /etc/init.d/functionselif [ -f /lib/lsb/init-functions ]; then    . /lib/lsb/init-functionsfiprefix="/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=0start() {   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=2esacexit $RETVAL

總之來說還是比較簡單的,其中有使用到系統的functions,可以參看:http://jim123.blog.51cto.com/4763600/1900432,其中要注意的一點是,把檔案上傳至/etc/init.d目錄後需要授予執行權,然後用chkconfig加入系統中使service能管理到,如果是Linux/Centos 7的系統還要使用systemctl daemon-reload重載一次:

[[email protected] init.d]# chmod +x nrped[[email protected] init.d]# chkconfig --add nrpedchkconfig --list nrpedsystemctl daemon-reload[[email protected] init.d]# chkconfig --list nrpednrped           0:關閉  1:關閉  2:啟用  3:啟用  4:啟用  5:啟用  6:關閉[[email protected] init.d]# /etc/init.d/nrped restartStopting nrpe                                              [確定]Starting nrpe                                              [確定][[email protected] init.d]# service nrped restartStopting nrpe                                              [確定]Starting nrpe                                              [確定]


本文出自 “Jim的技術隨筆” 部落格,謝絕轉載!

Nagios中用於nrpe的啟動管理指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.