我試圖讓Nagios的執行定製的Java命令,但我總是得到錯誤126Nagios的:試圖運行自定義命令返回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是我的測試腳本和「罐子」是當前目錄,其中罐子位於
腳本是這樣的:
#!/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
並且當在控制檯手動啓動時工作完美
[[email protected] 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);
}
只要從殼我得到了啓動命令還是0:
[[email protected] plugins]# /usr/java/latest/bin/java -cp .:/usr/lib64/nagios/plugins/jars/SimpleNagiosPlugin.jar it.nagios.SimpleTest
This is an OK message
[[email protected] plugins]# echo $?
0
我還需要檢查,以確定是怎麼回事錯在這裏?
什麼是'/ usr/java/latest/bin/java -cp。:/ usr/lib64/nagios/plugins/jars/SimpleNagiosPlugin.jar it.nagios.SimpleTest'的返回代碼,即不在包裝腳本。它看起來像子進程將它的返回代碼(126)傳遞給包裝腳本。 – Gingernator007 2013-02-08 13:52:12
哼聲返回代碼應爲0,因爲我將System.exit(0)聲明爲我的java測試程序。
'[root @ bw plugins]#/ usr/java/latest/bin/java -cp。:/ usr/lib64/nagios/plugins/jars/SimpleNagiosPlugin.jar it.nagios.SimpleTest
這是一個OK消息
[root @ bw plugins]#echo $?
0' – 2013-02-08 14:16:04
當您測試它時,您是否以同一用戶身份運行它,即nrpe/nagios。或者嘗試禁用selinux來排除。 – Gingernator007 2013-02-08 15:47:22