Walking Subtrees
Versions 3.4 and later of MIB Smithy SDK support automated SNMP Get-Next walks of subtrees or entire agents using the SNMP Session's walk
subcommand. Like individual requests, the command may be used either in synchronous or asynchronous mode, depending on whether or not the -callback
parameter is been specified. Using the walk
command is particularly useful for gathering table data, and most options available to other request types are available to the walk.
Syntax:
% snmpcmd walk ?option value ...? ?varBindList?
Where:
snmpcmd
- is the name of session whose configuration identifies the agent to send the request to;
option value
- are zero or more option+value pairs that may be present to override session configuration or other aspects of the request; and
varBindList
- is an optional list of zero or more Variable Bindings to include in the request.
If the varBindList
parameter is unspecified or empty, the SDK will walk the entire agent starting at 0.0. Otherwise, the SDK will issue a get-next with the given variable bindings and continue issuing get-nexts with the response OIDs until one or more of them is in a different subtree. In either case, the walk stops if a request times out, is cancelled, or the end of the MIB view is reached.
Returns:
- In asynchronous mode: a unique identifier that can be used by the callback procedure to later correlate response and result information to the request.
- In synchronous mode: a list of variable bindings containing all of the values returned by the agent during the walk.
Request Options
-address address
- Specifies the IP address or hostname to send the request to. This option overrides the default address configured for the session.
-alias name
- Specifies the name an alias of preconfigured options that are to be subsituted in place of the alias in the
walk
command.
-callback proc
- Specifies the name of a Tcl procedure to be evaluated when a response is received or a timeout occurs. This procedure will be passed the unique identifier for the pending request and any result and response information received. If specified, the request will be performed in asynchronous mode, and synchronous mode otherwise.
-community string
- Specifies the community string to use in the request if transmitting via SNMPv1 or SNMPv2c. This option overrides the default read community string configured for the session.
-ctxengineid string
- Specifies the contextEngineID value to use for SNMPv3 messages. An empty string (default) indicates that the same value as msgAuthoritativeEngineID is to be used for contextEngineID.
-ctxname string
- Specifies the contextName value to use for SNMPv3 messages.
-db name
- Specifies the name of the SMI Database to use for any necessary lookups for data types or converting names to OIDs in the request. This option overrides the default SMI Database configured for the session.
-delay ms
- Specifies a delay (in milliseconds) to wait before sending each SNMP message, which may be used to mitigate network congestion issues. This option overrides the default delay configured for the session.
-port port
- Specifies the integer port number or service name to send the request to. This option overrides the default port configured for the session.
-retries count
- Specifies the number of attempts to be made to retransmit the request if no response is received. This option overrides the default number of retries configured for the session.
-timeout ms
- Specifies the integer timeout (in milliseconds) to wait before either retransmitting the message or signalling a timeout to the calling script (or callback), depending on the number of attempts made and the number of configured retries. This option overrides the default timeout configured for the session.
-version version
- Specifies the SNMP version to use when sending the request. This option overrides the default SNMP version configured for the session. The valid values accepted are the same as those for the
config
command.
Example 1 - Synchronous Walk of system Subtree
% foreach vb [snmplib walk system] { puts $vb }
1.3.6.1.2.1.1.1.0 {OCTET STRING} {Example sysDescr}
1.3.6.1.2.1.1.2.0 {OBJECT IDENTIFIER} 1.3.6.1.4.1.8072.3.2.8
1.3.6.1.2.1.1.3.0 TimeTicks 772878758
1.3.6.1.2.1.1.4.0 {OCTET STRING} {Example sysContact}
1.3.6.1.2.1.1.5.0 {OCTET STRING} {Example sysName}
1.3.6.1.2.1.1.6.0 {OCTET STRING} Unknown
1.3.6.1.2.1.1.8.0 TimeTicks 4
Example 2 - Asynchronous Walk of system Subtree
% proc cb { id args } {
array set resp $args
if {$resp(-status) == "noError"} {
foreach vb $resp(-varbinds) { puts $vb }
}
}
% snmplib walk -callback cb system
2
% snmplib wait 2
1.3.6.1.2.1.1.1.0 {OCTET STRING} {Example sysDescr}
1.3.6.1.2.1.1.2.0 {OBJECT IDENTIFIER} 1.3.6.1.4.1.8072.3.2.8
1.3.6.1.2.1.1.3.0 TimeTicks 772878758
1.3.6.1.2.1.1.4.0 {OCTET STRING} {Example sysContact}
1.3.6.1.2.1.1.5.0 {OCTET STRING} {Example sysName}
1.3.6.1.2.1.1.6.0 {OCTET STRING} Unknown
1.3.6.1.2.1.1.8.0 TimeTicks 4
Example 3 - Synchronous Walk of Entire Agent
% puts "Agent has [llength [snmplib walk]] variables"
Agent has 1529 variables