#!/bin/sh

# $Id: larrd-html.sh,v 1.3 2000/06/29 19:06:21 root Exp root $

#set -x

# larrd-html.sh - script to integrate HTML into BB

if test ! "$BBHOME"

then
        echo "$0: BBHOME is not set"
        exit 1
fi

if test ! -d "$BBHOME"
then
        echo "$0: BBHOME is invalid"
        exit 1
fi

 
HTML=$BBHOME/www/html
# source the conf
. $BBHOME/etc/bbdef.sh
. $BBHOME/ext/larrd/larrd.conf

DATE=`date`
# get in the logs dir
cd $BBHOME/www/graphs

# this should support all FQDN's
# just checking for existence of la pngs
# not pretty but it works
#HOSTS=`ls *.la.hourly.png | $SED 's/\.la\.hourly\.png//' | uniq`
# now we want html for any .png that is present 

## 2/21/2000 I had to patch the regexp below to include the numbers
##  that the modified disk-graph.sh generates in the filename - nate
#HOSTS=`ls *.png | $SED 's/\.[a-z0-9]*\.[a-z]*\.png$//' | uniq`
HOSTS=`ls *.png | $SED 's/\.[a-z0-9]*\.[a-z]*\.png$//' | uniq`

# generate the larrd column based on any daily .png existing
for host in $HOSTS
do
        # get a list of daily pngs that are available for that host
        PNGS=`ls ${host}.*.hourly.png`
        #echo $PNGS

#        echo "<CENTER>" >> $BBTMP/larrd.html
        # for each monitor type make some HTML
        for png in $PNGS
        do
                # figure what data is associated to .png
                # these is going to need some attention as things get added
#                DATA=`echo $png | $SED -e "s/${host}\.//" | $AWK -F. '{print $1}' `
                DATA=`echo $png | $SED -e "s/${host}\.//" | $AWK -F. '{print $1}'| $AWK -F, '{print $1}' `
 
                # if need be make the detail stat page, thanks colin
                DOC="${host}.${DATA}.${COL}.html"
                if [ ! -r ${HTML}/${DOC} ]; then
                        $SED -e "s/HOST/${host}/g" \
                        -e "s/STATISTIC/${DATA}/g" \
                        ${LARRDHOME}/web/HOST.STATISTIC.html > \
                        ${HTML}/${DOC}
                fi

## old html link & png generation
#                echo "<A HREF=\"${BBWEB}html/${DOC}\"><IMG SRC=\"${BBWEB}graphs/${png}\" \
#                        ALT=\"larrd is accumulating\"></A><BR>" >> \
#                        $BBTMP/larrd.html


case "$DATA" in
        mem)
		echo "<A HREF=\"/cgi-bin/hacked-mem-graph-lt.sh?${host}\"> \
		<IMG SRC=\"/cgi-bin/hacked-mem-graph.sh?${host}\" \
		ALT=\"larrd is accumulating\"></A><BR>" >> \
		$BBTMP/larrd.html
        ;;
	la)
		echo "<A HREF=\"/cgi-bin/hacked-la-graph-lt.sh?${host}\"> \
		<IMG SRC=\"/cgi-bin/hacked-la-graph.sh?${host}\" \
		ALT=\"larrd is accumulating\"></A><BR>" >> \
		$BBTMP/larrd.html
        ;;
	diskpct0)
		echo "<A HREF=\"/cgi-bin/hacked-disk-graph-lt.sh?${host}\"> \
		<IMG SRC=\"/cgi-bin/hacked-disk-graph2.sh?${host}\" \
		ALT=\"larrd is accumulating\"></A><BR>" >> \
		$BBTMP/larrd.html
	;;
	swap)
		echo "<A HREF=\"/cgi-bin/hacked-swap-graph-lt.sh?${host}\"> \
		<IMG SRC=\"/cgi-bin/hacked-swap-graph.sh?${host}\" \
		ALT=\"larrd is accumulating\"></A><BR>" >> \
		$BBTMP/larrd.html
	;;
	perfasp)
		echo "<A HREF=\"/cgi-bin/hacked-perfasp-graph-lt.sh?${host}\"> \
		<IMG SRC=\"/cgi-bin/hacked-perfasp-graph.sh?${host}\" \
		ALT=\"larrd is accumulating\"></A><BR>" >> \
		$BBTMP/larrd.html
	;;
	tcp*)
		echo "<A HREF=\"/cgi-bin/hacked-bbnet-graph-lt.sh?${host}\"> \
		<IMG SRC=\"/cgi-bin/hacked-bbnet.sh?${host}\" \
		ALT=\"larrd is accumulating\"></A><BR>" >> \
		$BBTMP/larrd.html
	;;
esac

        done

#        echo "</CENTER>" >> $BBTMP/larrd.html

        # now report back to bb
        # need commas
        NEWHOST=`echo $host | $SED 's/\./,/g' `
        $BB $BBDISP "status ${NEWHOST}.${COL} green ${DATE} - larrd is accumulating 
`cat $BBTMP/larrd.html`"

        # clean up the html and start fresh
        rm $BBTMP/larrd.html
done
