The pysnmp.role module defines manager and agent classes, representing SNMP manager and agent roles in a SNMP system. These classes implement network client (manager) and server (agent) respectively, that do blocking I/O over a single BSD socket. They are intended to serve as a network transport for SNMP messages, within a synchronous SNMP entity process, over a TCP/IP network.
The pysnmp.role code is a pure network transport facility -- it deals with abstract data items and has nothing to know about SNMP context. In order to build a complete SNMP entity, a SNMP message processing code should be used along. See SNMP protocol modules (v2c, v1) for that.
Consequently, any custom, task specific transport may be employed instead in user applications in conjunction with the SNMP protocol modules.
The pysnmp.role module defines the following items:
Returns a new instance of manager class, representing network client optionally connected to a network server running at dst address. The dst argument, whenever given, must follow the socket module notation -- ('hostname', port) where hostname a string and port is an integer.
The default for dst is None what means no default destination, so user would unconditionally have to specify destination to each manager.send() method (see below).
Once a default dst is specified, specific destination may not be given to the manager.send() method.
The iface parameter, if given, specifies the interface and port on local machine to bind() to. This argument must also follow the socket module notation. All further requests would then be originated from the given interface/port (for example, ('127.0.0.1', 0)).
The default for iface is ('0.0.0.0', 0) what stands for binding to a primary interface at the local machine.
Returns a new instance of agent class, representing network server optionally bound to specific network interfaces/ports ifaces at the local machine. The ifaces argument, whenever given, must be a list of ('ifacename', port) tuples (socket module notation).
The default for the ifaces is to listen on the loopback interface, port 161/UDP, so the default value is [('127.0.0.1', 161)].
Be aware that for a UNIX process to bind(2) to a low port, such as 161 (that is less than 1024), a superuser privelege is required. Since running scripts under superuser privelege is not particular secure in UNIX environment, binding to a non-priveleged port is therefore strongly recommended.
Exception raised on any error in the pysnmp.role module and its derivatives. This exception class is a subclass of the error.General class.
See documentation on the error.General base class for usage details.
The following exceptions are derived from this class:
Bad parameters given.
Besides being used to report various network related problems, this class also serves as a base class for a few specific exceptions (read on).
The following exceptions are derived from the NetworkError class:
No response arrived before timeout.
No request came before timeout.