#!/bin/sh

name=`basename $0`

usage () {
	echo "Usage: $name {-h|-s} [-l label] [-w warn_thres] [-c crit_thres] -d <host_or_service_ret_codes_comma_sep>"
	exit 3
}
#echo "$*" >> /tmp/trace.clus

while getopts "d:hsl:w:c:" option
do
	case $option in
		d) spec="$OPTARG" ;;
		s) type="-s" ;;
		h) type="-h" ;;
		l) label="$OPTARG" ;;
		w) warn="-w $OPTARG" ;;
		c) crit="-c $OPTARG" ;;
		*) usage ;;
		\?) usage ;;
	esac
done

if [ -z "$type" -o -z "$spec" ]; then usage; fi

OLD_IFS="$IFS"
IFS=,

for stat in $spec
do
	if [ "$stat" -eq "$stat" ] 2>/dev/null; then continue; else
		echo "The host or service specified \"$stat\" does not exist"
		exit 3
	fi
done

IFS="$OLD_IFS"

lbl=`echo $label | sed 's/ /_/g'`
label="$lbl"

#echo "/usr/local/monitoring/nagios/libexec/check_cluster $type $label -d $spec $warn $crit" >> /tmp/trace.clus
/usr/local/monitoring/nagios/libexec/check_cluster $type -l $label -d $spec $warn $crit
exit $?
