Reputation: 533
I'm trying to get Nagios to execute a custom java command but I always get error 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.
Now I've checked few things but as I'm a newbie here I probably missed something. Here few information about the environment:
-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 is my test script and "jars" is the current dir where the jar is located
Scripts is this:
#!/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
and is working perfectly when launched manually at console
[root@bw plugins]# ./test_java_plugin.sh
0: This is an OK message
Forgot to add command definition:
# 'test_java_plugin' command definition
define command{
command_name test_java_plugin
command_line $USER1$/test_java_plugin.sh
}
Also as as per request into comment I'm adding also the current java code of my test class
public static void main(String[] args) {
System.out.println("This is an OK message");
System.exit(0);
}
Just launching the command from a shell I got still 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
What else should I check to determine what is going wrong here?
Upvotes: 1
Views: 5041
Reputation: 433
I faced a similar issue and found that SELinux was blocking me. The same can be checked in /var/log/audit/audit.log
If you get denied errors for nagios_t/nagios_system_plugin_t, add them to the permissive list of selinux using the below command rather than turning it off completely
semanage permissive -a nagios_t
Upvotes: 3
Reputation: 347
Error 126 Means that the plugin was found but not executable.
You can try 2 things. Try running the plugin as nagios user and check for the error.
or
This did work out for one issue i had. Try it out. hopefully it may work
/bin.bash -l -c "/#{path to plugin}/test_java_plugin.sh"
Upvotes: 1
Reputation: 346
you should try to run test_java_plugin.sh as nagios user, you can give nagios a shell (temporary) . Take into account that the root environment is different from the nagios environment . When running test_java_plugin.sh as nagios , you can add "env > env_log_file" to see what is the environment during the run time.
Good luck.
Upvotes: 1