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

# "@(#)09   1.10   src/rsct/rm/ER/wallevent, ERrm, rsct_relgh, relghs001a 10/11/06 17:06:39";

#####################################################################
#
# 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()

PERL=/usr/sbin/rsct/perl5/bin/perl

CTMSG=/usr/sbin/rsct/bin/ctdspmsg
MSGMAPPATH=/usr/sbin/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}) );  

'
)

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_VALUE"`;;

esac

echo "${WallMsg}" | wall
