API reference

While Snimpy is targeted at being used interactively or through simple scripts, you can also use it from your Python program.

It provides a high-level interface as well as lower-level ones. However, the effort is only put in th manager module and other modules are considered as internal details.

manager module

Internal modules

Those modules shouldn’t be used directly.

mib module

snmp module

This module is a low-level interface to build SNMP requests, send them and receive answers. It is built on top of pysnmp but the exposed interface is far simpler. It is also far less complete and there is an important dependency to the basictypes module for type coercing.

exception snimpy.snmp.SNMPAuthorization
exception snimpy.snmp.SNMPBadValue[source]
exception snimpy.snmp.SNMPCommitFailed
exception snimpy.snmp.SNMPEndOfMibView
exception snimpy.snmp.SNMPException[source]

SNMP related base exception. All SNMP exceptions are inherited from this one. The inherited exceptions are named after the name of the corresponding SNMP error.

exception snimpy.snmp.SNMPGen
exception snimpy.snmp.SNMPInconsistentName
exception snimpy.snmp.SNMPInconsistentValue
exception snimpy.snmp.SNMPNoAccess
exception snimpy.snmp.SNMPNoCreation
exception snimpy.snmp.SNMPNoSuchInstance
exception snimpy.snmp.SNMPNoSuchName[source]
exception snimpy.snmp.SNMPNoSuchObject
exception snimpy.snmp.SNMPNotWritable
exception snimpy.snmp.SNMPReadOnly[source]
exception snimpy.snmp.SNMPResourceUnavailable
exception snimpy.snmp.SNMPTooBig[source]
exception snimpy.snmp.SNMPUndoFailed
exception snimpy.snmp.SNMPWrongEncoding
exception snimpy.snmp.SNMPWrongLength
exception snimpy.snmp.SNMPWrongType
exception snimpy.snmp.SNMPWrongValue
class snimpy.snmp.Session(host, community='public', version=2, secname=None, authprotocol=None, authpassword=None, privprotocol=None, privpassword=None, contextname=None, bulk=40, none=False)[source]

SNMP session. An instance of this object will represent an SNMP session. From such an instance, one can get information from the associated agent.

bulk

Get bulk settings.

Returns:False if bulk is disabled or a non-negative integer for the number of repetitions.
get(*oids)[source]

Retrieve an OID value using GET.

Parameters:oids – a list of OID to retrieve. An OID is a tuple.
Returns:a list of tuples with the retrieved OID and the raw value.
retries

Get number of times a request is retried.

Returns:Number of retries for each request.
set(*args)[source]

Set an OID value using SET. This function takes an odd number of arguments. They are working by pair. The first member is an OID and the second one is basictypes.Type instace whose pack() method will be used to transform into the appropriate form.

Returns:a list of tuples with the retrieved OID and the raw value.
timeout

Get timeout value for the current session.

Returns:Timeout value in microseconds.
walk(*oids)[source]

Walk from given OIDs but don’t return any “extra” results. Only results in the subtree will be returned.

Parameters:oid – OIDs used as a start point
Returns:a list of tuples with the retrieved OID and the raw value.
walkmore(*oids)[source]

Retrieve OIDs values using GETBULK or GETNEXT. The method is called “walk” but this is either a GETBULK or a GETNEXT. The later is only used for SNMPv1 or if bulk has been disabled using bulk() property.

Parameters:oids – a list of OID to retrieve. An OID is a tuple.
Returns:a list of tuples with the retrieved OID and the raw value.

basictypes module