Session objects

The Session class, once instantiated, represents a virtual connection to the peername. The methods described below, represent SNMP commands as well as convenience methods, to help in dealing with the MIB trees and tables.

When supplying miboid to get(), getnext(), getbulk(), set() and trap(), you can supply as many valid MIBOIDs as you want (as strings). Either you can pass a list or a tuple of MIBOIDs, or simply pass them as multiple arguments to the methods. In both cases, all MIBOIDs you provide will be bundled in the same PDU, and thus in one single packet. If you exceed the maximum size of the PDU (which depends on the MTU), either on the outgoing packet or on the response incoming packet, the SendError exception will be raised. The methods will return a tuple with the results of the respective SNMP commands, in the same order you provided them. Note: if you provide only one miboid to get(), getnext() and set(), the result will not be a tuple, unless you provide the single argument as a one element list or tuple.

A Session instance has the following methods:

get(miboid, [miboid, ...])
Performs an SNMP GET. The result for each miboid corresponds to a string.
getnext(miboid, [miboid, ...])
Performs an SNMP GETNEXT. The result for each miboid is a tuple containing two strings.
getbulk(miboid, [miboid, ...], [non_repeaters=non_repeaters, [max_repetitions=max_repetitions]]))
Performs an SNMP GETBULK. The result is a tuple of tuples (containing the string pair). The optional parameter non_repeaters, allows you to specify how many of the miboids you provide as argument, should be treated as a GETNEXT (returning only the next MIBOID), and defaults to 0. The max_repetitions argument allows you to specify how many MIBOIDs follow the miboids given as arguments, and defaults to 100.
set(miboid, [miboid, ...])
Performs an SNMP SET. The input arguments miboid must be a list or tuple, containing three strings, the first corresponding to the MIBOID, the second identifying the type (see net-snmp documentation for details), and the third representing the value you wish to set it to. You can provide as many miboid tuples as you wish. The result is the same as with the getnext() method.
trap(uptime, trapoid, miboid, [miboid, ...])
Performs an SNMP TRAP (v2). The uptime is a string representing timeticks (see sysUpTime.0), trapoid is a valid MIBOID and miboid follows the three string tuple concept described for set(). The function returns immediately, without returning anything, as traps are fire and forget.
walk(miboid)
Walk is not an SNMP command. You supply one miboid to this method, and it will return a tuple of tuples containing the whole MIB tree corresponding to that miboid. If the class was instantiated to use SNMP version 2c or higher, the GETBULK command will be used instead of GETNEXT, to drastically reduce the number of packets required to obtain the tree, and thus substantially increase performance.
table(miboid)
Supply this method with a miboid corresponding to a table, and it will return you a tuple of dictionaries representing the table. The tuple represents the rows (for each instance), and the dictonary has keys corresponding to the various MIBOIDs composing that table, with the values being the returned values from the actual query.

Yves Perrenoud