#!/bin/sh

USAGE="log_bcnu -m message -h masterhost -a agent -e errorlevel -f filename -l loglevel"

while getopts m:h:a:e:f:l: x
do
        case $x in
        m)      message=$OPTARG;;
        h)      masterhost=$OPTARG;;
        a)      agent=$OPTARG;;
        e)      level=$OPTARG;;
        f)      filename="-f $OPTARG";;
        l)      logging=$OPTARG;;
        \?)     echo "log_bcnu : syntax error "
                echo $USAGE
                exit 2;;
        esac
done

set -- "$masterhost" "$agent" "$logging" 

. /usr/local/bcnu/etc/bcnuenv
. $BCNUHOME/agent/agent_head

case $level in
	$BCNU_WARN) BCNUMSG="$BCNU -m 'warning - $message' $filename -e $level -t $BCNUHOSTTYPE $BCNUHOST"
		bcnu_warn_send
		;;
	$BCNU_ALERT) BCNUMSG="$BCNU -m 'alert - $message' $filename -e $level -t $BCNUHOSTTYPE $BCNUHOST"
		bcnu_err_send
		;;
	$BCNU_ERR) BCNUMSG="$BCNU -m 'error - $message' $filename -e $level -t $BCNUHOSTTYPE $BCNUHOST"
		bcnu_err_send
		;;
	$BCNU_OK) BCNUMSG="$BCNU -m 'ok - $message' $filename -e $level -t $BCNUHOSTTYPE $BCNUHOST"
		bcnu_send
		;;
	$BCNU_BLACK) blackout
		;;
	*) echo "Unknown logging level"
		echo "Use levels $BCNU_OK, $BCNU_WARN, $BCNU_ERR, $BCNU_BLACK $BCNU_ALERT" 
		exit 1
		;;
esac
