#!/bin/ksh
#  ALTRAN_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  Copyright (C) Altran ACT S.A.S. 2017,2019,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/network_down.sh 1.23 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1990,2005 
# 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/network_down.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM

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

#########################################################################
#                                                                       #
#       Name:           network_down                                    #
#                                                                       #
#       Description:    This event script is called when one of the     #
#			cluster networks goes down.      		#
#                                                                       #
#       Called by:      cluster manager                                 #
#                                                                       #
#       Calls to:       None                                            #
#                                                                       #
#       Arguments:      nodename network_name                     	#
#									#
#                       nodename - name of the node whose network failed#
#                                to function.                           #
#                                (-1 indicates global network failure.)	#
#									#
#                       network_name - logical network name from 	#
#                                      cluster configuration.           #
#                                                                       #
#       Returns:        0       success                                 #
#                       1       failure                                 #
#                       2       bad argument                            #
#                                                                       #
#########################################################################

typeset PROGNAME=${0##*/}
export PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)"
# NETWORKNAME environmental variable is using in cl_rrmethods2call function
export NETWORKNAME=$2
# Including Availability metrics library file
. /usr/es/lib/ksh93/availability/cl_amlib
if [[ $VERBOSE_LOGGING == "high" ]]; then
    eval export $(cllsparam -x)
    set -x
    version='%I%'
fi

set -a
eval $(cllsparam -n $LOCALNODENAME)
set +a
STATUS=0

if [ $# -ne 2 ]
then
   cl_log  1033 "Usage: $PROGNAME nodename network_name\n"  $PROGNAME
    exit 2
fi

if [[ $1 == $LOCALNODENAME ]];then
    amlog_trace $AM_NETWORK_DOWN_BEGIN "$EVENT_SERIAL_NUMBER|$1|$2"
fi
        

#
# Call replicated resource net_cleanup methods
#
        
METHODS=$(cl_rrmethods2call net_cleanup)

for method in $METHODS
do
  if [[ -x $method ]]
  then
      if ! $method $*
      then
        STATUS=1
      fi
  fi
done


set -u

#
# This is the template script for network_down event,
# and is locally configurable.
# 
# e.g.:
# if [ $1 -eq -1 -o "$2" == "ether" ]
# then
#	mail -s "global network failure or ether net failed to function.." root
# fi
#
if [[ $1 == $LOCALNODENAME ]];then
    if [[ $STATUS -ne 0 ]];then
       #Logging failure in clavailability.log
       amlog_trace $AM_NETWORK_DOWN_FAILURE "$EVENT_SERIAL_NUMBER|$1|$2"
    else
        amlog_trace $AM_NETWORK_DOWN_END "$EVENT_SERIAL_NUMBER|$1|$2"
    fi
fi
exit $STATUS
