I. Custom Nagios monitoring scripts
1. Create a script on the client/usr/local/nagios/libexec/check_disk.sh
Vim/usr/local/nagios/libexec/check_disk.sh writes the following: (On the client)
#!/bin/bash
row= ' df-h |wc-l ' #输出的总行数
For i in ' seq 2 $row ' #从第二行开始为真实的磁盘 because the first behavior header information
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 $ "#去掉% of utilization
p_p= ' df-h-p|sed-n "$i" P|awk ' {print $6} ' #挂载点
If ["$u _per"-gt "];then"
Echo-n "$p _p CRITICAL $u _per% $ava"
sta[$i]=2 #大于97, gives the return value 2 and displays some information
elif ["$u _per"-gt "];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
# #exit 2 means that after the program exits, it returns a value of 2.
It can be understood that the program died, its last words were 2, telling others that they died for what reason. This way the forensic (shell or its parent process) can know the cause to determine who the murderer (the program is making) is, and for further processing.
2. After saving, modify the permissions of the script
chmod +x/usr/lib/nagios/plugins/check_disk.sh (on client)
3. Then edit the/etc/nagios/nrpe.cfg file
VIM/ETC/NAGIOS/NRPE.CFG # Add a line: (on client)
command[check_disk]=/usr/lib/nagios/plugins/check_disk.sh
Save, restart Nrpe service
/etc/init.d/nrpe restart (on client)
4. The way to detect if the script is working correctly is to execute the following command to the server side:
/usr/lib/nagios/plugins/check_nrpe-h 192.168.0.12-c Check_disk (on server)
If normal, it will output a row of disk detection data, or may be error.
5. Add the appropriate service to the server
cd/etc/nagios/conf.d/
Vim 192.168.0.12.cfg # Add the following:
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. Restart the Nagios service
/etc/init.d/nagios restart (on server)
3.2-nagios Custom Monitoring System disk script