#!/usr/bin/ksh
##
## Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
##
## @(#)esmsyslog	1.2 01/08/04
##

# This script should be run as root, to enable or disable the logging of
# alarms to the syslog.

usage () {
    echo "usage: $SCRNAME enable | disable

    where:
	enable	Turn on logging of alarms to syslog
	disable	Turn off logging of alarms to syslog
"
    exit 1
}

SCRIPT=$0
SCRNAME=`/bin/basename $SCRIPT`

if [ $# -ne 1 ]; then
    usage
fi

command=$1
if [ "$command" != "enable" -a "$command" != "disable" ]; then
    usage
fi

if [ "$command" = "enable" ]; then
    sqlfile="createalarmlog.sql"
else
    sqlfile="dropalarmlog.sql"
fi


ESM_BASE=`/usr/bin/pkgparam SUNWstm ESM_BASE`
if [ $? -ne 0 ]; then
   ESM_BASE=/opt/SUNWstm
fi
SSTR_HOME=$ESM_BASE/sssm
SSTR_DBHOME=$SSTR_HOME/util/pgsql
SSTR_DBBIN=$SSTR_DBHOME/nsm1/bin
SSTR_DBSTART=$SSTR_DBBIN/dbstart.sh
SSTR_DBOWNER=sstr001
SSTR_PSQL=$SSTR_DBHOME/bin/psql

if [ -f $SSTR_DBHOME/nsm1/data/postmaster.pid ]; then
    /usr/bin/su - $SSTR_DBOWNER -c ". $SSTR_DBBIN/postgres.env; $SSTR_PSQL -f $SSTR_DBHOME/nsm1/ddl/$sqlfile" > /dev/null 2>&1
    echo "sending alarms to syslog ${command}d"
else
    echo "ERROR: The database is not running.  Please restart ESM with
	'$ESM_BASE/bin/esmcontrol start' and run this command again."
    exit 2
fi
