我试图让 Nagios 执行自定义 java 命令,但我总是收到错误 126。
[1360324906] Warning: Return code of 126 for check of service 'Java Process Test' on host 'localhost' was out of bounds.Make sure the plugin you're trying to run is executable.
现在我检查了几件事,但由于我是这里的新手,我可能错过了一些东西。这里有一些关于环境的信息:
-rwxr-xr-x. 1 root root 2938 Aug 17 15:39 check_wave
drwxr-xr-x. 2 root root 4096 Jan 13 15:08 eventhandlers
drwxr-xr-x. 2 root root 4096 Feb 7 17:22 jars
-rwxr-xr-x. 1 root root 38696 Aug 17 15:39 negate
-rwxr-xr-x. 1 root root 886 Feb 8 12:47 test_java_plugin.sh
test_java_plugin.sh 是我的测试脚本,“jars”是 jar 所在的当前目录
脚本是这样的:
#!/bin/bash
#This will get the output of process
output=$(/usr/java/latest/bin/java -cp .:/usr/lib64/nagios/plugins/jars/SimpleNagiosPlugin.jar it.nagios.SimpleTest)
#This will catch the result returned by last process that is our java command
java_result=$?
echo "$java_result: $output"
exit $java_result
并且在控制台手动启动时运行良好
[root@bw plugins]# ./test_java_plugin.sh
0: This is an OK message
忘记添加命令定义:
# 'test_java_plugin' command definition
define command{
command_name test_java_plugin
command_line $USER1$/test_java_plugin.sh
}
此外,根据评论中的请求,我还添加了我的测试类的当前 java 代码
public static void main(String[] args) {
System.out.println("This is an OK message");
System.exit(0);
}
刚从 shell 启动命令我还是 0:
[root@bw plugins]# /usr/java/latest/bin/java -cp .:/usr/lib64/nagios/plugins/jars/SimpleNagiosPlugin.jar it.nagios.SimpleTest
This is an OK message
[root@bw plugins]# echo $?
0
我还应该检查什么来确定这里出了什么问题?