#!/bin/sh

echo "Content-type: text/html"
echo ""

CURHOST=""
echo "<html><head><title>Current non-green systems</title><body><table>"

bb 127.0.0.1 "hobbitdboard color=red,yellow,purple fields=hostname,testname,color" |
while read L
do
    set `echo "$L" | sed -e 's/|/ /'g`
    HOST=$1
    TEST=$2
    COLOR=$3

    if test "$CURHOST" != "$HOST"
    then
        if test "$CURHOST" != "" 
        then
            # new host, finish table row
	    echo "</tr>"
        fi

        echo "<tr><th align=left>$HOST</th>"
	CURHOST="$HOST"
    fi

    echo "<td><a href=\"/cgi-bin/bb-hostsvc.sh?HOSTSVC=$HOST.$TEST\">$TEST ($COLOR)</a></td>"
done

echo "</tr>"
echo "</table></body></html>"

exit 0

