Grab multiple OIDs via SNMPwalk

SNMPWALK is a great too for grabbing SNMP oject identifier values (OIDs). To see how to install it see this post here.

Mostly I use it for checking various single OID values but sometimes is can be useful to grab more than one value.  SNMPwalk itself doesn’t allow for you to grab more than one specific OID at a time. You can pipe the output through some other tools to make it output more than one value but I find it easier just to make a simple bash script.

This example is a very simple snmpwalk script that will do a basic inventory check of Cisco ASA devices. It will grab the hostname, serial number, software version and the hardware type. You can see the basic structure and then taylor it to your own needs 🙂

#!/bin/bash
# Grabbing more than one OID from Cisco ASA
echo "############################"
echo "#                          #"
echo "# Mutiple value SNMPwalker #"
echo "#  http://www.m00nie.com   #"
echo "#                          #"
echo "############################"
echo
cat $1 | while read line; do
        NAME=`snmpwalk -v 2c -c m00nily $line SNMPv2-MIB::sysName.0 | grep -o '[^ ]*$'`
        SERIAL=`snmpwalk -v 2c -c m00nily $line SNMPv2-SMI::mib-2.47.1.1.1.1.11.1 | grep -o '[^ ]*$'`
        TYPE=`snmpwalk -v 2c -c m00nily $line SNMPv2-SMI::mib-2.47.1.1.1.1.13.1 | grep -o '[^ ]*$'`
        SOFT=`snmpwalk -v 2c -c m00nily $line SNMPv2-SMI::mib-2.47.1.1.1.1.10.1 | grep -o '[^ ]*$'`
        echo " $NAME = $SERIAL running $SOFT on $TYPE "
done

Save the above script as snmpwalker then its run by executing bash snmpwalker somefile. The “somefile” should be a file listing all the IPs you want to run this script against. Each IP should be on its own line.  The bash script is pretty straight forward, it runs snmpwalk multiple times to grab the values then pipes it through grep to return on the value of the last word separated by a blank space.

An example of the output:

[m00nie@N0C 11] bash snmpwalking firewalls
############################
#                          #
# Mutiple value SNMPwalker #
#  http://www.m00nie.com   #
#                          #
############################

 5505.m00nie.com = "XXXXXXXXXXX" running "8.2(1)" on "ASA5505"
 5510.m00nie.com = "XXXXXXXXXXZ" running "8.1(1)" on "ASA5510"
 5520.m00nie.com = "XXXXXXXXXXQ" running "8.4(2)" on "ASA5520"
 ...
 5505B.m00nie.com = "XXXXXXXXXXY" running "8.2(1)" on "ASA5505"

You can find out how to list ALL cisco ASA OIDS [here].

Enjoy 🙂

m00nie

Leave a Reply