I''m using Winrpe-3.1.0 and I'm trying to confirure in a custom check that I wrote in Java. The program scans multiple user specified directories looking for the oldest file that is older than a user specified time. If this is the first time the file is returned a warning message and status are returned. If this is the second time the file is returned a critical message and status are returned. The java program works perfectly from JNRPE, but our IT staff favors Winrpe; therefore, how do I configure Winrpe to execute a java program.
My program is in an executable jar called "NagiosFileAge.jar". I created an entry in nrpe.cfg that looks like the following line:
command[run_test]="c:\Program Files\Java\jre7\bin\java.exe" -jar c:\NagiosFileAge.jar c:\aaa\PrevCheck c:\tmp
When I try executing the test from Nagios with "check_nrpe -H <my_test_ip> -c run_test" I get back "NRPE: Unable to read output". I replaced the command above with a call to a simple "cmd" file that echoes "Everything is working" and when I execute "check_nrpe -H <my_test_ip> -c run_test" this time I get back ""Everything is working". I've tested the "exe" files and some "cmd" files, but trying to execute a java program is not working.
I have several java monitoring programs that would benefit by being integrated into Nagios, but I really don't want to rewrite these programs to C. Any help on this would be appreciated.
Your problem can be related to the fact that Winrpe is based on Cygwin, which has its own path-conventions. Cygwin equivalent of c:\Program Files\Java\jre7\bin\java.exe is /cygdrive/c/Program Files/Java/jre7/bin/java.exe. Escaping backslashes can also be necessary. Try following command:
command[run_test]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar c:\\NagiosFileAge.jar c:\\aaa\\PrevCheck c:\\tmp
If Java/bin is in the system path, you can simply specify java.exe directly.
Your suggestion seemed reasonable so I tried it, but it didn't work. Just to make sure the command invocation was the correct value in Cygwin, I copied your command, opened up my Cygwin terminal, pasted it in, ran it, and it worked perfectly. I pasted the same command into my windows nrpe.cfg file and it didn't work when I tried to called it remotely. From the same Cygwin terminal I used earlier, I tried calling: "/cygdrive/c/Program Files (x86)/ICW/bin/check_nrpe.exe" -H 127.0.0.1 -c run_test. It returned: NRPE: Unable to read output.
I don't understand why the command won't work locally when calling it from check_nrpe. Any thoughts or suggestion are appreciated.
When you run the command directly from a Cygwin terminal, you use credentials of the user logged in with admin privilges possibly. When you try the same via winrpe, it is run by the service account SvcInet, which has privileges of an ordinary normal user. It may help to give that account admin privileges.
I give that a try. Thank you!
21 Aug 2013
I used the following command and it worked:
command[run_test]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar NagiosFileAge.jar 5 /cygdrive/c/aaa/PrevCheck /cygdrive/c/tmp
I installed the jar file in the "C:\Program Files (x86)\ICW\" folder. Note the file path prefix of "/cygdrive/c/" was using to specified all of the file/directory locations except for the jar. I don't understand why?
Is cygwin required if I want to reun java from this plugin?
Sorry for the delay getting back to you. Must I have Cygwin installed on the Windows machine if I want to run a java program via Windows NRPE?
I was able to get the java program to run using command[run_t]. The following are all of the commands I tested:
command[run_t]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar /NagiosFileAge.jar 5 /cygdrive/c/aaa/PrevCheck /cygdrive/c/tmp
command[run_t2]="c:\Program Files\Java\jre7\bin\java.exe" -jar \aaa\NagiosFileAge.jar 5 \aaa\PrevCheck \tmp
command[run_t3]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar c:\\aaa\\NagiosFileAge.jar 5 c:\\aaa\\PrevCheck c:\\tmp
command[run_t4]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar /cygdrive/c/aaa/NagiosFileAge.jar 5 c:\\aaa\\PrevCheck c:\\tmp
command[run_t5]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar /cygdrive/c/NagiosFileAge.jar 5 c:\\aaa\\PrevCheck c:\\tmp
command[run_t6]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar /cygdrive/c/NagiosFileAge.jar 5 /cygdrive/c/aaa/PrevCheck /cygdrive/c/tmp
command[run_t7]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar /cygdrive/c/NagiosFileAge.jar 5 c:\\aaa\\PrevCheck c:\\tmp
run_t is the only one that worked. Note the only difference between run_t and run_t6 is where I placed the jar file. I had to move the jar file into cygwin's root folder.
I was able to get it to work with the following command:
command[run_t]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar NagiosFileAge.jar 5 /cygdrive/c/aaa/PrevCheck /cygdrive/c/tmp
Note that all file references except for the jar file use "/cygdrive/c/...". I tried using "cygdrive/c/..." for the jar file and that did not work. What really made this work was placing the jar file in the <nagios_installdir> and leaving off the path to the jar.
I find it curious that the "/cygdrive/c/..." path prefix was required by everything except the jar and I find it curious that the default folder for the jar is the <nagios_installdir>. Can anyone explain this?
I was able to get it to work with the following command:
command[run_test]="/cygdrive/c/Program Files/Java/jre7/bin/java.exe" -jar NagiosFileAge.jar 5 /cygdrive/c/aaa/PrevCheck /cygdrive/c/tmp
Notice that I used the path prefix of "/cygdrive/c/" for everything except 5 and the jar file. I placed the jar file in "C:\Program Files (x86)\ICW\" and this worked. If I tried to prefix the jar path with "/cygdrive/c/" it would not work.
I have two questions:
1. Why does the jar file not use the file prefix when the other entries do?
2. Must you have CYGWIN installed on the Windows machine to use the file prefix "/cygdrive/c/" ?
Must Cygwin be installed on the Windows machine to use the file path prefix of "/cygdrive/c/"?
Must CYGWIN" be installed on the Windows machine in order to use the file path prefix of "/cgydrive/c/"?
Is CYGWIN required to run a java program via this plugin?
Is CYGWIN required to run JAVA from plugin?