我已经成功创建了一个可以从nagios用户执行的bash脚本。问题是这个脚本在Linux命令行中工作正常,但如果由nagios运行(在Web GUI中返回),它将返回未知状态。
我已将脚本放在nagios服务器中:
loc:/usr/local/nagios/libexec/
脚本
#!/bin/bash
rootUsage=$(du -s /root | cut -d "/" -f1)
output=$(du -s /root | cut -d "/" -f1)
if(($rootUsage<= 204800));then
echo "OK. root storage is : $output :"
exit 0
elif((204800<$rootUsage) && ($rootUsage<211111)); then
echo "WARNING. root storage is : $output"
exit 1
elif(($rootUsage >= 211111));then
echo "CRITICAL. root storage is : $output"
exit 2
else
echo "UNKNOWN. root storage given value : $rootUsage"
exit 3
fi
创建命令:
define command{
command_name check_root_space
command_line $USER1$/check_root_space
}
服务创建:
define service{
use generic-service
host_name NagiosLinuxClient
service_description Monitor Root Usage
check_command check_nrpe!check_root_space
}
Ngios clinet结束:
相同的bash脚本放在/usr/local/nagios/libexe/
目录
并且在nagios中配置了coomand,cfg文件
command[chech_root_space]=/usr/local/nagios/libexe/check_root_space
当我尝试使用以下命令从nagios服务器执行插件时
/usr/local/nagios/libexe/check_nrpe -H <ip addressofclient> -c check_root_space
最终输出:
NRPE: Command 'check_root_space' not defined