#!/bin/sh
if [ $# -ne 2 ]
then
	echo Usage: $0 network community
	exit
fi
network=$1
community=$2

hostlist=`cat $PINGKYDIR/$network.LINKS| awk '{ print $2" "$7}'`
echo $hostlist
for node in `echo $hostlist | sort | uniq`
do
	list=`echo $list -h $node`
done

echo snmptable2 -c $community $list ifOperStatus
snmptable2 -c $community $list ifOperStatus > /tmp/$network.results

echo "" >/tmp/$network.STATUS

cat /tmp/$network.results  |
while read line
do
        echo line=$line
	node=`echo $line | awk -F: '{ print $1}'`
	echo $line | grep Did
	if [ $? -eq 0 ]
	then
		node $node did not respond
		echo 0 NODE NSS `gethostname $node` $node NR >>/tmp/$network.STATUS
	else
		interface=`echo $line | awk '{ print $2 }' | awk -F. '{ print $2}'`
		state=`echo $line | awk '{ print $3}'`
		echo node=$node interface=$interface state=$state
		echo 0 NODE NSS `gethostname $node` $node UP >>/tmp/$network.STATUS
		cat $PINGKYDIR/$network.LINKS | awk '
{ 
	if (( $2 == "'$node'" ) && ( $4 == "'$interface'" )) 
		if ( '$state' == 1 ) print "0 LINK ISISLINK "$2" "$7" UP" 
		else print "0 LINK ISISLINK "$2" "$7" DOWN" 
	if (( $5 == "'$interface'" ) && ( $7 == "'$node'" ))
		if ( '$state' == 1 ) print "0 LINK ISISLINK "$7" "$2" UP" 
		else print "0 LINK ISISLINK "$7" "$2" DOWN" 
}' >>/tmp/$network.STATUS
	fi
done
diff /tmp/$network.STATUS $PINGKYDIR/$network.STATUS
cp  /tmp/$network.STATUS $PINGKYDIR/$network.STATUS
