#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  Copyright (C) Altran ACT S.A.S. 2017,2018,2019,2021.  All rights reserved.
#
#  ALTRAN_PROLOG_END_TAG
#
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r721 src/43haes/usr/sbin/cluster/events/event_error.sh 1.13.1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1990,2016 
# 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/events/event_error.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM

#########################################################################
#                                                                       #
#       Name:           event_error                                     #
#                                                                       #
#       Description:    When an event script fails, this script is      #
#			run to alert the admin.                         #
#                                                                       #
#       Called by:      cluster manager                                 #
#                                                                       #
#       Arguments:      return code of the failed event                 #
#                       script name and parameters                      #
#                                                                       #
#       Returns:        2 on error, otherwise 0                         #
#                                                                       #
#########################################################################

typeset PROGNAME=${0##*/}
export PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)"

set -a
eval $(cllsparam -n $LOCALNODENAME)
set +a

if [[ $VERBOSE_LOGGING == "high" ]]; then
    set -x
    version='%I%'
fi

EXIT_STATUS=$1
RP_NAME=$*

# 
# This is only ever called by clstrmgr so we only do rudimentary checking
#
if (( $# != 2 ))
then
        echo "$PROGNAME: An internal error occurred - if the problem persists,\nplease report it to IBM support.\n"
        exit 2
fi

set -u

# strip parameters from the script name
RP_NAME=${RP_NAME#*_}
RP_NAME=${RP_NAME%_*}

# retrieve cluster name
CLUSTER=$(cllsclstr -c | tail -1 | cut -d ':' -f2)

# echo to both stdout and the console to make it as visible as possible
dspmsg -s 46 scripts.cat 13 "ERROR: Cluster $CLUSTER failed while running event [$RP_NAME], exit status was $EXIT_STATUS\n" $CLUSTER $RP_NAME $EXIT_STATUS >/dev/console
dspmsg -s 46 scripts.cat 14 "Manual intervention will be required to resume normal PowerHA processing.\n" >/dev/console
dspmsg -s 46 scripts.cat 15 "Until that time, no further cluster events will be processed.\n" >/dev/console
dspmsg -s 46 scripts.cat 16 "Follow local troubleshooting procedures to analyze any errors found in\nhacmp.out on the failed nodes.\n" >/dev/console

dspmsg -s 46 scripts.cat 13 "ERROR: Cluster $CLUSTER failed while running event [$RP_NAME], exit status was $EXIT_STATUS\n" $CLUSTER $RP_NAME $EXIT_STATUS 
dspmsg -s 46 scripts.cat 14 "Manual intervention will be required to resume normal PowerHA processing.\n" 
dspmsg -s 46 scripts.cat 15 "Until that time, no further cluster events will be processed.\n" 
dspmsg -s 46 scripts.cat 16 "Follow local troubleshooting procedures to analyze any errors found in\nhacmp.out on the failed nodes.\n" 

#
# This event is called for both local and remote failures 
#
if [[ "$LOCALNODENAME" == "$EVENT_FAILED_NODE" ]]
then
    
    # local failure
    dspmsg scripts.cat 9648 "Check hacmp.out on this node for errors.\n"

else

    # 
    # failure occurred remotely
    #
    echo ""
    dspmsg scripts.cat 9647 "Check hacmp.out on node $EVENT_FAILED_NODE for errors.\n" $EVENT_FAILED_NODE
    echo ""

fi

#
# clstrmgr will run the ffdc event to capture RAS data, so we are done here
#

exit 0
