#!/usr/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/ihs/sbin/cl_lsihs.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2009,2010 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)75	1.1  src/43haes/usr/sbin/cluster/sa/ihs/sbin/cl_lsihs.sh, hacmp, 61haes_r714 11/28/11 15:00:07
# Load the common functions, logmsg, dbgmsg, errmsg, abort
. /usr/es/lib/ksh93/common_functions.ksh93

PROGNAME=$(basename ${0})
PATH="$($(dirname ${0})/../../../utilities/cl_get_path all)"
PATH=$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/sbin:/usr/es/sbin/cluster/sa/sbin
FPATH_BASE=/usr/es/lib/ksh93
FPATH=$FPATH_BASE/hacmp:$FPATH_BASE/sa:$FPATH_BASE/aix:$FPATH_BASE/aix/odm
export PATH FPATH

[[ "$VERBOSE_LOGGING" == "high" ]] && set -x

IHSSA_HOME="/usr/es/sbin/cluster/sa/ihs"
IHSSA_ETC_PATH="$IHSSA_HOME/etc"
IHSSA_SBIN_DIR="$IHSSA_HOME/sbin"

KLIB_MSGCATALOG="ihssa.cat"
KLIB_MSGSET=7

# Get the arguments.
if set -- $(getopt i:no $* 2>&1); then
    while [ $# != 0 ]; do
        case "$1" in

            -i)
                NODES=$2
                shift
                ;;

            -n)
                # lists only IBM Http Servers not managed by HACMP
                USEHACMPODM=FALSE
                ;;

            -o)
                # lists only IBM Http Servers managed by HACMP
                USEHACMPODM=TRUE
                ;;

            --)
                shift
                break
                ;;
        esac
    shift
    done
fi


header="TRUE"
found="FALSE"

typeset APPLICATION_NAME

# lists only IBM Http Servers not managed by HACMP
if [[ "$USEHACMPODM" == "FALSE" ]]; then
    
    if [[ -n $NODES ]]; then
        NODES=$(echo "$NODES" | tr ',' ' ')
        for node in $NODES ; do

            APPLICATION_NAME="IHS_"$node
            clquerysaapp -a $APPLICATION_NAME INSTALL_NODE_NAME > /dev/null 2>&1
            if (( $? != 0 )) ; then
                if [[ "$header" == "TRUE" ]]; then
                    echo "#Server"
                    header="FALSE"
                fi
                echo $node
            fi
        done
    else
        # Server data not found.
        dspmsg -s $KLIB_MSGSET $KLIB_MSGCATALOG 20 "ERROR: There is no %1\$s information in the discovery file.\n" "HTTP Server"
        exit 1  
    fi
fi


# lists only IBM Http Servers managed by HACMP
if [[ "$USEHACMPODM" == "TRUE" ]]; then

    odmget -q "sa_type=$sa_type and name=INSTALL_NODE_NAME" HACMPsa_metadata | while IFS='=' read f_name f_value; do
    f_name=$(eval echo $f_name)
    if [[ "$f_name" == "value" ]]; then
        f_value=$(echo $f_value | sed -e "s/\"//g")

        if [[ "$header" == "TRUE" ]]; then
        echo "#Server"
        header="FALSE"
        fi

        echo $f_value
        found="TRUE"
    fi
    done

    if [[ "$found" != "TRUE" ]]; then
        dspmsg -s $KLIB_MSGSET $KLIB_MSGCATALOG 100 "WARNING: IBM HTTP Server PowerHA SystemMirror Resources are not configured.\n"
    fi

    exit 0
fi
