Using the Tcl shell, Tcl commands can perform actions on MIBs. The following example shows how to set up the community access
strings to permit access to SNMP. Public access is read-only, but private access is read-write. The following example shows
how to retrieve a large section of a table at once using the snmp_getbulk Tcl command extension.
Two arguments, non-repeaters and max-repetitions , must be set when an snmp_getbulk command is issued. The non-repeaters argument specifies that the first N objects are to be retrieved with a simple snmp_getnext operation. The max-repetitions argument specifies that up to M snmp_getnext operations are to be attempted to retrieve the remaining objects.
In this example, three bindings--sysUpTime (1.3.6.1.2.1.1.2.0), ifDescr (1.3.6.1.2.1.2.2.1.2), and ifType (1.3.6.1.2.1.2.2.1.3)--are
used. The total number of variable bindings requested is given by the formula N + (M * R), where N is the number of non-repeaters
(in this example 1), M is the max-repetitions (in this example 5), and R is the number of request objects (in this case 2,
ifDescr and ifType). Using the formula, 1 + (5 * 2) equals 11; and this is the total number of variable bindings that can
be retrieved by this snmp_getbulk request command.
Sample results for the individual variables include a retrieved value of sysUpTime.0 being 1336090, where the unit is in milliseconds.
The retrieved value of ifDescr.1 (the first interface description) is FastEthernet0/0, and the retrieved value of ifType.1
(the first interface type) is 6, which corresponds to the ethernetCsmacd type.
snmp-server community public RO
snmp-server community private RW
tclsh
snmp_getbulk public 1 5 1.3.6.1.2.1.1.2.0 1.3.6.1.2.1.2.2.1.2 1.3.6.1.2.1.2.2.1.3
{<obj oid='sysUpTime.0' val='1336090'/>}
{<obj oid='ifDescr.1' val='FastEthernet0/0'/>}
{<obj oid='ifType.1' val='6'/>}
{<obj oid='ifDescr.2' val='FastEthernet1/0'/>}
{<obj oid='ifType.2' val='6'/>}
{<obj oid='ifDescr.3' val='Ethernet2/0'/>}
{<obj oid='ifType.3' val='6'/>}
{<obj oid='ifDescr.4' val='Ethernet2/1'/>}
{<obj oid='ifType.4' val='6'/>}
{<obj oid='ifDescr.5' val='Ethernet2/2'/>}
{<obj oid='ifType.5' val='6'/>}
The following example shows how to retrieve the sysDescr.0, sysObjectID.0, sysUpTime.0, sysContact.0, sysName.0, and sysLocation.0
variables--in this example shown as system.1.0, system.2.0, system.3.0, system.4.0, system.5.0, and system.6.0--from the SNMP
entity on the router using the snmp_getid Tcl command extension.
tclsh
snmp_getid public
{<obj oid='system.1.0' val='Cisco Internetwork Operating System Software
Cisco IOS XE(tm) 7200 Software (C7200-IK9S-M), Experimental Version 12.3(20030507:225511)
[geotpi2itd1 124]
Copyright (c) 1986-2003 by Cisco Systems, Inc.
Compiled Wed 21-May-03 16:16 by engineer'/>}
{<obj oid='system.2.0' val='products.223'/>}
{<obj oid='sysUpTime.0' val='6664317'/>}
{<obj oid='system.4.0' val='1-800-553-2447 - phone the TAC'/>}
{<obj oid='system.5.0' val='c7200.myCompany.com'/>}
{<obj oid='system.6.0' val='Bldg 24, San Jose, CA'/>}
The following example shows how to retrieve a set of individual variables from the SNMP entity on the router using the snmp_getnext Tcl command extension:
snmp_getnext public 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.2.0
{<obj oid='system.2.0' val='products.223'/>}
{<obj oid='sysUpTime.0' val='6683320'/>}
The following example shows how to retrieve a set of individual variables from the SNMP entity on the router using the snmp_getone Tcl command extension:
snmp_getone public 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.2.0
{<obj oid='system.1.0' val='Cisco Internetwork Operating System Software
Cisco IOS XE(tm) 7200 Software (C7200-IK9S-M), Experimental Version 12.3(20030507:225511)
[geotpi2itd1 124]
Copyright (c) 1986-2003 by Cisco Systems, Inc.
Compiled Wed 21-May-03 16:16 by engineer'/>}
{<obj oid='system.2.0' val='products.223'/>}
The following example shows how to change something in the configuration of the router using the snmp_setany Tcl command extension. In this example, the hostname of the router is changed to TCLSNMP-HOST.
tclsh
snmp_setany private 1.3.6.1.2.1.1.5.0 -d TCLSNMP-HOST
{<obj oid='system.5.0' val='TCLSNMP-HOST'/>}