#!/bin/sh
#
# BIG BROTHER OVERALL EVENT LOGS HISTORY DISPLAY SCRIPT
# Robert-Andre Croteau
# Version 1.4
# Mar 05th, 2000
#
# This program is Copyright (c) 1997-2000
# The MacLawran Group Inc.
# All Rights Reserved
#

#
# Similar to the work of MR NETOPS
# (Todd Jimenez <TJimenez@outpost.com>)
# but his is nicer...
# Thanks Todd for pestering us to include this feature !!!
#
# This script should be called within mkbb.sh or mkbb2.sh
#

NUMEVENTS=20

echo "<BR><BR>
<TABLE BORDER=0>
<TR BGCOLOR="333333">
<TD ALIGN=CENTER COLSPAN=4><FONT SIZE=-1 COLOR="teal">Last $NUMEVENTS events received</TD></TR>"

$TAIL -$NUMEVENTS $BBHOME/www/hist/allevents | $AWK '{x[NR] = $0} END { for (i = NR; i > 0; i--) print x[i] }' |
while read line
do
	if test "$BG" = "000000"
	then
		BG="000033"
	else
		BG="000000"
	fi

	echo "<TR BGCOLOR=$BG>"

	set $line
	if [ "$#" -ne 8 ]
	then
		echo "<TD COLSPAN=4>Invalid line in 'hist/allevents'</TD>"
		continue
	fi

	HOST=$1
	#HOSTDIR=`echo "$HOST" | $SED 's/\./_/g'`
	HOSTDIR=$HOST
	SERVICE=$2
	ATDATE=`$BBHOME/bin/touchtime -c $3`
	FROMDATE=`$BBHOME/bin/touchtime -c $4`

	color=$7
	bgcolor=$6

	argnum=0
	for color in $6 $7
	do
		if [ "$color" = "re" ]
		then
			color=red
		elif [ "$color" = "pu" ]
		then
			color=purple
		elif [ "$color" = "pu" ]
		then
			color=purple
		elif [ 	"$color" = "ye" ]
		then
			color=yellow
		elif [ "$color" = "gr" ]
		then
			color=green
		elif [ "$color" = "bl" ]
		then
			color=blue
		elif [ "$color" = "cl" ]
		then
			color=clear
		else
			color=clear
		fi
		
		if [ "$argnum" -eq 0 ]
		then
			tocolor=$color
			argnum=1
		else
			fromcolor=$color
		fi
	done

	echo "<TD ALIGN=CENTER>$ATDATE</TD>"

	if [ "$tocolor" = "clear" ]
	then
		echo "<TD ALIGN=CENTER BGCOLOR=black><FONT COLOR=white>$HOST</FONT></TD>"
	else
		echo "<TD ALIGN=CENTER BGCOLOR=$tocolor><FONT COLOR=black>$HOST</FONT></TD>"
	fi

	echo "<TD ALIGN=LEFT>$SERVICE</TD>"

	set $FROMDATE
	echo "<TD><A HREF=\"$CGIBINURL/bb-histlog.sh?HOST=$HOSTDIR&SERVICE=$SERVICE&TIMEBUF=${1}_${2}_${3}_${4}_${5}\">"

	echo "<IMG SRC=\"$BBSKIN/$fromcolor.gif\" BORDER=0 ALT=$fromcolor></A>"


	set $ATDATE
	echo "<IMG SRC=\"$BBSKIN/arrow.gif\" BORDER=0>"

	echo "<A HREF=\"$CGIBINURL/bb-histlog.sh?HOST=$HOSTDIR&SERVICE=$SERVICE&TIMEBUF=${1}_${2}_${3}_${4}_${5}\">"
	echo "<IMG SRC=\"$BBSKIN/$tocolor.gif\" BORDER=0 ALT=$tocolor></A></TD></TR>"
done

echo "</TABLE>"
		

exit 0
