Skip to content

Instantly share code, notes, and snippets.

@yeled
Created July 30, 2017 14:23
Show Gist options
  • Save yeled/69b864bebec8f80f2ea9ba7dd4ecfd43 to your computer and use it in GitHub Desktop.
Save yeled/69b864bebec8f80f2ea9ba7dd4ecfd43 to your computer and use it in GitHub Desktop.
snmp scrape LSP bandwidths from your router
#!/bin/bash
set -e
HOST=$1
COMMUNITY=$2
# http://www.juniper.net/documentation/en_US/junos12.3/topics/reference/mibs/mib-jnx-mpls.txt
# The number of octets that have been forwarded over current LSP active path.
LSP_BYTES=".1.3.6.1.4.1.2636.3.2.3.1.3"
# The configured bandwidth for this LSP, in units of thousands of bits per second (Kbps).
LSP_BW="1.3.6.1.4.1.2636.3.2.3.1.21"
LSP_RAW=$(snmpbulkwalk -v2c -Oan -c "$COMMUNITY" "$HOST" .1.3.6.1.4.1.2636.3.2.3.1.1 | awk '{sub(/^.1.3.6.1.4.1.2636.3.2.3.1.1/, "");print $1}')
declare -A LSP
for LSP_OID in $LSP_RAW ; do
# assign [oid]=name
LSP[$LSP_OID]=$(snmpget -v2c -Oan -c "$COMMUNITY" "$HOST" .1.3.6.1.4.1.2636.3.2.3.1.1${LSP_OID}|awk '{print $4}')
# print name
BYTES=$(snmpget -v2c -Ovq -c $COMMUNITY $HOST ${LSP_BYTES}${LSP_OID})
BW=$(snmpget -v2c -Ovq -c $COMMUNITY $HOST ${LSP_BW}${LSP_OID})
echo ${LSP[$(echo $LSP_OID)]}:\ \ Bytes:\ $(($BYTES / 1024 / 1024 ))MB\ Bw:\ $(( $BW / 1024 ))Mbps
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment