MIB Smithy SDK provides mechanisms for triggering events to be called for different kinds of messages sent or received, such as notifications (traps and informs). Seperate event handlers can be triggers for traps only, informs only, and/or both traps and informs, or all messages sent or received. Notification event handlers take approximately the same form as Callback Functions, but without the initial id
parameter. Handlers are registered and unregistered using the bind
session command.
Notifications can be received either on the automatically-assigned port that is used by the session to send requests or on the configured "local port" for the session, which defaults to port 162. By default, the SDK will listen for incoming notifications on all applicable interfaces. The session can be configured to listen for notifications on a specific interface by specifying that interface's IP address or hostname to the session's -localaddress
property.
% session bind ?event ?handler??
snmpcmd
event
handler
bind
command will return a list of event types for which handlers have been registered.handler
argument, the bind
command will return the currently registered handler for the specified event.-inform
-notifications
-notify
-notifications
.-recv
-send
-trap
# Load the MIB Smithy SDK into Tcl package require SmithySDK # Load MIB file - you'll need one of these for each dependency, up to # 5 modules with the evaluation version. # smilib import -file your-mib-file.mib # Define a simple handler to dump trap information to stdout # args gets a list of paired items containing all information parsed # out of the message and trap PDU. proc printNotification { args } { foreach { param value } $args { if {$param == "-varbinds"} { foreach vb $value { set varOID [lindex $vb 0] set varType [lindex $vb 1] set varValue [lindex $vb 2] set varName [smilib get -name $varOID] set varSuffix [smilib get -oidsuffix $varOID] if {$varSuffix != ""} { append varName ".$varSuffix" } puts "VB $varName == $varValue (type $varType)" } } else { puts "$param == $value" } } } # If necessary, configure a different port to listen to for traps. # Default port is 162, which requires root priviledges on Unix. # snmplib config -localport 4000 # Register the handler to be called for all notification types. # Use -trap for only traps or -inform for only informs. snmplib bind -notifications printNotification # Wait for ever, processing events, if running in the Tcl shell # (Tcl will not process events at the normal Tcl shell prompt, but # the wish shell will.) vwait forever