Client
1. Create Script check_disk.sh
[email protected] ~]# vim/usr/lib64/nagios/plugins/check_disk.sh #一般都放在这个路径下
#!/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 "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
##### #输出结果 ######
[Email protected] ~]# sh/usr/lib64/nagios/plugins/check_disk.sh
/OK 26% 13g/dev/shm ok 0% 242m/boot OK 8% 426M
[[email protected] ~]# echo $?
0
2, after saving, modify the permissions of the script
[Email protected] ~]# chmod +x/usr/lib64/nagios/plugins/check_disk.sh
3. Edit/etc/nagios/nrpe.cfg, add custom scripts
[Email protected] ~]# vim/etc/nagios/nrpe.cfg
command[check_disk]=/usr/lib64/nagios/plugins/check_disk.sh
4. Restart Nrpe Service
[Email protected] ~]#/etc/init.d/nrpe restart
Service side
5. Check if the script is running correctly
[email protected] ~]#/usr/lib64/nagios/plugins/check_nrpe-h 192.168.219.128-c check_disk
/OK 26% 13g/dev/shm ok 0% 242m/boot OK 8% 426M
Explanatory notes:
If normal, it will output a row of disk detection data, or may be error.
# # # # #错误 #####
[Email protected] ~]#/usr/lib64/nagios/plugins/check_nrpe-h 192.168.153.129-c check_disk
Nrpe:unable to read output
#############
Note: The reason is that the client script does not have permission to modify
6. Add the appropriate service
[Email protected] ~]# CD/ETC/NAGIOS/CONF.D
[Email protected] conf.d]# vim 192.168.219.128.cfg
Define Service{
Use Generic-service
HOST_NAME 192.168.219.128
Service_description Check_disk
Check_command Check_nrpe!check_disk
Max_check_attempts 5
Normal_check_interval 1
}
Note: Also check if there are any Check_nrpe in/etc/nagios/object/commands.cfg.
7. Restart the Nagios service and start the HTTP service
[Email protected] conf.d]#/etc/init.d/nagios restart
[[email protected] conf.d]#/etc/init.d/httpd start
8. Visit the browser to view
650) this.width=650; "src=" HTTP://NOTE.YOUDAO.COM/YWS/RES/9062/WEBRESOURCEDB2D8DFFF9DE38743E96F7FC877F36CB "alt=" Webresourcedb2d8dfff9de38743e96f7fc877f3 "/>
This article from the "Linux" blog, reproduced please contact the author!
Nagios Custom Monitoring System disk script