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

#########################################################################
#
#   COMPONENT_NAME: EVENTS
#
#   FUNCTIONS: none
#
#########################################################################


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

[[ "$VERBOSE_LOGGING" = "high" ]] && set -x
[[ "$VERBOSE_LOGGING" = "high" ]] && version='%I%'
NODENAME=$1
LOCALNODENAME=${LOCALNODENAME:-$(/usr/es/sbin/cluster/utilities/get_local_nodename )}

if [[ -z "$LOCALNODENAME" ]]
then
    print "${PROGNAME}[$LINENO]: local node name not set"
    return -1
fi

if [[ -z "$NODENAME" ]]
then
    print "${PROGNAME}[$LINENO]: Argument 1 not specified"
    return -1
fi

integer STATUS=0

dspmsg scripts.cat 9970 "Following this event you might see resource group acquire and \n\
release events that would result in moving affected resource groups. \n\
Configure pre/post events to resource_state_change and\n\
resource_state_change_complete events to customize pre-resource group move and\n\
post-resource group move actions."


# Call replicated resource method pprc_snmptrap_event if it is defined
#METHODS=$(cl_rrmethods2call pprc_snmptrap_event)
# SNMPTRAP_EVENT will be set by the caller
METHODS=$SNMPTRAP_EVENT

if [[ "$LOCALNODENAME" = "$NODENAME" ]]
then
    for method in $METHODS; do
        if [[ -x $method ]]; then
            $method $*
            rc=$?
            if [[ $rc -ne 0 ]]; then
                (( STATUS=STATUS+1 ))
            fi
        fi
    done
else
    print "${PROGNAME}[$LINENO]: This isn't node $NODENAME, nothing to do"
fi
exit $STATUS
