#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2017,2020,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/sa/oracle/sbin/IO.sh 1.6 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2006,2009 
# 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/oracle/sbin/IO.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
#----------------------------------------------------------------------------
# Global Definitions:
#----------------------------------------------------------------------------

# Read in the message catalog entries
. /usr/es/sbin/cluster/sa/oracle/sbin/Catalog

#----------------------------------------------------------------------------
# Functions:
#   osaGetLogPath
#
#   user_msg
#   log_msg
#   warn_msg
#   osaError
#
#----------------------------------------------------------------------------

function user_msg {
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
    typeset -i s=$1
    typeset -i id=$2
    shift
    shift
    typeset args=$*
    typeset c="$s,$id"
    
    [[ -z $s || -z $id ]] && {
        return 1
    }

    /usr/bin/dspmsg -s $s "${SA_Catalog[catalog]}" $id "${SA_Catalog[$c]}" $args
    echo
    # Log the information to the oraclesa.log log file
    typeset msg=$(LC_ALL=C /usr/bin/dspmsg -s $s "${SA_Catalog[catalog]}" $id "${SA_Catalog[$c]}" $args)
    log_msg $msg
}

#-----------------------------------------------------------------------------
# Function:
#   InternalErrorAbort 
#
# Purpose:
#   Creates a fatal error log file with time of occurence of error and stores a 
#   copy of Oracle smart assist log file which will help to diagnose the fault.
#
# Arguments:
#   NA
#
# Returns:
#   0
#
function InternalErrorAbort {
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
    typeset date=$(LC_ALL=C date +"%m.%d.%y-%H-%M-%S")
    typeset logfile="/var/hacmp/log/oraclesa.fatal.$date"
    cp -f $ORACLESA_LOGFILE $logfile 2>/dev/null
    user_msg 30 100 $logfile
    # Return from this fucntion to enable cleanup of HA components before exit.
    return 0 
}

function osaGetLogPath {
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
    typeset LOGFILE="oraclesa.log"
    typeset LOGPATH=$(/usr/bin/odmget -q "name=oraclesa.log" HACMPlogs 2>/dev/null |
        grep -w value | awk -F'=' '{ print $2 }' | sed -e "s/\"//g")
    typeset DEFAULTLOGPATH=$(odmget -q "name=oraclesa.log" HACMPlogs 2>/dev/null |
        grep -w value | awk -F'=' '{ print $2 }' | sed -e"s/\"//g")

    [[ -z $ORACLESA_LOGPATH ]] && {
        [[ -z $DEFAULTLOGPATH ]] && {
            LOGFILE="/var/hacmp/log/oraclesa.log"
        } || {
            LOGFILE="$DEFAULTLOGPATH/$LOGFILE"
        }
    } || {
        LOGFILE="$LOGPATH/$LOGFILE"
    }
    echo $LOGFILE
}

function log_msg {
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
    DATE=$(/bin/date +"%D %T")
    echo "$DATE INFO: $*" >> $ORACLESA_LOGFILE
}

function warn_msg {
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
    DATE=$(/bin/date +"%D %T")
    echo "$DATE WARN: $*" >> $ORACLESA_LOGFILE
}

function osaError {
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
    DATE=$(/bin/date +"%D %T")
    echo "$DATE ERROR: $1" >> $ORACLESA_LOGFILE
}

#----------------------------------------------------------------------------
# Main:
#----------------------------------------------------------------------------

ORACLESA_LOGFILE=$(osaGetLogPath)

