#!/bin/bash
#
# Author: Peter Kok(pk21@hotmail.com)
# Description: this check will test the status of the ip sla command on cisco equipment to locate connectivity issues in a network. It was created especially to test the icmp-echo option but other tests will probably also work.
#
# An example of a icmp-echo test below. You can configure a tag so xymon can use is to describe what is being tested:
# ip sla 3
# icmp-echo 172.16.1.2
# threshold 200
# tag iBGP
# ip sla schedule 3 life forever start-time now
#
# the check will display "Index: 3 RTT: 1 Threshold: 200 Status: ok Tag: iBGP" in xymon
#
BBHTAG=sla # What we put in bb-hosts to trigger this test
COLUMN=$BBHTAG # Name of the column, often same as tag in bb-hosts
COMMUNITY=public
$BBHOME/bin/bbhostgrep $BBHTAG | while read L
do
set $L # To get one line of output from bbhostgrep
HOSTIP="$1"
MACHINEDOTS="$2"
MACHINE=`echo $2 | $SED -e's/\./,/g'`
COLOR=green
MSG="$BBHTAG status for host $MACHINEDOTS"
declare -a STATUSCODES=('other' 'ok' 'disconnected' 'overThreshold' 'timeout' 'busy' 'notConnected' 'dropped' 'sequenceError' 'verifyError' 'applicationSpecific' 'dnsServerTimeout' 'tcpConnectTimeout' 'httpTransactionTimeout' 'dnsQueryError' 'httpError' 'error')
for INDEX in `/usr/bin/snmpwalk -c $COMMUNITY -v2c $HOSTIP 1.3.6.1.4.1.9.9.42.1.2.1.1.4|awk '{ print $1 }'|awk -F\. '{ print $10 }'`
do
RTT=$(/usr/bin/snmpget -c $COMMUNITY -v2c $HOSTIP 1.3.6.1.4.1.9.9.42.1.2.10.1.1.$INDEX|awk '{ print $4 }')
TAG=$(/usr/bin/snmpget -c $COMMUNITY -v2c $HOSTIP 1.3.6.1.4.1.9.9.42.1.2.1.1.3.$INDEX|awk -F\" '{ print $2 }')
STATUS=$(/usr/bin/snmpget -c $COMMUNITY -v2c $HOSTIP 1.3.6.1.4.1.9.9.42.1.2.10.1.2.$INDEX|awk '{ print $4 }')
THRESHOLD=$(/usr/bin/snmpget -c $COMMUNITY -v2c $HOSTIP 1.3.6.1.4.1.9.9.42.1.2.1.1.5.$INDEX|awk '{ print $4 }')
CCOLOR="green"
if [ "$STATUS" == 0 ] && [ "$COLOR" != "red" ]
then
CCOLOR="yellow"
if [ "$COLOR" != "red" ]
then
COLOR=yellow
fi
elif [ "$STATUS" == 1 ]
then
CCOLOR="green"
if [ "$COLOR" != "red" ] && [ "$COLOR" != "yellow" ]
then
COLOR=green
fi
else
COLOR=red
CCOLOR="red"
fi
STATUSTRANSLATED=${STATUSCODES[$STATUS]}
MSG=$(echo -e "$MSG\n<img src=/xymon/gifs/$CCOLOR.gif> Index: $INDEX\tRTT: $RTT\tThreshold: $THRESHOLD\tStatus: $STATUSTRANSLATED\tTag: $TAG")
done
$BB $BBDISP "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
"
done
exit 0