#!/bin/sh

# To enable IPv6 connectivity tests, add the "conn6" tag to bb-hosts.

bbhostgrep conn6 | cut -d ' ' -f 2 | fping6 -e | while read host line ; do
	case $line in
		is?alive*) color="green"
		TIME=`echo "$line" | perl -ne 'if (/\(([\d.]+) ?us/) { printf "%f", $1/1000000 }
						elsif (/\(([\d.]+) ?ms/) { printf "%f", $1/1000 }
						elsif (/\(([\d.]+)/) { print $1 }'`
		;;
		*) color="red"
		if bbhostgrep conn6 | grep $host | grep -q dialup ; then
			color="clear"
		fi
		;;
	esac
	( echo "status $host.conn6 $color `date`"
	  host -t AAAA $host
	  echo
	  echo "&$color $host $line"
	  echo "Seconds: $TIME"
	) | bb $BBDISP @
done
