Nagios java plugins


#1

I have a couple of java classes that check various things on my network/systems.

I can quickly modify them to comply with the return values needed by nagios.

2 questions:

  1. how do I call these java plugins from nagios?
  2. how will the jvm be handled if I have several of these java plugins running?

#2

You can combine this in order to achieve what you want:
saloon.javaranch.com/cgi-bin/ubb … 3&t=001766


#3

Thank you.

I will play around with it a bit and report back on the jvm question - if anyone else does not answer it.


#4

This technique is not working. All I get back is a warning for that service, with the status info messageas: (null)

calling: java -cp MyJar.jar MyClass directly results in CRITICAL: (Return code of 127 is out of bounds - plugin may be missing) .

Am I correct in assuming that when you call the shell script, nagios is reading the shell script’s output and return code instead of the java that is being called from the shell script?

Can anyone suggest an alternative solution?


#5

Yes, Nagios looks at the shell script output and it’s exit code. What you could do in a shell script is to redirect output of java plugin and java plugin exit code to some shell script variables and then use them as the shell output. For example:

[code]#!/bin/bash

output=java_plugin
exitcode=$?

echo $output
exit $exitcode[/code]


#6

[quote=“Albin”]
What you could do in a shell script is to redirect output of java plugin and java plugin exit code to some shell script variables and then use them as the shell output.[/quote]

Perfect. This solves my problem of calls from nagios to java.

For now I will solve my problem of multiple calls to java creating multiple vm’s by making one call to java that will do all the checks and log them, and then have separate checks getting the results from the logs.
I was suggested (elsewhere) that I run the java tests in a continuous loop elsewhere, with a sleep timer, and then testing those logs. But I think I prefer to have nagios call the java test and get a result to see if all the tests completed.

Thanks again for your time and your help.