分类: 系统运维
2011-12-28 15:12:09
1.在/usr/local/nrpe/libexec/目录
vi check_sda3.sh
#!/bin/sh
df_sda3=`/usr/bin/sudo df -k | grep /dev/sda3`
disk_usage_percent=`echo $df_sda3 | awk '{print $5}' | awk -F"%" '{print $1}'`
if [ $disk_usage_percent -lt 60 ]
then
echo "OK -disk usage is ${disk_usage_percent}%"
exit 0
fi
if [ $disk_usage_percent -gt $1 -a disk_usage_percent -lt 80 ]
then
echo "Warning -disk usage is ${disk_usage_percent}%"
exit 1
fi
if [ $disk_usage_percent -gt 80 ]
then
echo "Critical -disk usage is ${disk_usage_percent}%"
exit 2
fi
#chmod +x check_sda3.sh 加上执行权限
#chown nagios:nagios check_sda3.sh
2.在被监控机改nrpe.cfg 定义插件命令.
vi /usr/local/nagios/etc/nrpe.cfg
command[check_sda3]=/usr/local/nagios/libexec/check_sda3
3.在被监控机上测试
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_sda3
OK -disk usage is 15%
注:以nagios用户运行df命令,可能无法检查某些文件系统。
如:
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 50394964 22551628 25283380 48% /
none 8311408 0 8311408 0% /dev/shm
df: `/usr/local/httpd/htdocs/': Permission denied
造成下述结果:
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_sda3
NRPE: Unable to read output
因此需要修改/etc/sudoers,允许nagios用户以root运行df,且不用输入密码
#visudo
# Cmnd alias specification
Cmnd_Alias NAGIOS_CMD=/bin/df
# User privilege specification
nagios ALL=NOPASSWD:NAGIOS_CMD
其中:NAGIOS_CMD必须全部大写,否者会报语法错误。
4.在监控平台机定义命令及服务
define service{
use generic-service
host_name remotehost
service_description check_sda3 Space
check_command check_nrpe!check_sda3
}
5. 平台reload nagios
#service nagios restart