Each session may have its own file channel configured for printing hex dumps of sent and received SNMP messages messages. By default, no channel is configured and hex dumps are not generated. It can be any type of channel recognized by Tcl's "puts" command (such as an actual file or a memory channel using the freely-available "memchan" package). If you want, for example, for hex dumps to be sent to stderr, captured for display within your own GUI, or for each session to log to a different channel, then the session(s) can be configured to do so.
To enable hex dumps, the session's -logchannel
is configured with the name of the channel(s) where they should be printed. You can specify one channel for both sent and received messages or a list of two channels for sent and received messages to be sent to separately (or to only print messages going in one direction).
% session config -logchannel channel
% session config -logchannel { sendChannel recvChannel }
Either or both channels may be set to an empty string to disable the packet traces.
% snmplib config -logchannel stdout % snmplib get sysUpTime.0 Sending 43 bytes to 127.0.0.1#161 0000: 30 29 02 01 00 04 06 70 75 62 6c 69 63 a0 1c 02 0).....public... 0016: 04 60 d5 7a 9b 02 01 00 02 01 00 30 0e 30 0c 06 .`.z.......0.0.. 0032: 08 2b 06 01 02 01 01 03 00 05 00 .+......... Received 47 bytes from 127.0.0.1#161 0000: 30 2d 02 01 00 04 06 70 75 62 6c 69 63 a2 20 02 0-.....public. . 0016: 04 60 d5 7a 9b 02 01 00 02 01 00 30 12 30 10 06 .`.z.......0.0.. 0032: 08 2b 06 01 02 01 01 03 00 43 04 29 04 b2 ce .+.......C.)...
In addition to logging pre-formatted messages directly to a channel configured through the sessions's -logchannel
setting, the SDK can invoke a user-specified callback with details about the message as separate fields using the -logcommand
setting. Details are provided as separate fields, which can be assembled to generate messages in a desired format.
Callbacks take the form:
proc callback { args } { ... }
The args
parameter receives a dictionary (key+value pairs) with the following keys:
address address
dir
.data data
dir direction
send
or recv
)dump text
-logchannel
.length count
port port
dir
.% proc onLogEvent { args } { foreach { key value } $args { if {$key != "data"} { puts "$key=$value" } else { puts "data=(elided)" } } } % snmplib config -logcommand onLogEvent % snmplib get sysUpTime.0 dir=send address=127.0.0.1 port=161 length=43 data=(elided) dump=0000: 30 29 02 01 00 04 06 70 75 62 6c 69 63 a0 1c 02 0).....public... 0016: 04 60 d5 7a 9a 02 01 00 02 01 00 30 0e 30 0c 06 .`.z.......0.0.. 0032: 08 2b 06 01 02 01 01 03 00 05 00 .+......... dir=recv address=127.0.0.1 port=161 length=47 data=(elided) dump=0000: 30 2d 02 01 00 04 06 70 75 62 6c 69 63 a2 20 02 0-.....public. . 0016: 04 60 d5 7a 9a 02 01 00 02 01 00 30 12 30 10 06 .`.z.......0.0.. 0032: 08 2b 06 01 02 01 01 03 00 43 04 29 04 12 33 .+.......C.)..3