自定义命令:
脚本:
如检查目录下的文件数量
sh check_file_num.sh -w 10 -c 62
WARING File num 61
check_file_num.sh
#!/bin/bash
c_path="/usr/local/nagios/libexec"
f_num="`ls $c_path|wc -l`"
w_arg="$2"
c_arg="$4"
msg=""
if [[ $# -lt 2 ]]
then
echo "Usage `basename $0 ` -w \$arg -c \$arg"
exit 1
fi
if [[ $f_num -ge $w_arg && $f_num -lt $c_arg ]]
then
msg="WARING"
fi
if [[ $f_num -ge $c_arg ]]
then
msg="Critical"
fi
#show msg
echo "$msg Current File $f_num"
exit
模式1:固定数字
注册到 nrpe.cfg 中
#commandcheck_file_num=/usr/local/nagios/libexec/check_file_num.sh -w ARG1 -c ARG2
commandcheck_file_num1=/usr/local/nagios/libexec/check_file_num.sh -w 20 -c 40
重启nrpe (KILL 进程)
(如果不需要更换命令名字,则不需要注册command.cfg 和services.cfg)
注册到command.cfg 文件中
#check_file
define command{
command_name check_file_num
command_line USER1/check_nrpe -H HOSTADDRESS -c ARG1 ARG2
}
添加services.cfg 中,使之生效
define service{
use local-service
host_name nagios-admin,nagios-client
service_description Current File Num
check_command check_file_num!check_file_num
}
不变更命令名
添加services.cfg 中,使之生效
define service{
use local-service
host_name nagios-admin,nagios-client
service_description Current File Num
check_command check_nrpe!check_file_num
}
监控机上
重启nagios 服务
/etc/init.d/nagios reload
检测脚本是否执行超过
./check_nrpe -H 192.168.146.170 -c check_file_num1
./check_nrpe -H 10.0.0.64 -c check_mysql_slave