#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2019 
# 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 

# sccsid = "@(#)09   1.15   src/rsct/rm/ER/wallevent, ERrm, rsct_rady, rady2035a 11/12/15 16:39:57"

#####################################################################
#
# Name:    wallevent
#
# Purpose: Broadcast a message to the console to notify all the 
#          logged-in of an event or a rearm event.
#          Message depends on locale. 
#
# Inputs:  None
#
#####################################################################

# main()
# Set path to known value
PATH=/opt/rsct/bin:/usr/xpg4/bin:/usr/bin:/usr/sbin:/bin
export PATH

PERL=/usr/bin/perl

CTMSG=/opt/rsct/bin/ctdspmsg
MSGMAPPATH=/opt/rsct/msgmaps
export MSGMAPPATH

Usage=`$CTMSG script IBM.ERrm.cat MSG_SH_USAGE`

# Convert Seveirty
case $ERRM_COND_SEVERITYID in

    0 ) COND_SEVERITY=`$CTMSG script IBM.ERrm.cat MSG_SH_INFO`;;
    1 ) COND_SEVERITY=`$CTMSG script IBM.ERrm.cat MSG_SH_WARNING`;;
    2 ) COND_SEVERITY=`$CTMSG script IBM.ERrm.cat MSG_SH_CRITICAL`;;

esac

# Convert EventType
case $ERRM_TYPEID in

    0 ) TYPE=`$CTMSG script IBM.ERrm.cat MSG_SH_EVENT`;;
    1 ) TYPE=`$CTMSG script IBM.ERrm.cat MSG_SH_REARMEVENT`;;

esac

CMD_OPTION=0
while getopts ":hc" opt
do
  case $opt in

    h ) print "Usage: `basename $0` [-h] [-c]"
        exit 0;;

    c ) CMD_OPTION=1;;

    ? ) print "Usage: `basename $0` [-h] [-c]"
        exit 3;;
  esac
done

# convert time string
seconds=${ERRM_TIME%,*}

EventTime=$(seconds=$seconds $PERL -e \
'
use POSIX qw(strftime);
print strftime("%A %D %T", localtime($ENV{seconds}) );  

'
)

ERRM_VALUE2=`echo $ERRM_VALUE | /bin/sed 's/\"/\\\"/g'`

case $CMD_OPTION in

    0 ) WallMsg=`$CTMSG script IBM.ERrm.cat MSG_SH_WALLN "$COND_SEVERITY" "$TYPE" "$ERRM_COND_NAME" "$ERRM_RSRC_NAME" "$ERRM_RSRC_CLASS_PNAME" "$EventTime" "$ERRM_NODE_NAME" "$ERRM_NODE_NAMELIST"`;;
    1 ) WallMsg=`$CTMSG script IBM.ERrm.cat MSG_SH_WALLN_OC "$COND_SEVERITY" "$TYPE" "$ERRM_COND_NAME" "$ERRM_RSRC_NAME" "$ERRM_RSRC_CLASS_PNAME" "$EventTime" "$ERRM_NODE_NAME" "$ERRM_NODE_NAMELIST" "$ERRM_VALUE2"`;;

esac

echo "${WallMsg}" | wall