#!/bin/bash # # RS 20160524 # # # Check LACP-Ports on switches, using IEEE8023-LAG-MIB # # IEEE8023-LAG-MIB *must* be installed! # OK=0 CRITICAL=2 STATE=0 PLUGIN_PATH="/usr/local/nagios/libexec/plugins" OID_sysDescr=SNMPv2-MIB::sysDescr.0 OID_lag=1.2.840.10006.300.43.1 #OID_lag=1.2.840.10006.300.43.1.1 VERSION="0.1" print_version() { echo "$SCRIPTNAME" version "$VERSION" echo "This nagios plugins comes with ABSOLUTELY NO WARRANTY." echo "You may redistribute copies of the plugins under the terms of the GNU General Public License v2." echo "Author: SicherByte GmbH Dr. Ralf Schwedler" echo "Itzehoe - 2016" echo "schwedler@sicherbyte.com" } print_help() { print_version echo "" echo "check integrity of LACP links" echo "" echo "-H ADDRESS (default: 127.0.0.1)" echo "-c COMMUNITY (default: public)" echo "-g LACP GROUP (default: 1)" # echo "-p Port name" # echo "-n number of link in a LACP bundle" echo "-V Print version" echo "-h this help" } ADDRESS="127.0.0.1" COMMUNITY="public" GROUP="1" while getopts H:c:g:Vh OPT do case "$OPT" in H) HOSTNAME="$OPTARG" ;; c) COMMUNITY="$OPTARG" ;; g) GROUP="$OPTARG" ;; V) print_version exit $STATE ;; h) print_help ;; esac done echo $(snmpwalk -v 1 -c $COMMUNITY $HOSTNAME $OID_sysDescr|sed -e 's/^.* = STRING: //') " LACP group " $GROUP #Get system infomation sysinfo=`snmpwalk -v 1 -c $COMMUNITY $HOSTNAME $OID_sysDescr| awk 'NR==1 {print $4}'` # 3Com # snmpwalk -v 1 -c $COMMUNITY $HOSTNAME IF-MIB::ifDescr # liefert alle Portnamen, grep -w "\ $portname$" | awk -F '[{. }]' '{print $2}'` liefert fuer einen Namen die portid # # snmpwalk -v 1 -c $COMMUNITY $HOSTNAME IF-MIB::ifAlias # liefert die Portbeschreibungen # snmpwalk -v 1 -c $COMMUNITY $HOSTNAME IF-MIB::ifSpeed # liefert die Portgeschwindigkeiten # snmpwalk -mALL -v 1 -c $COMMUNITY $HOSTNAME $OID_lag # IEEE8023-LAG-MIB::dot3adAggActorSystemID. # .1.2.840.10006.300.43.1.1.1.1.4 # IEEE8023-LAG-MIB::dot3adAggActorAdminKey. !!! ungleich !!! # .1.2.840.10006.300.43.1.1.1.1.6 # IEEE8023-LAG-MIB::dot3adAggActorOperKey. !!! # .1.2.840.10006.300.43.1.1.1.1.7 SYSID=$(snmpwalk -v 1 -c $COMMUNITY $HOSTNAME -Oq -Oe -Ov 1.2.840.10006.300.43.1.1.1.1.4.$GROUP) # echo $SYSID if [[ -z $SYSID ]] then echo $HOSTNAME LACP group $GROUP not found / not reachable exit 2 fi ADMINKEY=$(snmpwalk -v 1 -c $COMMUNITY $HOSTNAME -Oq -Oe -Ov 1.2.840.10006.300.43.1.1.1.1.6.$GROUP) # echo $ADMINKEY if [[ -z $SYSID ]] then echo Admin Key for $HOSTNAME LACP group $GROUP not found exit 2 fi OPERKEY=$(snmpwalk -v 1 -c $COMMUNITY $HOSTNAME -Oq -Oe -Ov 1.2.840.10006.300.43.1.1.1.1.7.$GROUP) # echo $OPERKEY if [[ -z $SYSID ]] then echo Oper Key for $HOSTNAME LACP group $GROUP not found exit 2 fi # IEEE8023-LAG-MIB::dot3adAggPortActorOperKey # 1.2.840.10006.300.43.1.2.1.1.5 # Port -> OperKey PORTS=$(snmpwalk -mALL -v 1 -c $COMMUNITY $HOSTNAME -Oq 1.2.840.10006.300.43.1.2.1.1.5 | sed -e 's/^.*\.//' -e 's/\( [0-9]*\)/\1X/' | egrep " $OPERKEY""X" | sed -e 's/ .*//') # snmpwalk -mALL -v 1 -c $COMMUNITY $HOSTNAME -Oq 1.2.840.10006.300.43.1.2.1.1.5 NUMPORTS=$(echo $PORTS | wc -w) # echo $PORTS $NUMPORTS # IEEE8023-LAG-MIB::dot3adAggPortActorOperState # 1.2.840.10006.300.43.1.2.1.1.21 ERRORS=0 for i in $PORTS do CODE=$(snmpwalk -mALL -v 1 -c $COMMUNITY $HOSTNAME -Oq 1.2.840.10006.300.43.1.2.1.1.21.$i | sed -e 's/[^"]*"//' -e 's/ .*//' -e 's/".*//') # echo X$CODE""X if [[ $CODE != "3D" && $CODE != "BC" ]] then ((ERRORS = ERRORS+1)) fi # echo $ERRORS echo -n $(snmpwalk -mALL -v 1 -c $COMMUNITY $HOSTNAME 1.3.6.1.2.1.2.2.1.2.$i | sed -e 's/^[^=]*= //' -e 's/STRING: //') " " snmpwalk -mALL -v 1 -c $COMMUNITY $HOSTNAME 1.2.840.10006.300.43.1.2.1.1.21.$i | sed -e 's/.*BITS: //' # fi done # echo $PORTS $NUMPORTS $ERRORS if (( ERRORS > 0 )) then if (( ERRORS == NUMPORTS )) then exit 2 else exit 1 fi else exit 0 fi