#!/bin/bash
# 
# define some defaults
MONITCONFFILES="/etc/monitrc /etc/monit.conf /etc/monit.d/*"

# include possible confie file (to override MONITCONFFILES)
[ -f /etc/nagios/check_monit.conf ] && . /etc/nagios/check_monit.conf

CRED=`grep -E '(^ +?allow.*:)' ${MONITCONFFILES} 2>/dev/null | awk '{print $NF}'`
if [ -n "${CRED}" ] ; then
	LOGIN=`echo ${CRED} | awk -F: '{print $1}'`
	PASS=`echo ${CRED} | awk -F: '{print $2}'`

	PARAMS="-u ${LOGIN} -P ${PASS}"
else
	PARAMS=""
fi
/usr/lib/nagios/plugins/check_monit.py -H localhost ${PARAMS}
exit $?
