#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2001,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 = "@(#)81   1.8   src/rsct/rm/ER/ewallevent, ERrm, rsct_rady, rady2035a 11/12/15 16:38:54"

#####################################################################
#
# Name:    ewallevent
#
# Purpose: Broadcast a message to the console to notify all the 
#          logged-in of an event or a rearm event.
#          Message always in English.
#
# 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

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=$(LC_ALL=C seconds=$seconds $PERL -e \
'
use POSIX qw(strftime);
print strftime("%A %D %T", localtime($ENV{seconds}) );  

'
)

# Convert Seveirty 
case $ERRM_COND_SEVERITYID in

    0 ) COND_SEVERITY=Informational;;
    1 ) COND_SEVERITY=Warning;;
    2 ) COND_SEVERITY=Critical;;

esac

# Convert EventType
case $ERRM_TYPEID in

    0 ) TYPE=Event;;
    1 ) TYPE=RearmEvent;;

esac

WallMsg="$COND_SEVERITY $TYPE occurred for the condition $ERRM_COND_NAME on the resource $ERRM_RSRC_NAME of the resource class $ERRM_RSRC_CLASS_PNAME at $EventTime. The resource was monitored on $ERRM_NODE_NAME and resided on $ERRM_NODE_NAMELIST." 
case $CMD_OPTION in

    0 ) WallMsg="$COND_SEVERITY $TYPE occurred for the condition $ERRM_COND_NAME on the resource $ERRM_RSRC_NAME of the resource class $ERRM_RSRC_CLASS_PNAME at $EventTime. The resource was monitored on $ERRM_NODE_NAME and resided on $ERRM_NODE_NAMELIST." ;;
    1 ) WallMsg="$COND_SEVERITY $TYPE occurred for the condition $ERRM_COND_NAME on the resource $ERRM_RSRC_NAME of the resource class $ERRM_RSRC_CLASS_PNAME at $EventTime. The resource was monitored on $ERRM_NODE_NAME and resided on $ERRM_NODE_NAMELIST. Event value: $ERRM_VALUE." ;;

esac

echo "${WallMsg}" | wall