標籤:nagios
1. 在用戶端上建立指令碼/usr/local/nagios/libexec/check_disk.sh
vim /usr/local/nagios/libexec/check_disk.sh 寫入如下內容:(client上)
#!/bin/bash
#!/bin/bash
row=`df -h |wc -l`
for i in `seq 2 $row`
do
ava=`df -h |sed -n “$i”p|awk ‘{print $4}’`
u_per=`df -h |sed -n “$i”p|sed -n “s/\%//”p|awk ‘{print $5}’`
p_p=`df -h -P|sed -n “$i”p|awk ‘{print $6}’`
if [ “$u_per” -gt “97” ];then
echo -n “$p_p CRITICAL $u_per% $ava ”
sta[$i]=2
elif [ “$u_per” -gt “95” ];then
echo -n “$p_p WARNING! $u_per% $ava ”
sta[$i]=1
else
echo -n “$p_p OK $u_per% $ava ”
sta[$i]=0
fi
done
n=0
for j in `seq 2 $row`
do
if [ “${sta[$j]}” -gt $n ];then
n=${sta[$j]}
fi
done
exit $n
2. 儲存後,修改該指令碼的許可權
chmod +x /usr/lib/nagios/plugins//check_disk.sh (client上)
3. 然後編輯/etc/nagios/nrpe.cfg檔案
vim /etc/nagios/nrpe.cfg # 加入一行:(client上)
command[check_disk]=/usr/lib/nagios/plugins/check_disk.sh
儲存,重啟nrpe服務
/etc/init.d/nrpe restart (client上)
4. 檢測剛才的指令碼是否正常啟動並執行方法是,到server端執行如下命令:
check_nrpe -H 192.168.210.12 -c check_disk (server上)
如果正常的話,會輸出一行磁碟檢測的資料,否則可能會報錯。
5. 到server上添加相應的service
192.168.210.12.cfg # 加入如下內容:
define service{
use generic-service
host_name 192.168.0.12
service_description check_disk
check_command check_nrpe!check_disk
max_check_attempts 5
normal_check_interval 1
}
6. 重啟nagios服務
/etc/init.d/nagios restart (server上)
一個監控磁碟的nagios指令碼