Previous section   Next section

Recipe 17.2 Extracting Router Information via SNMP Tools

17.2.1 Problem

You wish to extract or change router information via SNMP.

17.2.2 Solution

To extract router information via SNMP, we will use the suite of SNMP tools provided with the NET-SNMP toolkit (see Appendix A for more details).

Use snmpget to extract a single MIB object from the router's MIB tree. This example uses snmpget to extract the router's system contact information:

freebsd% snmpget -v1 -c ORARO Router .1.3.6.1.2.1.1.4.0
system.sysContact.0 = Helpdesk  800-555-2992

Use snmpset to alter MIB objects within the router's MIB tree. The next example demonstrates how to modify MIB variables, using snmpset to change the system contact information:

freebsd% snmpset -v1 -c ORARW Router .1.3.6.1.2.1.1.4.0 s "Ian Brown 555-1221"
system.sysContact.0 = Ian Brown 555-1221
freebsd% snmpget -v1 -c ORARO Router sysContact.0
system.sysContact.0 = Ian Brown 555-1221

The snmpwalk utility extracts a series of MIB objects from the router's MIB tree. This example uses snmpwalk to extract all of the router's interface descriptions:

freebsd% snmpwalk -v1 -c ORARO Router ifDescr 
interfaces.ifTable.ifEntry.ifDescr.1 = "Ethernet0"
interfaces.ifTable.ifEntry.ifDescr.2 = "Serial0"
interfaces.ifTable.ifEntry.ifDescr.3 = "Serial1"
interfaces.ifTable.ifEntry.ifDescr.4 = "Null0"
interfaces.ifTable.ifEntry.ifDescr.5 = "Loopback0"
interfaces.ifTable.ifEntry.ifDescr.6 = "Serial0.1"
freebsd%

17.2.3 Discussion

In this recipe, we use the suite of SNMP tools provided by the NET-SNMP project (formerly UCD-SNMP) to demonstrate basic SNMP functionality. NET-SNMP provides a variety of useful SNMP tools that you can run from the command-line interface of any Unix or Windows workstation. This software is freely distributed and is available on a variety of platforms, which makes it extremely popular for scripts of all shapes and sizes. We consider NET-SNMP to be a sort of Swiss army knife of SNMP that wonderfully illustrates the usefulness of SNMP for working with Cisco routers. Of course, many commercial software vendors also provide SNMP tools that are equally effective and frequently include a graphical user interface. The underlying concepts remain the same, even if the command syntax differs. In some cases it is easier to do the types of SNMP commands shown in this recipe using a graphical user interface, rather than a command-line utility.

NET-SNMP provides a set of SNMP utilities for performing various useful SNMP functions. This recipe used three of the most basic tools.

Note that leaving out the MIB object or OID causes snmpwalk to walk the entire MIB tree. This can cause CPU overload problems on the router, as well as congestion problems on low-speed links.

Most NMS systems have similar commands that you can access from the command line and use in scripts. See your software documentation for details.

Table 17-1Table 17-1 shows a number of useful MIB entries and their associated OID numbers. Several of these variables are Cisco-specific, and will not make sense if used on equipment from other vendors.

Table 17-2. Common Cisco router SNMP MIB entries

MIB name

Description

OID

sysName

Hostname

.1.3.6.1.2.1.1.5.0

sysUpTime

Uptime

.1.3.6.1.2.1.1.3.0

sysDescr

System Description

.1.3.6.1.2.1.1.1.0

sysContact

System Contact

.1.3.6.1.2.1.1.4.0

sysLocation

System Location

.1.3.6.1.2.1.1.6.0

ciscoImageString.5

IOS Version

.1.3.6.1.4.1.9.9.25.1.1.1.2.5

avgBusy1

1-Minute CPU Util.

.1.3.6.1.4.1.9.2.1.57.0

avgBusy5

5-Minute CPU Util.

.1.3.6.1.4.1.9.2.1.58.0

freeMem

Free memory

.1.3.6.1.4.1.9.2.1.8.0

ciscoImageString.4

IOS feature set

.1.3.6.1.4.1.9.9.25.1.1.1.2.4

whyReload

Reload reason

.1.3.6.1.4.1.9.2.1.2.0

A complete listing of Cisco-supported MIBs are located at http://www.cisco.com/public/sw-center/netmgmt/cmtk/mibs.shtml. Note that this includes a huge amount of information. However, with a little time and effort, you should be able to find a way to extract exactly the information you need.

You can extract the same MIB objects using SNMPv2c:

freebsd% snmpget -v 2c -c ORARO Router sysContact.0
system.sysContact.0 = Ian Brown 416-555-2943
freebsd%

The only difference in this example is that we specified the SNMP version number as part of the snmpget command syntax. This is useful because SNMPv2c introduced 64-bit counters. Cisco supports a small number of MIB objects that can only be accessed using SNMPv2c (or SNMPv3). One such MIB object is ifHCInOctets:

Freebsd% snmpwalk -v 2c -c ORARO Router ifHCInOctets           
ifHCInOctets.7 = Counter64: 145362298
ifHCInOctets.8 = Counter64: 85311547
Freebsd%

This MIB object counts the number of inbound bytes (octets) received by an interface. The older SNMPv1 ifInOctets MIB object counts exactly the same thing, but uses a 32-bit variable to hold the number. The newer object does not roll over to zero as often, making it more useful for high-speed interfaces. If you attempt to get one of these 64-bit counter objects using SNMPv1, the query will fail.

17.2.4 See Also

Recipe 17.1; Recipe 17.21; Appendix A


  Previous section   Next section
Top