#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2019,2020,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r720 src/43haes/usr/sbin/cluster/sa/tsmadmin/sbin/cl_tsmadminmonitor.sh 1.2.1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 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
# @(#)  7d4c34b 43haes/usr/sbin/cluster/sa/tsmadmin/sbin/cl_tsmadminmonitor.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
###############################################################################################
#
# NAME:
#       cl_tsmadminmonitor
#
# PURPOSE:
#       monitor script of Smart Assist for TSM admin center
#
# ARGUMENTS:
#               -a smart assist application name
#
# RETURNS
#  0 on success
#  1 on Failure
#
#################################################################################################

eval export $(cllsparam -n $(clodmget -f nodename HACMPcluster))
if [[ $VERBOSE_LOGGING == "high" ]]
then
    PS4_FUNC=true
    set -x
fi
. /usr/es/sbin/cluster/sa/tsmadmin/sbin/cl_tsmadminGlobals
KLIB_HACMPLOG_ENTRY=$KLIB_TSM_ADMIN_HACMPLOG_ENTRY

while getopts a: opt
do
        case $opt in

                a) # admin application name, which will be highly available
                        app_name=$OPTARG
                        ;;

        esac
done

user=$(clodmget -q "name=TSM_AC_USER and application_id=$app_name" -f value -n HACMPsa_metadata)
set +x
pass=$(clodmget -q "name=TSM_AC_PASSWORD and application_id=$app_name" -f value -n HACMPsa_metadata | /usr/es/sbin/cluster/cspoc/cldecodearg)
set -x

KLIB_SA_logmsg INFO 2 31 tsmadminsa.cat "monitoring the TSM Admin center\n"
if [[ -z $TSM_ADMIN_VERSION ]]; then
    $TSM_ADMIN_PROFILE_SCRIPTS/serverStatus.sh tsmServer -username $user -password $pass |grep STARTED >> $LOG_FILE 2>&1
else
    ps -eo 'pid,args' | grep -vw grep | grep $TSM_ADMIN_INST_DIR/ui/Liberty >> $LOG_FILE 2>&1 
fi
exit $?
