#!/bin/bash # check the status of all BGP-Peers. Report status <6 as critical # Author M.Salathe(michael.salathe@murxs.ch) # Public Domain # Object bgpPeerState # OID 1.3.6.1.2.1.15.3.1.2 # Type INTEGER # Permission read-only # Status current # Values 1 : idle # 2 : connect # 3 : active # 4 : opensent # 5 : openconfirm # 6 : established # MIB BGP4-MIB ; snmpwalk -v 2c -c $2 $1 1.3.6.1.2.1.15.3.1.2 | awk 'BEGIN{good=0;crit=0;warn=0;unk=0;} $4 < 6 {crit=crit+1}$4==6{good=good+1}$4>6{unk=unk+1}$4<1{unk=unk+1} END{status="UNKKNOWN"; ex=3; if(good>0){status="OK"; ex=0;} if(unk>0){status="UNKNOWN"; ex=3;} if(warn>0){status="WARNING"; ex=1;} if(crit>0){status="CRITICAL"; ex=2;} print "BGP " status " - ok:" good" warn: "warn" crit: " crit " unk: " unk; exit(ex)}' exit $?