Using Tcl for SNMP communication
Now that we have performed SNMP queries using TkIned, we can move on to using Scotty from Tcl directly to communicate over SNMP.
Querying SNMP in Tcl
The Tnm
package offers a large number of features. Main part of its functionality is related to SNMP and MIB.
A quick example to query SNMPv2-MIB::sysContact
value over SNMP can be as follows:
set session [Tnm::snmp generator] $session configure -address "192.168.2.2" \ -version "SNMPv1" -community "private" puts [$session get SNMPv2-MIB::sysContact.0]
This will create a connection handle, configure it to query the IP 192.168.2.2
over SNMPv1
protocol and get sysContact
value. This will print out something like the following:
{1.3.6.1.2.1.1.4.0 {OCTET STRING} root@router}
This is a list of a single element, which is a sub-list with three elements—OID of the item, data type, and actual value. In order to print out just the value we can get get the third element from the first item by doing:
puts [lindex \ [$session...