#!/bin/bash
# 27/JAN/2012 Evelyn Riha
# Some minor amendments; Modified exit stati to comply with the icinga return values and fallback option to UNKNOWN
# 25/JAN/2012 Evelyn Riha
# Checks the ospf neighbor state of the given switch and ospf enabled interface
#################################################################################
## fill constants ##
OID='1.3.6.1.2.1.14.10.1.6'
SNMPWALK=`which snmpwalk`
USAGE="Usage: ./check_ospf -H <hostname> -C <community> -i <ospf interface>"
## set variables ##
community=""
hostname=""
ospf_interface=""
## main method ##
while getopts ":C:H:i:" options;
do
case $options in
C ) community="$OPTARG";;
H ) hostname="$OPTARG";;
i ) ospf_interface="$OPTARG";;
? ) echo $USAGE
exit 1;;
esac
done
if [[ $hostname != '' ]] && [[ $community != '' ]]
then
ospf_status=`$SNMPWALK -v 2c -c $community $hostname $OID.$ospf_interface.0 | awk '{ print $4 }'`
case $ospf_status in
1) #down
status="CRITICAL - OSPF neighbor on $ospf_interface is in DOWN state"
exit_state=2
;;
2) #attempt
status="CRITICAL - OSPF neighbor on $ospf_interface is in ATTEMPT state"
exit_state=2
;;
3) #init
status="CRITICAL - OSPF neighbor on $ospf_interface is in INIT state"
exit_state=2
;;
4) #twoWay
status="WARNING - OSPF neighbor on $ospf_interface is in TWO WAY state"
exit_state=1
;;
5) #exchangeStart
status="WARNING - OSPF neighbor on $ospf_interface is in EXCHANGE START state"
exit_state=1
;;
6) #exchange
status="WARNING - OSPF neighbor on $ospf_interface is in EXCHANGE state"
exit_state=1
;;
7) #loading
status="WARNING - OSPF neighbor on $ospf_interface is in LOADING state"
exit_state=1
;;
8) #full
status="OK - OSPF neighbor on $ospf_interface is in FULL state"
exit_state=0
;;
*) #unknown
status="UNKNOWN - Please check the given arguments"
exit_state=3
;;
esac
echo $status
else
echo $USAGE
exit 1
fi
exit $exit_state