#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 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/sap/sbin/cl_sapMonitorAS.sh 1.3.1.4 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2008,2015 # 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/sap/sbin/cl_sapMonitorAS.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM ## ## NAME: cl_sapMonitorAS ## ## PURPOSE: ## Monitoring script for AS instance. ## ## ARGUMENTS: ## ## Type: ## -a Application ID ## ## ## OUTPUT: ## ## ## RETURNS: ## 0 on success ## 1 on failure ## . /usr/es/lib/ksh93/func_include #---------------------------------------------------------------------------- # Global Definitions #---------------------------------------------------------------------------- . /usr/es/sbin/cluster/sa/sap/etc/SAPGlobals . /usr/es/sbin/cluster/sa/sap/sbin/SAPUtilities typeset PROGRAM=${0##*/} PATH=$PATH:/usr/es/sbin/cluster/sa/sbin PATH=$(/usr/es/sbin/cluster/utilities/cl_get_path all) export PATH #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # Function: # checkIsASRunning # # Purpose: # To Monitor SAP AS instance processes using sapcontrol for healthiness. # # Arguments: # 1) Instance Number # 2) Virtual IP used by the instance # 3) Instance Name # # Returns: # 0 For sucess # exit with 1 For failure # function checkIsASRunning { if [[ $VERBOSE_LOGGING == 'high' ]] then PS4_FUNC=checkIsASRunning set -x fi typeset instance_num virtual_ip typeset processDisplayStatus processNames instance_num=$1 virtual_ip=$2 instance_name=$3 out=$(/usr/bin/su - $SAPADMNUSR -c \ "env LANG=C sapcontrol -host $virtual_ip -nr $instance_num \ -function GetProcessList -format script" 2>/dev/null | grep "[0-9] " \ | awk -F":" '/dispstatus:/ {print $2}') [[ -z $out ]] && { user_msg 60 7 $PROGRAM exit 1 } processDisplayStatus=(${out}) out=$(/usr/bin/su - $SAPADMNUSR -c \ "env LANG=C sapcontrol -host $virtual_ip -nr $instance_num \ -function GetProcessList -format script" 2>/dev/null | grep "[0-9] " \ | awk -F":" '/name:/ {print $2}') [[ -z $out ]] && { user_msg 60 8 $PROGRAM exit 1 } processNames=(${out}) for count in "${!processDisplayStatus[@]}"; do [[ ${processDisplayStatus[$count]} == "GREEN" ]] && { user_msg 60 9 $instance_name ${processNames[$count]} \ ${processDisplayStatus[$count]} } || { user_msg 60 10 $instance_name ${processNames[$count]} \ ${processDisplayStatus[$count]} exit 1 } done return 0 } #------------------------------------------------------------------------------- #Main #------------------------------------------------------------------------------- typeset out SID inst_name virt_ip profile typeset PROGRAM=${0##*/} typeset instance_start_profile inst_profile if [[ -z $ODMDIR ]]; then ODMDIR=/usr/es/sbin/cluster/etc/objrepos/active/ fi export ODMDIR eval export $(cllsparam -n $(clodmget -f nodename HACMPcluster)) if [[ $VERBOSE_LOGGING == 'high' ]] then PS4_TIMER=true set -x version='1.3.1.4' fi while getopts a: option do case $option in a) APPLICATION_ID=$OPTARG ;; esac done [[ -z $APPLICATION_ID ]] && { user_msg 30 30 $PROGRAM exit 1 } set -a eval $(clquerysaapp -a $APPLICATION_ID | grep SAPSYSTEMNAME) set +a export SAPSYSTEMNAME [[ -z $SAPSYSTEMNAME ]] && { user_msg 30 34 $PROGRAM exit 1 } user_msg 40 10 $SAPSYSTEMNAME setSAPGlobalEnv $SAPSYSTEMNAME ret=$? (( $ret != 0 )) && { user_msg 30 12 exit 1 } inst_name=$(clquerysaapp -a $APPLICATION_ID \ | awk -F"=" '/INSTANCE_NAME/ {print $2}' 2>/dev/null) [[ -z $inst_name ]] && { user_msg 30 31 $PROGRAM exit 1 } virt_ip=$(clquerysaapp -a $APPLICATION_ID \ | awk -F"=" '/VIRTUAL_IP/ {print $2}' 2>/dev/null) [[ -z $virt_ip ]] && { user_msg 30 32 $PROGRAM exit 1 } inst_no=$(clquerysaapp -a $APPLICATION_ID \ | awk -F"=" '/INSTANCE_NUMBER/ {print $2}' 2>/dev/null) [[ -z $inst_no ]] && { user_msg 30 33 $PROGRAM exit 1 } # Set START_PROFILE instance_start_profile="/usr/sap/"$SAPSYSTEMNAME"/SYS/profile/START_"$inst_name"_"$virt_ip # Set INSTANCE_PROFILE inst_profile="/usr/sap/"$SAPSYSTEMNAME"/SYS/profile/"$SAPSYSTEMNAME"_"$inst_name"_"$virt_ip if [ -f ${instance_start_profile} ]; then profile=${instance_start_profile}; else profile=${inst_profile}; fi checkForRunningSapstartsrv $profile ret=$? (( ret == 0 )) && { user_msg 60 13 $inst_name } || { user_msg 60 12 $inst_name exit 1 } checkIsASRunning $inst_no $virt_ip $inst_name exit 0