#!/bin/bash
prefix=ela
self_rec_get=0

OUTPUT=/dev/console
ELA_SCRIPTS_DIR=/usr/share/evlog

FACILITY=""
EVENT_TYPE=""
SEVERITY=""
CAUSES=""
ACTIONS=""

echo $ACTIONS $CAUSES > /dev/null

. $ELA_SCRIPTS_DIR/ela_funcs
recid=${1}

#
# If temporary storage is not created then create it
#
# begin_rec_get - Capture the event record with this recid and 
# put it in our temporary storage - Subsequent get_* will work
# of this temporary storage.
#  
did_get_rec $prefix $recid
ret=$?
if [ $ret -eq "0" ]; then
	echo "did_get_rec returns $ret"
	echo "console create temp"
	begin_rec_get $prefix $recid
	if [ $? -eq "1" ]; then
		echo "Error: can't find event record with recid=${recid}"
		exit 1
	fi
	self_rec_get=1
fi
 
echo $recid > $OUTPUT

#
# Get the event facility - Facility will be stored in FACILITY var  
#
FACILITY=$(get_facility "$prefix" "$recid") 

#
# Get the event type -
#
EVENT_TYPE=$(get_event_type "$prefix" "$recid")
#
# Get the severity
#
SEVERITY=$(get_severity "$prefix" "$recid")
echo "facilty=${FACILITY} event_type=${EVENT_TYPE} severity=${SEVERITY}" >> $OUTPUT
#
# Get the error message
#
EVENT_MSG=$(get_event_none_std_att "$prefix" "$recid" "msg:printk")
if [ ! -z "$EVENT_MSG" ]; then
	echo "${EVENT_MSG}" >> $OUTPUT
fi

#
# TODO: get vpd stuff here
#
CAUSES=$(get_event_none_std_att "$prefix" "$recid" "probableCauses")
if [ ! -z "${CAUSES}" ]; then
	echo "Probable cause:" >> $OUTPUT
	echo -e "${CAUSES}" | awk '{print "\t" $0}' >> $OUTPUT
fi
	
ACTIONS=$(get_event_none_std_att "$prefix" "$recid" "actions")

if [ ! -z "${ACTIONS}" ]; then
	echo "Recommend actions:" >> $OUTPUT
	echo -e "${ACTIONS}" | awk '{print "\t" $0}' >> $OUTPUT
fi

#
# Remove temporary storage
#
# This script create the temp storage - it should remove it
# when it is done.
#
if [ $self_rec_get -eq 1 ]; then
	end_rec_get $prefix $recid
fi


