#!/bin/sh
# Configure this:
nrpecfg=/etc/nagios/nrpe.cfg

# Main routine
if [ ! -f "$nrpecfg" ] ; then
	echo "$nrpecfg not found"
	exit 1
fi

if [ $# -lt 1 ] ; then
	echo "Usage: $0 command"
	echo "  where 'command' is an entry in nrpe.cfg."
	exit 2
fi

option=$1
shift

command=`sed -ne "s/^command\[$option]=\(.*\)/\1/p" <$nrpecfg`
if [ -z "$command" ] ; then
	echo "'$option' not found in $nrpecfg"
	exit 3
fi

com=`echo $command | cut -f1 -d' '`
if [ ! -x $com ] ; then
	echo "$com not executable"
	exit 4
fi

if `$com --help | grep -q -- -t` ] ; then
	output=`$command -t 15000`
	rval=$?
else
	output=`$command`
	rval=$?
fi

echo "`date +%s`;`hostname -s`;$option;$rval;$output"

