Create a script on the client/usr/lib/nagios/plugins/check_disk.sh//yum installation of Nagios, if you are compiling the default script file directory for your own installation in a custom installed Nagios directory
To operate on the client:
vim/usr/lib/nagios/plugins/check_disk.sh writes the following://This is a disk script sample, you can also write your own monitoring script
#!/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 $
p_p= ' df-h |sed-n "$i" P|awk ' {print $6} '
if ["$u _per"-gt "];then"//percentage can be customized
echo-n "$p _p CRITICAL $u _per% $ava"
sta[$i]=2
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//The loop is to find the sta[] maximum for all disk partitions
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)
on the server side operation:
4. The way to detect if the script is working correctly is to execute the following command to the server side:
check_nrpe-h ip-c check_disk (server)//This IP is the IP of the client
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 ip.cfg # file name can be customized, I use the client IP here to do file name, you can also use the hostname, the purpose is to facilitate the separation
define service{
Use generic-service
host_name IP
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)
This article is from the Linux OPS blog, so be sure to keep this source http://zhumy.blog.51cto.com/11647651/1827551
customizing Nagios monitoring Scripts