#!/bin/bash OK=0 CRITICAL=2 STATE=0 PLUGIN_PATH="/usr/local/nagios/libexec/plugins" outputfile=/var/log/bgp.log OID_sysDescr=SNMPv2-MIB::sysDescr.0 OID_lag=1.2.840.10006.300.43.1.1.1 COMMUNITY=********* VERSION="1.0" 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: hafthanhf" echo "Hanoi - 2014" } print_help() { print_version echo "" print_usage echo "**** Check the status of LACP link ****" echo -e "This script opertates based on checking the speed of a LACP port, \nif one of its link goes down, the speed will decrease respectively.\nBased on that the Script gives the alarm exactly" echo "" echo -e "-H ADDRESS - Hostname to query (default: 127.0.0.1)\n -p Port name \n -n number of link in a LACP bundle \n -V Print version" echo "-h Print this help" } # Arguments while getopts H:p:n:hV OPT do case "$OPT" in H) HOSTNAME="$OPTARG" ;; p) portname="$OPTARG";; n) amount="$OPTARG";; h) print_help exit $STATE ;; V) print_version exit $STATE ;; esac done ############################ ######---Main----########### ############################ #Get system infomation sysinfo=`snmpwalk -v 2c -c $COMMUNITY $HOSTNAME $OID_sysDescr | awk 'NR==1 {print $4}'` if [ "$amount" -gt "4" ]; then echo "Cannot check, too many link" exit 3 fi #SPEED=`expr $amount \* 1000000000` case "$sysinfo" in Cisco) lacp="Port-channel" ;; Juniper) lacp="ae" ;; esac #echo $lacp #echo $sysinfo portid=`snmpwalk -v 2c -c $COMMUNITY $HOSTNAME IF-MIB::ifDescr | grep -w "\ $portname$" | awk -F '[{. }]' '{print $2}'` #echo $portid portalias=`snmpwalk -v 2c -c $COMMUNITY $HOSTNAME IF-MIB::ifAlias | grep "$portid" ` #echo $portalias #echo "List Port-channel:" #snmpwalk -v 2c -c $COMMUNITY $HOSTNAME IF-MIB::ifDescr | grep $lacp | awk '{print $4}' speed=`snmpwalk -v 2c -c $COMMUNITY $HOSTNAME IF-MIB::ifSpeed.$portid | awk '{print $4}'` SPEED=`expr $speed / 1000000000` echo "Interface Speed: $SPEED Gbps" if [ "$SPEED" -lt "$amount" ]; then echo "One of the link is down, plz check this link " exit 2 else echo "link OK" exit 0 fi ################# INFO ############ ###########################################