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
#!/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-p|sed-n "$i" P|awk ' {print $6} '
If ["$u _per"-gt "];then"
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
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:
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.
cd/etc/nagios/conf.d/
Vim 192.168.0.12.cfg (your IP address name) # Add the following:
Define host{
use linux-server
host_name 192.168.0.12
alias 0.12
address 192.168.0.12
}
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
}
Continue adding services
Vim/etc/nagios/objects/commands.cfg
Define Command{
Command_name Check_nrpe
Command_line $USER 1$/check_nrpe-h $HOSTADDRESS $-C $ARG 1$
}
Login ip/nagios/to see if it was successful
Nagios monitoring scripts (custom monitoring system disks)