#!/bin/sh
#
#
#
# This required thie dhcping utility:
#
# http://www.mavetju.org/unix/general.php
#
#
## Add to the hobbitserver.cfg in the TEST2RRD section: dhcp=tcp, this will show a graph of respond time.
## Built on Solaris 10.
COLUMN=dhcp
TIMEOUT=10
### Place the Client IP here
CLIENTIP=0.0.0.0
### Place the Client Mac here
MACADDR="xx:xx:xx:xx:xx:xx"
# /usr/local/bin/dhcping -v -s ${IP} -c ${CLIENTIP} -h ${MACADDR}
# Got answer from: ${IP}
$BBHOME/bin/bbhostgrep --no-down ${COLUMN} |
while read L
do
     set $L
     IP="$1"
     HOSTNAME="$2"
     COLOR=green
     /bin/ptime /usr/local/bin/dhcping -v -t ${TIMEOUT} -s $IP -c ${CLIENTIP} -h ${MACADDR} >$BBTMP/${COLUMN}.out 2>&1
     SECONDS=`egrep "^real" $BBTMP/${COLUMN}.out | awk '{printf $2}'`
     if test $? -ne 0
     then
        COLOR=red
	MSG="DHCP query failed
`cat $BBTMP/${COLUMN}.out`
Seconds: ${SECONDS}
"
     else
        COLOR=green
	MSG="DHCP query succeeded
`cat $BBTMP/${COLUMN}.out`
Seconds: ${SECONDS}
"
  fi
  $BB $BBDISP "status $HOSTNAME.$COLUMN $COLOR `date`
  $MSG"
  $RM $BBTMP/${COLUMN}.out
done
exit 0