遠程修改Nrpe的指令碼

來源:互聯網
上載者:User

遠程修改Nrpe的指令碼 前言:作為一個營運人員,經常修改監控是無可避免的,改少量機器還好說,如果量特別多的話,那就不容易了。如老大一句話,修改所有機器的check_disk參數,那就傻了。我今天就遇到了,開發說要修改所有業務系統的check_swap,自己寫了個指令碼,可以供大家參考下。兩個檔案:  www.2cto.com  1、hostlist   這個是我需要修改監控參數的主機檔案;2、editnrpe.sh  這個是我的指令碼,執行指令碼時,需要調用1檔案;3、scannrpe.sh  這個是我修改完之後,再掃描一下Nrpe的指令檔;下面的指令碼實現如下功能,之前的Nrpe參數為:command[check_swap]=/usr/local/nagios/libexec/check_swap -w 80% -c 70%修改後的參數為:command[check_swap]=/usr/local/nagios/libexec/check_swap -w 75% -c 65% 指令碼如下:[only.liu@l-rtools1.ops.cn1 ~]$ cat editnrpe.sh#!/bin/bash## This script is auto edit Nrpe# By Only.liu swapfile="/usr/local/nagios/etc/nrpe.cfg" for host in `cat hostlist`do     ping -c 1 $host >> /dev/null 2>&1    if [ "$?" == 0 ]; then         echo "$host is alived!"         ssh $host  "sudo sed -i -e '/check_swap/{s/\-w 80\%/\-w 75\%/;s/-c 70\%/-c 65\%/}' '$swapfile'"          if [ "$?" == 0 ]; then             echo "Swap is edited success!"             ssh $host "grep "check_swap" $swapfile"         fi         ssh $host "ps aux | grep nrpe | grep -v grep | awk '{ print \$2 }' | xargs sudo kill -HUP"         ssh $host "exit"         echo "Nrpe restart ok!"    fidone 修改完之後,不放心,再掃描一下:指令碼如下:  www.2cto.com  [only.liu@l-rtools1.ops.cn1 ~]$ cat scannrpe.sh #!/bin/bash## This script is auto edit Nrpe# By Only.liu #hostlist=`cat hostlist`swapfile="/usr/local/nagios/etc/nrpe.cfg" for host in `cat hostlist`do     ping -c 1 $host >> /dev/null 2>&1    if [ "$?" == 0 ]; then         echo "$host is alived!"         ssh $host  "sudo sed -n '/check_swap/p' '$swapfile'"     fidone 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.