#!/bin/sh

plugins=/usr/local/monitoring/nagios/libexec
port=9666
timeout=60

if [[ "$#" -ne "1" ]]; then echo "Usage: check_nrpe_agent <hostname>"; exit 3; fi

host=$1
out=`${plugins}/check_nrpe -t $timeout -H $host -p $port 2>&1`
stat=$?

if [[ "$stat" -gt "3" ]]; then
	stat=2
fi

out=`echo "$out" | sed 's/^\(CHECK_NRPE: Socket timeout\|Connection refused\|connect.*No route to host\).*$/The NRPE Agent is **NOT** responding!!! Do **NOT** ignore!/'`

echo $out
exit $stat
