Icinga Plugin – Check OSPF States
Just wrote a small check plugin for Icinga yesterday. It’s just about checking OSPF stati from a Cisco router/switch via SNMP. Copy and paste the following in a textfile and make it executable or just donwload it here check_snmp_ospf.tar.gz. Enjoy!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#!/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 |