gohopper / jmxquery

Automatically exported from code.google.com/p/jmxquery
0 stars 0 forks source link

Improve check_jms bash script to autodetect java location #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Here is an improved version of check_jmx bash script, one that will detect 
JAVA_HOME and that fails nicely when JAVA is missing.

#!/bin/sh
#
# Nagios plugin to monitor Java JMX (http://java.sun.com/jmx)attributes.
#
#RDIR=`dirname $0`
#java -cp $RDIR/jmxquery.jar org.nagios.JMXQuery $@

#!/bin/sh
JAVA_CMD=`which java`
if [ -z $JAVA_CMD ]; then
    if [ -x $JAVA_HOME/bin/java ]; then
<------>JAVA_CMD=$JAVA_HOME/bin/java
    else
<------>echo JMX CRITICAL - java not found.
<------>exit 2
    fi
fi

RDIR=`dirname $0`
OUTPUT=$($JAVA_CMD -jar $RDIR/jmxquery.jar $@)
EXIT_STATUS=$?
STATUS=`echo $OUTPUT`
VALUE=$(echo $OUTPUT | sed 's/.*{\(.*\)}.*/\1;/' | sed 's/;/; /g')
echo "$STATUS | $VALUE"

exit $EXIT_STATUS.

Original issue reported on code.google.com by sorin.sb...@gmail.com on 10 Dec 2013 at 11:55