Can't execute a Nagios plugin written by java code

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
microxuzh
Posts: 5
Joined: Tue Oct 29, 2013 12:55 am

Can't execute a Nagios plugin written by java code

Post 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?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

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

Post 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.
microxuzh
Posts: 5
Joined: Tue Oct 29, 2013 12:55 am

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

Post by microxuzh »

Dear ssax,

It works now, thanks for your help.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

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

Post by tmcdonald »

I'll be closing this thread now, but feel free to open another if you need anything in the future!
Former Nagios employee
Locked