#! /bin/ksh
#
# ident	"@(#)sap_status.shi	1.4	99/10/18 SMI"
#
# Copyright (c) 1997-1999 by Sun Microsystems, Inc.
# All rights reserved.
#

#
# Usage: sap_status LogicalHosts
#
# Called from hastat to get status of SAP

# Define msg. file name and location
TEXTDOMAIN=sap_status;  export TEXTDOMAIN
TEXTDOMAINDIR=/opt/SUNWcluster/locale;  export TEXTDOMAINDIR

nodeloghosts="$1"

# source in ha-services common utilities
. /opt/SUNWcluster/bin/hads_utilities

SYSLOG_PREFIX="SUNWcluster.ha.sap"

# Set varible for the HA-SAP configuration file
HASAP_CONFIG_FILE=/etc/opt/SUNWscsap/hadsconf

if [ ! -f "${HASAP_CONFIG_FILE}" ]; then
	lmsg1=`gettext "       SAP is not yet configured"`
	printf "${lmsg1}\n"
	exit 0
fi

#
# Call the parser to handle the config file.
#
source_env_file $HASAP_CONFIG_FILE
if [ $? -ne 0 ]; then
	lmsg1=`gettext "       SAP is not configured properly"`
	printf "${lmsg1}\n"
        exit 0
fi

for i in $_INST_LIST; do
    
	# Check Logical Host
	instloghost=`get_config_param $i LOGICAL_HOST`

	is_member "${instloghost}" "${nodeloghosts}"
	if [ $? -ne 0 ]; then
		# The SAP loghost is not mastered here
		lmsg1=`gettext "       SAP Instance %s is not being managed on this system"`
		printf "${lmsg1}\n" "${i}"
		continue
	fi

	ha_svc_not_running "${i}.probe"
	if [ $? -eq 0 ]; then
		lmsg1=`gettext "       SAP Instance %s is not monitored"`
		printf "${lmsg1}\n" "${i}"
	else
		lmsg1=`gettext "       SAP Instance %s is monitored"`
		printf "${lmsg1}\n" "${i}"
	fi

done

exit 0

