MIB Smithy

  1. Up to Table of Contents

Receiving Notifications

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??


is the name of session interested in receiving notifications;
specifies the type of event to be registered; and
is the handler to be called when the event is triggered or an empty string 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.

Event Types:

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.
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.
Equivalent to -notifications.
Specifies or queries the event handler that is called for each message received regardless of PDU type. If configured, this handler is called even if another handler for the PDU (e.g. notification) is also configured.
Specifies or queries the event handler that is called for each message sent regardless of PDU type.
Specifies or queries the event handler that is called only for notification types containing the SNMPv1 or SNMPv2 Trap PDUs.

Example - simple command-line notification log

# 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
  1. Up to Table of Contents