Created
July 4, 2013 10:27
-
-
Save yee379/5926619 to your computer and use it in GitHub Desktop.
dumps a bunch of snmp information from a list of devices and if indexes - stick in cron job to have easy network monitoring!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# simple script to collect some snmp information from a list of switches and interfaces and dump the result into $DIR | |
# currently configured to grab the in and out octet counters | |
# provide a hash of the network device and the if indexes that you wish to monitor, | |
# eg ["rtr-farm02"]="380 53 58" will monitor the device rtr-farm02 on if index 380, 53 and 58 | |
declare -A INTERFACES | |
INTERFACES=( ["swh-farm02a"]="12" ["rtr-farm02"]="380 53 58" ["rtr-farmcore1"]="117" ["rtr-core1"]="9" ["rtr-border2"]="20 3 7" ) | |
DIR='/scratch/atl-prod10/' | |
COMMUNITY=`cat /opt/etc/snmp.community.read` | |
OIDS=( ifHCInOctets ifHCOutOctets ) | |
CMD="/usr/bin/snmpget -v2c -c $COMMUNITY -On {{ DEVICE }} {{ OID }}.{{ IF_INDEX }}" | |
for d in "${!INTERFACES[@]}"; do | |
# echo $d | |
for i in ${INTERFACES[$d]}; do | |
declare -A DATA | |
DATE=$(/bin/date +"%Y-%m-%d %T %z") | |
for o in "${OIDS[@]}"; do | |
THIS_CMD=`echo \"$CMD\" | sed -e s/'{{ DEVICE }}'/$d/g -e s/'{{ OID }}'/$o/g -e s/'{{ IF_INDEX }}'/$i/g | sed s/\"//g` | |
DATA[$o]=$($THIS_CMD | awk '{print $4}') | |
done | |
echo -e "$DATE\t$d\t$i\t${DATA['ifHCInOctets']}\t${DATA['ifHCOutOctets']}" >> $DIR/$(/bin/date +"%Y-%m-%d").txt | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment