#!/bin/ksh
# DO NOT EDIT THIS FILE
#pragma ident   "@(#)hastat_common	1.5 00/07/23  SMI"

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

MEMBERSHIP="HASTAT_CURRENT_MEMBERSHIP" 
CONFIG_STATE="HASTAT_CONFIG_STATE:" 
UPTIME_STATE="HASTAT_UPTIME_STATE:" 
LOGHOST_MASTERED="HASTAT_LOGICAL_HOSTS_MASTERED" 
LOGHOST_BACKUP="HASTAT_LOGICAL_HOSTS_BACKUP:" 
LOGHOST_MAINT="HASTAT_LOGICAL_HOSTS_MAINTENANCE"  
PRIVNET_STATUS="HASTAT_PRIV_NET_STATUS"  
PUBNET_STATUS="HASTAT_PUBLIC_NET_STATUS" 
SERVICE_STATUS="HASTAT_SERVICE_STATUS" 
RECENT_ERROR_MESG="HASTAT_RECENT_ERR_MSGS" 

MEMBERSHIP_DESC=`gettext "CURRENT MEMBERS OF THE CLUSTER"`
CONFIG_STATE_DESC=`gettext "CONFIGURATION STATE OF THE CLUSTER"`
UPTIME_STATE_DESC=`gettext "UPTIME OF NODES IN THE CLUSTER"`
LOGHOST_MASTERED_DESC=`gettext "LOGICAL HOSTS MASTERED BY THE CLUSTER MEMBERS"`
LOGHOST_BACKUP_DESC=`gettext "LOGICAL HOSTS WHICH HAVE BACKUP-NODES IN THE CLUSTER"`
LOGHOST_MAINT_DESC=`gettext "LOGICAL HOSTS IN MAINTENANCE STATE"` 
PRIVNET_STATUS_DESC=`gettext "STATUS OF PRIVATE NETS IN THE CLUSTER"` 
PUBNET_STATUS_DESC=`gettext "STATUS OF PUBLIC NETS IN THE CLUSTER"`
SERVICE_STATUS_DESC=`gettext "STATUS OF DATA SERVICES RUNNING IN THE CLUSTER"`
RECENT_ERROR_MESG_DESC=`gettext "RECENT  ERROR MESSAGES FROM THE CLUSTER"`


set -A List "${MEMBERSHIP}"  "${CONFIG_STATE}"  "${UPTIME_STATE}"  "${LOGHOST_MASTERED}"  "${LOGHOST_MAINT}"  "${PRIVNET_STATUS}"  "${PUBNET_STATUS}"  "${SERVICE_STATUS}"  "${RECENT_ERROR_MESG}" 

set -A DescList "${MEMBERSHIP_DESC}"  "${CONFIG_STATE_DESC}"  "${UPTIME_STATE_DESC}"  "${LOGHOST_MASTERED_DESC}"  "${LOGHOST_MAINT_DESC}"  "${PRIVNET_STATUS_DESC}"  "${PUBNET_STATUS_DESC}"  "${SERVICE_STATUS_DESC}"  "${RECENT_ERROR_MESG_DESC}" 

#
# Copyright 1997-1998 Sun Microsystems, Inc.  All Rights Reserved.
#
# ident   "@(#)get_ha_status.shi	1.24 01/08/27  SMI"

# This File displays the Status of High Availablity Configuration 
# in a Sun Cluster configuration.
#
# hastat_common file, which has all display formats, is prefixed to 
# this file by the Makefile


init()
{
        set -a
	integer i numnodes

        LD_LIBRARY_PATH=/opt/SUNWcluster/lib
        CLUSTERBIN=/opt/SUNWcluster/bin
        CLUSTERETC=/etc/opt/SUNWcluster
        CLUSTERVAR=/var/opt/SUNWcluster
        SSACLI=${CLUSTERBIN}/pdbssa
        PATH=$PATH:/usr/sbin:/usr/bin/:${CLUSTERBIN}:
	clustname=$(/bin/cat ${CLUSTERETC}/conf/default_clustername)
        # export CDB and LOGfile path.
        cdbfile=${CLUSTERETC}/conf/${clustname}.cdb
        cdbfilter=${CLUSTERETC}/conf/cdb.filter
        tmpdir=`enmatch env.tmpdir`
        admindir=${CLUSTERVAR}/admindir
	TMPDIR=${tmpdir}
	TMPSTATE=$TMPDIR/hastat_tmpstate.$$
	TMPERR=$TMPDIR/hastat_tmperr.$$
	TMPDB=$TMPDIR/hastat_tmpdb.$$
	TMPRDB=$TMPDIR/hastat_tmprdb.$$
	localhost=`uname -n`

	numnodes=`enmatch cluster.number.nodes`
	i=0
	allnodes=""
	while [ $i -lt $numnodes ]
	do
		allnodes="${allnodes} $i"
		i=i+1
	done

	set +a

}


function validate_env_vars
{
        set -a   

        currnodes=`${CLUSTERBIN}/clustm getcurrmembers $clustname`
        localnodeid=`${CLUSTERBIN}/clustm getlocalnodeid $clustname`
        allnodes=`${CLUSTERBIN}/clustm getallnodes ${clustname}`

	# convert currnodes to currmembers.
        currnodenames=""
        for i in ${currnodes}
        do
                name=`enmatch cluster.node.${i}.hostname`
                currnodenames="${currnodenames} ${name}"
        done

	# convert allnodes to currmembers.
        allnodenames=""
        for i in ${allnodes}
        do
                name=`enmatch cluster.node.${i}.hostname`
                allnodenames="${allnodenames} ${name}"
        done

	CCDFILE=$(${CLUSTERBIN}/ccdadm ${clustname} -w)
	ccdfile=$(${CLUSTERBIN}/ccdadm ${clustname} -w)

        set +a
}        

# lookup a value in the pdb configuration file
enmatch() {
        ${CLUSTERBIN}/cdbmatch $* ${cdbfile}
}

count_items()
{
        echo $#
}
 
get_first_item()
{
        echo $1
}

############################################################
# is_node_in_membership                                    #
#                                                          #
# Checks if the node is a cluster member                   #
# returns                                                  #
#       0 - If node is a cluster member.                   #
#       1 - If node is not a cluster member.               #
############################################################
function is_node_in_membership
{
        typeset checknode nodes
        typeset -i j

        checknode=$1

        # convert the current_nodes to current-names
        set -A nodes ${currnodenames}
        j=0
        while [ ! -z ${nodes[j]} ]
        do
                if [ ${nodes[j]} = ${checknode} ]; then
                        return 0;
                fi
                j=j+1;
        done
        return 1;

}


########################################################################
# get_the_monitor_host  <logical-host>  <backup_node>                  # 
# This function                                                        #
#       evaluates ${backup_node} to the backupnode.                    # 
########################################################################
function get_the_monitor_host
{
        typeset host loghostccd current_master nodeids default_master

        integer j
        integer anchor
        integer i

        host=$1

        # Get the CCD entry for LOGHOST.
        # XXX: should get -f <ccdfile>
        loghostccd=`${CLUSTERBIN}/scccd -f ${ccdfile} ${clustname} \
                        LOGHOST query lname ${host}`
        if [ -z ${loghostccd} ]; then
                return
        fi

        # get the current master from CCD.
        current_master=`${CLUSTERBIN}/scccd -f ${ccdfile} ${clustname} \
                        LOGHOST_CM query lname ${host} | \
                                /usr/bin/awk -F: '{ print $3 }'`

        if [ -z ${current_master} ]; then
                #log_info "$pre.4601" "Could not get LOGHOST_CM for ${host}"
                return
        fi
        # Get nodelist
        nodeids=`echo ${loghostccd} | /usr/bin/awk -F: '{ print $3}' | \
                         /usr/bin/sed 's/,/ /g'`

        # defensive check
        if [ ${current_master} = ${localhost} ]; then
                # error Should not happen
                lmsg=`gettext "Error Framework Error for loghost_sync"`
                printf "${lmsg}\n"
                return
        fi

	#
        # now that we have to get the node which is best suited
        # for backup, get the anchor for the nodeid next to the
        # current master.
	#
	# 4188241: Replaced the original algorithm which assumed that there
	#	   could only be two possible masters with this one which
	#	   doesn't. Each node in the ccdnodes array that is not the
	#	   ${current_master} is considered a "Backup Node" for the
	#	   logical host, ${host}.
	#
        set -A ccdnodes  ${nodeids}
        totalnodes=$(count_items ${nodeids})
        let i=0
	let j=0
	while (( i < totalnodes )); do
		if [[ ${ccdnodes[i]} != ${current_master} ]]; then
			is_node_in_membership ${ccdnodes[i]}
			if [[ $? == 0 ]]; then
				eval ${2}[${j}]=${ccdnodes[i]}
				(( j += 1 ))
			fi
		fi
		(( i += 1 ))
	done

        return
}

########################################################################
# get_my_backup_list                                                   #
#                                                                      #
# This function gets the list of logical host names that this physical #
# host needs to monitor (NFS) from the <List of Logical Host Names Not #
# Mastered On this Node> and stores them in BACKUP_LOGICAL_HOSTS       #
# Environment Variable: BACKUP_LOGICAL_HOSTS                           # 
########################################################################
function get_my_backup_list
{
	typeset logical_list i backup_node
	integer j
	set -a
	logical_list=$1
	set +a

	for i in ${logical_list}
	do
		# 4188241: Make ${backup_node} an array
		set -A backup_node ""
		get_the_monitor_host ${i} backup_node

                # we do not have the backupnode for this.
                if [ -z "${backup_node[*]}" ]; then
                        continue;
                fi

		#
		# 4188241: Replaced the original algorithm which assumed that
		#	   there could only be two possible masters with this
		#	   one which doesn't. ${backup_node} has been converted
		#	   to an array which returns the list of possible
		#	   "Backup Nodes".
		#
		let j=0
		while [[ -n "${backup_node[${j}]}" ]]; do
			if [[ ${backup_node[${j}]} == ${localhost} ]]; then
				BACKUP_LOGICAL_HOSTS="${BACKUP_LOGICAL_HOSTS} ${i}"
				break
			fi
			(( j += 1 ))
		done
        done
}

send_message()
{
	typeset message

	message=$*
	echo "${message}"
}


exit_from_hastat()
{
	echo "hastat:over"
	exit 0
}

config_state()
{
	#
	# First Determine if this is node is running as part of
	# the cluster.
	#
	send_message ${CONFIG_STATE}

	${CLUSTERBIN}/timed_run -q 3 ${CLUSTERBIN}/clustm getstate \
                        ${clustname} >/dev/null 2>&1 

	if [ $? -ne 0 ]; then
		# Node is not running as a part of the Cluster.
                lmsg1=`gettext "     Configuration State on %s : %s"`
                printf "${lmsg1}\n" "${localhost}" "Down" 
		send_message ${CONFIG_STATE}
		send_message "${MEMBERSHIP}"
                lmsg2=`gettext "     %s not a cluster member"`
                printf "${lmsg2}\n" "${localhost}" 
		send_message "${MEMBERSHIP}"
		return
	fi

	# Since it a part of the Cluster Validate ENV vars.

	validate_env_vars
	res=`${CLUSTERBIN}/clustm getstate ${clustname} 2>/dev/null`
	set -a
	if [ ${res} != "end" ]; then
		state="Reconfiguring"
	else
		state="Stable"
	fi

	set +a

        lmsg1=`gettext "     Configuration State on %s: %s"`
        printf "${lmsg1}\n" "${localhost}" "${state}" 
	send_message "${CONFIG_STATE}"
	send_message "${MEMBERSHIP}"
        lmsg2=`gettext "     %s is a cluster member"`
        printf "${lmsg2}\n" "${localhost}"
	send_message "${MEMBERSHIP}"

}


machine()
{
   typeset machine_result

   machine_result=`/usr/bin/uptime`
   send_message "${UPTIME_STATE}"
   lmsg1=`gettext "     uptime of %s: "`
   printf "${lmsg1}" "${localhost}" 
   send_message "       ${machine_result}"
   send_message "${UPTIME_STATE}"

}


logical_hosts()
{
	#
	# Print Results Only if state=Stable
	#
	send_message "${LOGHOST_MASTERED}"
	if [ "$state" != "Stable" ]; then
                lmsg1=`gettext "     %s is not a cluster member"`
                printf "${lmsg1}\n" "${localhost}"
		send_message "${LOGHOST_MASTERED}"
                return
        fi

	#
	# 4188241: This was changed from the original code because the original
	#	   code assumed that there could be at most 2 logical hosts.
	#
	#	   This fix assumes that echo strips newlines from the string
	#	   being echoed.
	#
	scratch=$(${CLUSTERBIN}/haget -f mastered)
	mastered_list=$(echo ${scratch})
	scratch=$(${CLUSTERBIN}/haget -f not_mastered)
	not_mastered_list=$(echo ${scratch})

	lmsg1=`gettext "Logical Hosts Mastered on %s:"`
	printf "${lmsg1}\n" "${localhost}"
	if [ "${mastered_list}" = "" ]; then
		send_message "        None"
	else
		send_message "        ${mastered_list}"
	fi

	#
	# Get the List of Logical Hosts for which this node is
	# the Backup
	# XXX: Finally should have a call "haget -f me_backup"
	# XXX: Also need to add logical host in maintenance state.
	#
	get_my_backup_list "${not_mastered_list}"
	lmsg1=`gettext "Logical Hosts for which %s is Backup Node:"`
	printf "${lmsg1}\n" "${localhost}"
	if [ -z "${BACKUP_LOGICAL_HOSTS}" ]; then
		send_message "        None"
	else
		send_message "       ${BACKUP_LOGICAL_HOSTS}"
	fi
	send_message "${LOGHOST_MASTERED}"

	allinfo=$(${CLUSTERBIN}/scccd -f ${CCDFILE} ${clustname} \
		LOGHOST_MSTATE query mmode 0)
	if [ "${allinfo}" !=  "" ]; then
		send_message "${LOGHOST_MAINT}"
		echo         "        \c"
		for i in ${allinfo}
		do
			lname=`echo ${i} | awk -F: ' {print $2} '`
			echo "${lname} \c"
		done
		echo ""
		send_message "${LOGHOST_MAINT}"
	fi
	
}

interconnect_status() {

	typeset i active_file select_file select net0 net1

        net0=unknown
        net1=unknown

        if [  -r ${cdbfile} ] ; then
                active_file=`${CLUSTERBIN}/cdbmatch ccm.script.topnet.file ${cdbfile}`
                select_file=`${CLUSTERBIN}/cdbmatch ccm.script.net.file ${cdbfile}`

                if [ -f ${active_file} -a -f ${select_file} ] ; then
                        #  find which nets are up by looking at active file contents
                        #  active file contents can be:
                        #               0 1
                        #               0
                        #               1
                        for i in `/bin/cat ${active_file}`
                        do
                                case "${i}" in
                                        '0') net0=up
                                                ;;
                                        '1') net1=up
                                                ;;
                                        *)
                                                ;;
                                esac
                        done

                        #  set the nets that aren't up to be down
                        #  active file only contains up nets
                        if [ "$net0" = "unknown" ] ; then
                                net0=down
                        fi
                        if [ "$net1" = "unknown" ] ; then
                                net1=down
                        fi

                        #  find selected net from select file
                        #  only nets that are up can be selected
                        #  select file contain one char (0 or 1) to
                        #  designate selected net
                        select=`/bin/cat ${select_file}`
                        if [ "X${select}" = "X0" ] ; then
                                if [ "${net0}" = "up" ] ; then
                                        net0=selected
                                fi
                        elif [ "X${select}" = "X1" ] ; then
                                if [ "${net1}" = "up" ] ; then
                                        net1=selected
                                fi
                        fi

                fi
        fi
        lmsg1=`gettext "        interconnect0: %s"`
        lmsg2=`gettext "        interconnect1: %s"`
        printf "${lmsg1}\n${lmsg2}\n" "${net0}"  "${net1}"

}

priv_nets()
{
	typeset name i
	typeset privateIP

	send_message "${PRIVNET_STATUS}" 
        lmsg1=`gettext "     Status of Interconnects on %s:"`
        printf "${lmsg1}\n" "${localhost}"
	interconnect_status

        lmsg2=`gettext "     Status of private nets on %s:"`
        printf "${lmsg2}\n" "${localhost}"
	#
	# From allnode in the cluster, get the hahost for that
	# node. It gives up the IP address.
	# Then Ping it , if it succeeds then Private Nets Are UP.
	# (XXXX: In future if we have failure fencing if ports then
	# i would suggest that we display this information only 
	# when required.
	#
	for i in ${allnodes}
	do
		name=`enmatch cluster.node.${i}.hostname`
		privateIP=`enmatch cluster.node.${i}.hahost`

		/usr/sbin/ping -n ${privateIP} 2 >/dev/null 2>&1

		RC=$?
	
		if [ ${RC} -ne 0 ]; then
			/usr/sbin/ping -n ${name} 2 >/dev/null 2>&1
			if [ $? -eq 0 ]; then
				send_message "        To ${name} - Down" 
			else
				send_message "        To ${name} - Unknown" 
			fi
		else
				send_message "        To ${name} - UP" 
		fi
	done
	send_message "${PRIVNET_STATUS}" 

}


pub_nets()
{
	#
	# Will PNMSTAT to the status of all adapters..
	# Sundeep Has told me that he will provide it.
	#
	send_message "${PUBNET_STATUS}"
	if [ "$state" != "Stable" ]; then
                lmsg1=`gettext "Status of Public Network On %s:"`
                printf "${lmsg1}\n\n" "${localhost}"  
                lmsg2=`gettext "     Public Net Monitoring Not running on %s"`
                printf "${lmsg2}\n" "${localhost}" 
		send_message "${PUBNET_STATUS}"
		return
	fi
        lmsg1=`gettext "Status of Public Network On %s:"`
        printf "${lmsg1}\n\n" "${localhost}"
	/usr/bin/pkginfo SUNWpnm >/dev/null 2>&1
	RC=$?

	if [ ${RC} -eq 0 ]; then
		# PNM packages are present, so use pnmstat -a
		# should display  it.
		# /opt/SUNWpnm/bin/pnmstat -a
		/opt/SUNWpnm/bin/pnmstat -l 2>/dev/null
	else
		#
		# PNM package is not present , so cannot do much
		#
                lmsg1=`gettext "     No Public Network status support as of Now"`
                printf "${lmsg1}\n"
	fi
	send_message "${PUBNET_STATUS}"
}


data_services()
{
	typeset newlist
	typeset row


        #
        # Only print results if state=Stable.
        #
	send_message "${SERVICE_STATUS}"

        lmsg1=`gettext "Status Of Data Services Running On %s"`
        printf "${lmsg1}\n" "${localhost}"

        if [ "$state" != "Stable" ]; then
                lmsg1=$(gettext 'No Data Services are running')
                printf "       ${lmsg1}\n"
		send_message "${SERVICE_STATUS}"
                return
        fi


	#
	# For each service that is ON in the Cluster.
	# Get the List of logical hosts Mastered.
	# And Also for which this node is the Backup which are
	# offering the services.
	# Call the Status routines. for the same
	# (now only for NFS etc..)
	#
	allinfo=$(${CLUSTERBIN}/scccd -f ${CCDFILE} ${clustname} DS_INFO \
			query ds_name "")

	allsvcon=""
	for i in ${allinfo}
	do
		svc=`echo ${i} | /bin/awk -F: ' {print $2} '`
		TEST=`haget -f service_is_on -s ${svc} 2>/dev/null`
		if [ ! -z "${TEST}" -a ${TEST} -ne 1 ]; then
			continue;
		fi
		allsvcon="${allsvcon} ${svc}"
	done

	if [ "${allsvcon}" = "" ]; then
		printf "       $(gettext 'None running').\n"
		send_message "${SERVICE_STATUS}"
		return
	fi

	for i in ${allsvcon}
	do
		svc=${i}

		mastered_list=`haget -f mastered`

		rows=$(scccd -f ${CCDFILE} ${clustname} \
		    LOGHOST_DS query dsname ${svc})
		newlist=""
		for r in ${rows}; do
			loghost_name=${r%:*}
			loghost_name=${loghost_name#*:}
			cm_row=$(${CLUSTERBIN}/scccd -f ${CCDFILE} \
			    ${clustname} LOGHOST_CM query lname ${loghost_name})
			cm=${cm_row#*:*:}
			if [ "${cm}" = "${localhost}" ]; then
				newlist="${newlist} ${loghost_name}"
			fi
		done
		if [ "${newlist}" = "" ]; then
			lmsg1=`gettext "       Data Service \"%s\":"`
			printf "${lmsg1}\n" "${svc}"
			lmsg2="       $(gettext \
			    'Not being managed on this system')"
			printf "${lmsg2}\n" 
				continue;
		fi

		case ${svc} in
		nfs)
			lmsg1=`gettext "       Data Service \"nfs\":"`
			printf "${lmsg1}\n"
			
			/opt/SUNWcluster/ha/nfs/nfs_stat "${newlist}"
			echo ""
			;;
		
                oracle|sybase|informix)
			lmsg1=`gettext "       Data Service \"%s\":"`
			printf "${lmsg1}\n" "${svc}"
			DBMS_SIDS=`${CLUSTERBIN}/${i}_status_svcs`
			if [ "$DBMS_SIDS" != "" ]; then
				lmsg1=`gettext "       Database Status on %s:"`
				printf "${lmsg1}\n" "${localhost}"

				if [ "${svc}" = "oracle" ]; then
                                        hasvc=HAORACLE
					instance=instancename
                                elif [ "${svc}" = "sybase" ]; then
                                        hasvc=HASYBASE
					instance=server
                                else
                                        hasvc=HAINFORMIX
					instance=onconfig
                                fi

				for j in $DBMS_SIDS; do
					echo "        $j - \c"

                # verify that logical host for the database instance
                # is mastered by localhost before running $i_status

                                        row=`${CLUSTERBIN}/scccd -f ${ccdfile} ${clustname} ${hasvc} query ${instance} ${j}`
                                        loghost_name=`echo "${row}"|/usr/bin/awk -F":" '{print $4}'`
                                        print $mastered_list|/usr/bin/grep $loghost_name > /dev/null
                                        if [[ $? == 0 ]]; then
						res=`${CLUSTERBIN}/${i}_status $j`
						echo "${res}; "
					else
						lmsg2=" $(gettext \
                                                'Not being managed on this system')"
                                                printf "${lmsg2}\n"
                                        fi

				done
			fi
			echo ""
			;;

		sap)
			lmsg1=`gettext "       Data Service \"sap\":"`
			printf "${lmsg1}\n"
			
			/opt/SUNWcluster/ha/sap/sap_status "${newlist}"
			echo ""
			;;

		*)
			lmsg1=`gettext "       No Status Method for Data Service \"%s\""`
			printf "${lmsg1}\n\n" "${svc}"
			;;

		esac
	done
	send_message "${SERVICE_STATUS}"

}


recent_err_msgs()
{
	send_message	"${RECENT_ERROR_MESG}"
        lmsg1=`gettext "Recent Error Messages on %s"`
        printf "${lmsg1}\n\n" "${localhost}"
	/bin/egrep -i 'SUNWcluster:.*notice:|warning|error|fatal|4???|[^a-zA-Z] (soc|pln|ssd|sd)[^a-zA-Z]|[^a-zA-Z](be|le|qe|hme|nf)[0-9]+:|ID[.*SUNWcluster.*\]:'  /var/adm/messages | /bin/tail -${recent_err_lines}
	send_message    "${RECENT_ERROR_MESG}"
}

get_hostnames()
{
	typeset i filelist list commalist list1
	
	# Following sentence is indicates the start of of net info
	# haopen() depends on this string for processing. So do not
	# change the sentence. 
	echo "LIST OF NAMES ON NETWORK"

        list=""
        filelist=$(/usr/bin/ls /etc/hostname.*[0-9])
        for i in ${filelist}
        do
                if [ -z ${list} ]; then
                        list=$(/usr/bin/cat ${i})
                else
                        list="${list} $(/usr/bin/cat ${i})"
                fi
        done

	#
	# ATM lan emulation do not put the entries in
	# /etc/hostname.* ; They remove these entries in
	# S00sunatm in /etc/rc2.d
	# Format of /etc/atmconfig (see man page of atmconfig)
	#
	# Physical-Interface Uni-Ver C-IPHost LaneInstance LaneHost
	#
	# See more information in man page of "atmconfig(4)" in 
	# /opt/SUNWatm/man/man4.

	# This will gather all the Lan Emulation Host.
	if [ -f /etc/atmconfig ]; then
	  list1=`grep -v \^# /etc/atmconfig | grep "ba[0-9]" | \
        	awk ' $5 != "-" { print $5 } '`
	  list="${list} ${list1}"
	fi

	# This code below will gather all the Classical Ip Host
	if [ -f /etc/atmconfig ]; then
	  list1=`grep -v \^# /etc/atmconfig | grep "ba[0-9]" | \
        	awk ' $3 != "-" { print $3 } '`
	  list="${list} ${list1}"
	fi

        # Remove all unnecessary blanks
        # The requester expects a comma seperated list
        commalist=""
        for i in ${list}
        do
                if [ -z ${commalist} ]; then
                        commalist=${i}
                else
                        commalist="${commalist},${i}"
                fi
        done
        echo ${commalist}
}

#
# First set the PATH so that we can execute all our functions.

# for oracle
_oraclepath=/opt/SUNWcluster/ha/oracle
# for normal path and bin
PATH=/usr/sbin/:/usr/bin/:/sbin/:/bin/:${_oraclepath}:/opt/SUNWcluster/bin:/opt/SUNWcluster/ha/nfs/:

argv0=$(/bin/basename $0)
res=$(/bin/id)
if [ `expr "$res" : "uid=\([0-9]*\)("` != 0 ] ; then
        lmsg1=`gettext "%s must be executed as super-user."`
        printf "${lmsg1}\n" "${argv0}" >&2
        exit 1
fi

trap "/bin/rm -f $TMPSTATE $TMPERR $TMPDB $TMPRDB; exit_from_hastat; exit" 1 2 13 15

arg1=$1

# If this is only to find hostnames
if [ "${arg1}" == "-hostname" ]; then
	get_hostnames
	exit_from_hastat
fi

if [ "${arg1}" = "" ]; then
	recent_err_lines=10
else
	recent_err_lines=${arg1}
fi

init
echo ""

config_state

machine
priv_nets

logical_hosts
pub_nets
data_services
recent_err_msgs
exit_from_hastat
