Page 1 of 1

Can't execute a Nagios plugin written by java code

Posted: Thu Mar 05, 2015 9:38 am
by microxuzh
Java Code:
public class check_health{
public static final int OK=0;
public static void main(String args[]){
System.out.println("System OK - Works fine!");
System.exit(OK);
}
}

bash shell:
#!/bin/bash
export JAVA_HOME=/usr/java/jdk1.7.0_40
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
java check_health

This plugin works fine in terminal but got error message in Nagios Core:
(No output on stdout) stderr: Error: Could not find or load main class check_health

Any idea?

Re: Can't execute a Nagios plugin written by java code

Posted: Thu Mar 05, 2015 1:15 pm
by ssax
I was able to replicate the issue and able to resolve it by passing the class path.

Please change the last line on your bash script from:

Code: Select all

java health_check
To:

Code: Select all

java -cp /usr/local/nagios/libexec check_health
Let us know if that works for you.

Re: Can't execute a Nagios plugin written by java code

Posted: Thu Mar 05, 2015 8:43 pm
by microxuzh
Dear ssax,

It works now, thanks for your help.

Re: Can't execute a Nagios plugin written by java code

Posted: Fri Mar 06, 2015 11:23 am
by tmcdonald
I'll be closing this thread now, but feel free to open another if you need anything in the future!