| < Prev | Back to Table of Contents | Next > |
Versions 2.1 and later of MIB Smithy SDK provide mechanisms for
triggering events to be called for notifications (traps and informs).
Seperate event handlers can be triggers for traps only, informs only,
and/or both traps and informs. 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.
% session bind ?event
?handler??
..where snmpcmd is the name of session
interested in receiving notifications, event
specifies the type of event to be registered, and
handler is the handler to be called when the
event is triggered.
An empty string may be passed to the
handler argument to unregister the event
handler.
When called with no arguments, the bind command will
return a list of event types for which handlers have been
registered.
When called only with an event type and no handler
argument, the bind command will return the currently
registered handler for the specified event.
Otherwise, nothing is returned.
| Option | Description |
|---|---|
-trap |
Specifies or queries the event handler that is called only for notification types containing the SNMPv1 or SNMPv2 Trap PDUs. |
-inform |
Specifies or queries the event handler that is called only for inform requests. The SDK automatically sends responses to the informs, so the event handler need not perform any special actions other than those typically used for a trap handler. |
-notifications |
Specifies or queries the event handler that is called for all notification types (both traps and informs), which may be separate or in addition to individual handlers for each. |
-notify |
Equivalent to -notifications. |
# 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
| < Prev | Back to Table of Contents | Next > |