diff --git a/CHANGES.txt b/CHANGES.txt index 2583eb7d..b1cef80c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -26,6 +26,25 @@ Revision 5.0.0, released 2018-09-?? user-supplied `cbCtx` object throughout the MIB instrumentation methods. The goal is to let MIB objects access/modify whatever custom Python objects they need while being called back. +- The high-level API (`hlapi`) extended to cover lightweight SNMP v1arch + in hope to ease the use of packet-level SNMP API. + + By way of introducing v1arch hlapi, the sub-packages layout changed + so that `pysnmp.hlapi` is moved to `pysnmp.hlapi.v3arch` and the new + v1arch layer is introduced in `pysnmp.hlapi.v1arch`. This change does + not break backward compatibility as `pysnmp.hlapi` still defaults to + `pysnmp.hlapi.v3arch`. + + The `pysnmp.hlapi.v1arch` is designed to be as much similar in use + to `pysnmp.hlapi.v3arch`, but with high-performance in mind. One of + the consequences of this higher performance focus is that various + automation around building well-formed SNMP messages is and mediating + differences between SNMP versions is not present in this new `v1arch` + layer. +- The signature of the hlapi `.sendNotification()` call has changed + to accept `*varBinds` instead of a sequence of `varBinds`. The rationale + is to unify this method call with similar methods of CommandGenerator. + This change should not compromise backward compatibility with pysnmp 4. Revision 4.4.6, released 2018-09-XX ----------------------------------- diff --git a/docs/source/docs/api-reference.rst b/docs/source/docs/api-reference.rst index 8ff7d958..cb7c6d3f 100644 --- a/docs/source/docs/api-reference.rst +++ b/docs/source/docs/api-reference.rst @@ -3,44 +3,40 @@ Library reference ================= .. toctree:: - :maxdepth: 2 + :maxdepth: 3 Dealing with many SNMP features may quickly overwhelm developers who aim at a quick and trivial task, PySNMP employs a layered architecture approach where the topmost programming API tries to be as simple as possible to allow immediate solutions for most common use cases. -It will let you perform SNMP GET/SET/WALK and TRAP/INFORM operations by -pasting code snippets from PySNMP documentation and example scripts -right into your Python interactive session. Most of SNMP operations involve packet exchange over network. PySNMP is shipped with a set of bindings to popular asynchronous Python I/O frameworks that let you run PySNMP in parallel with other tasks your application may perform. -Synchronous SNMP ----------------- +High-level, v3arch, sync +------------------------ -Most simple and strightforward way to use PySNMP is by employing its -Synchronous, blocking API. It's also the default API offered by -users on *pysnmp.hlapi* sub-package import. +The synchronous `hlapi.v3arch` API is the easiest to use and probably +the richest in features. However `hlapi.v1arch` API may be faster. Command Generator .. toctree:: :maxdepth: 2 - /docs/hlapi/asyncore/sync/manager/cmdgen/getcmd - /docs/hlapi/asyncore/sync/manager/cmdgen/setcmd - /docs/hlapi/asyncore/sync/manager/cmdgen/nextcmd - /docs/hlapi/asyncore/sync/manager/cmdgen/bulkcmd + /docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/getcmd + /docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/setcmd + /docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/nextcmd + /docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/bulkcmd Notification Originator .. toctree:: :maxdepth: 2 - /docs/hlapi/asyncore/sync/agent/ntforg/notification + /docs/hlapi/v3arch/asyncore/sync/agent/ntforg/notification Transport configuration +++++++++++++++++++++++ @@ -59,8 +55,8 @@ saves its configuration for the lifetime of SNMP engine object. .. autoclass:: pysnmp.hlapi.Udp6TransportTarget :members: setLocalAddress -Asynchronous: asyncore ----------------------- +High-level v3arch asyncore +-------------------------- The :mod:`asyncore` module is in Python standard library since ancient times. Main loop is built around :mod:`select` dispatcher, user @@ -71,17 +67,17 @@ Command Generator .. toctree:: :maxdepth: 2 - /docs/hlapi/asyncore/manager/cmdgen/getcmd - /docs/hlapi/asyncore/manager/cmdgen/setcmd - /docs/hlapi/asyncore/manager/cmdgen/nextcmd - /docs/hlapi/asyncore/manager/cmdgen/bulkcmd + /docs/hlapi/v3arch/asyncore/manager/cmdgen/getcmd + /docs/hlapi/v3arch/asyncore/manager/cmdgen/setcmd + /docs/hlapi/v3arch/asyncore/manager/cmdgen/nextcmd + /docs/hlapi/v3arch/asyncore/manager/cmdgen/bulkcmd Notification Originator .. toctree:: :maxdepth: 2 - /docs/hlapi/asyncore/agent/ntforg/notification + /docs/hlapi/v3arch/asyncore/agent/ntforg/notification Transport configuration +++++++++++++++++++++++ @@ -89,14 +85,14 @@ Transport configuration .. toctree:: :maxdepth: 2 -.. autoclass:: pysnmp.hlapi.asyncore.UdpTransportTarget +.. autoclass:: pysnmp.hlapi.v3arch.asyncore.UdpTransportTarget :members: setLocalAddress -.. autoclass:: pysnmp.hlapi.asyncore.Udp6TransportTarget +.. autoclass:: pysnmp.hlapi.v3arch.asyncore.Udp6TransportTarget :members: setLocalAddress -Asynchronous: asyncio ---------------------- +High-level v3arch asyncio +------------------------- The :mod:`asyncio` module first appeared in standard library since Python 3.3 (in provisional basis). Its main design feature is that @@ -108,17 +104,17 @@ Command Generator .. toctree:: :maxdepth: 2 - /docs/hlapi/asyncio/manager/cmdgen/getcmd - /docs/hlapi/asyncio/manager/cmdgen/setcmd - /docs/hlapi/asyncio/manager/cmdgen/nextcmd - /docs/hlapi/asyncio/manager/cmdgen/bulkcmd + /docs/hlapi/v3arch/asyncio/manager/cmdgen/getcmd + /docs/hlapi/v3arch/asyncio/manager/cmdgen/setcmd + /docs/hlapi/v3arch/asyncio/manager/cmdgen/nextcmd + /docs/hlapi/v3arch/asyncio/manager/cmdgen/bulkcmd Notification Originator .. toctree:: :maxdepth: 2 - /docs/hlapi/asyncio/agent/ntforg/notification + /docs/hlapi/v3arch/asyncio/agent/ntforg/notification Transport configuration +++++++++++++++++++++++ @@ -126,14 +122,14 @@ Transport configuration .. toctree:: :maxdepth: 2 -.. autoclass:: pysnmp.hlapi.asyncio.UdpTransportTarget +.. autoclass:: pysnmp.hlapi.v3arch.asyncio.UdpTransportTarget :members: setLocalAddress -.. autoclass:: pysnmp.hlapi.asyncio.Udp6TransportTarget +.. autoclass:: pysnmp.hlapi.v3arch.asyncio.Udp6TransportTarget :members: setLocalAddress -Asynchronous: trollius ----------------------- +High-level v3arch trollius +-------------------------- An almost compatible alternative to *asyncio* for pre-3.3 Python is `Trollius `_ module. PySNMP's @@ -142,8 +138,8 @@ is `Trollius `_ module. PySNMP's Please refer to :doc:`Trollius examples ` for more information. -Asynchronous: Twisted ---------------------- +High-level v3arch twisted +------------------------- `Twisted `_ is one of the earliest and hugely popular asynchronous I/O framework. It introduced a concept of @@ -156,17 +152,17 @@ Command Generator .. toctree:: :maxdepth: 2 - /docs/hlapi/twisted/manager/cmdgen/getcmd - /docs/hlapi/twisted/manager/cmdgen/setcmd - /docs/hlapi/twisted/manager/cmdgen/nextcmd - /docs/hlapi/twisted/manager/cmdgen/bulkcmd + /docs/hlapi/v3arch/twisted/manager/cmdgen/getcmd + /docs/hlapi/v3arch/twisted/manager/cmdgen/setcmd + /docs/hlapi/v3arch/twisted/manager/cmdgen/nextcmd + /docs/hlapi/v3arch/twisted/manager/cmdgen/bulkcmd Notification Originator .. toctree:: :maxdepth: 2 - /docs/hlapi/twisted/agent/ntforg/notification + /docs/hlapi/v3arch/twisted/agent/ntforg/notification Transport configuration +++++++++++++++++++++++ @@ -174,14 +170,14 @@ Transport configuration .. toctree:: :maxdepth: 2 -.. autoclass:: pysnmp.hlapi.twisted.UdpTransportTarget +.. autoclass:: pysnmp.hlapi.v3arch.twisted.UdpTransportTarget :members: setLocalAddress -SNMP Engine ------------ +High-level v3arch SNMP Engine +----------------------------- SNMP Engine is a central, stateful object used by all SNMP v3 -substsems. Calls to high-level Applications API also consume SNMP +subsystems. Calls to high-level Applications API also consume SNMP Engine object on input. .. toctree:: @@ -189,8 +185,8 @@ Engine object on input. .. autoclass:: pysnmp.hlapi.SnmpEngine(snmpEngineID=None) -Security Parameters -------------------- +High-level v3arch auth +---------------------- Calls to high-level Applications API consume Security Parameters configuration object on input. The shortcut classes described in @@ -242,8 +238,8 @@ via constant OIDs: Transport configuration is I/O framework specific and is described in respective sections. -SNMP Context ------------- +High-level v3arch SNMP Context +------------------------------ SNMP engine may serve several instances of the same MIB within possibly multiple SNMP entities. SNMP context is a tool for @@ -274,6 +270,111 @@ SNMP engine. See :RFC:`3411#section-3.3.1` for details. .. autoclass:: pysnmp.hlapi.ContextData +High-level v1arch sync +---------------------- + +The synchronous `hlapi.v1arch` API is probably the easiest to use and fast to run, +however it does not support SNMPv3. + +Command Generator + +.. toctree:: + :maxdepth: 2 + + /docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/getcmd + /docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/setcmd + /docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/nextcmd + /docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/bulkcmd + +Notification Originator + +.. toctree:: + :maxdepth: 2 + + /docs/hlapi/v1arch/asyncore/sync/agent/ntforg/notification + +Transport configuration ++++++++++++++++++++++++ + +The following shortcut classes convey configuration information to +SNMP engine's Local Configuration Datastore (:RFC:`2271#section-3.4.2`) +as well as to underlying socket API. Once committed to LCD, SNMP engine +saves its configuration for the lifetime of SNMP engine object. + +.. toctree:: + :maxdepth: 2 + +.. autoclass:: pysnmp.hlapi.v1arch.UdpTransportTarget + :members: setLocalAddress + +.. autoclass:: pysnmp.hlapi.v1arch.Udp6TransportTarget + :members: setLocalAddress + +High-level v1arch asyncore +-------------------------- + +The :mod:`asyncore` module is in Python standard library since ancient +times. Main loop is built around :mod:`select` dispatcher, user +code is invoked through callback callables. + +Command Generator + +.. toctree:: + :maxdepth: 2 + + /docs/hlapi/v1arch/asyncore/manager/cmdgen/getcmd + /docs/hlapi/v1arch/asyncore/manager/cmdgen/setcmd + /docs/hlapi/v1arch/asyncore/manager/cmdgen/nextcmd + /docs/hlapi/v1arch/asyncore/manager/cmdgen/bulkcmd + +Notification Originator + +.. toctree:: + :maxdepth: 2 + + /docs/hlapi/v1arch/asyncore/agent/ntforg/notification + +Transport configuration ++++++++++++++++++++++++ + +.. toctree:: + :maxdepth: 2 + +.. autoclass:: pysnmp.hlapi.v1arch.asyncore.UdpTransportTarget + :members: setLocalAddress + +.. autoclass:: pysnmp.hlapi.v1arch.asyncore.Udp6TransportTarget + :members: setLocalAddress + +High-level v1arch SNMP Dispatcher +--------------------------------- + +SNMP Dispatcher is a stateful object representing asynchronous +I/O event loop and also holding some caches. Calls to `v1arch` +always require consume SNMP Dispatcher object on input. + +.. toctree:: + :maxdepth: 2 + +.. autoclass:: pysnmp.hlapi.v1arch.SnmpDispatcher() + +High-level v1arch auth +---------------------- + +Calls to `v1arch` API require SNMP authentication object on input. + +Community-based ++++++++++++++++ + +Security Parameters object is Security Model specific. The +:py:class:`~pysnmp.hlapi.v1arch.CommunityData` +class is used for configuring Community-Based Security Model of SNMPv1/SNMPv2c. + +.. toctree:: + :maxdepth: 2 + +.. autoclass:: pysnmp.hlapi.v1arch.CommunityData(communityName, mpModel=1) + .. _mib-services: MIB services diff --git a/docs/source/docs/hlapi/v1arch/asyncore/agent/ntforg/notification.rst b/docs/source/docs/hlapi/v1arch/asyncore/agent/ntforg/notification.rst new file mode 100644 index 00000000..0787018c --- /dev/null +++ b/docs/source/docs/hlapi/v1arch/asyncore/agent/ntforg/notification.rst @@ -0,0 +1,8 @@ + +TRAP/INFORM notification +======================== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v1arch.asyncore.sendNotification diff --git a/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/bulkcmd.rst b/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/bulkcmd.rst new file mode 100644 index 00000000..de9fccf7 --- /dev/null +++ b/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/bulkcmd.rst @@ -0,0 +1,8 @@ + +GETBULK command +=============== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v1arch.asyncore.bulkCmd diff --git a/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/getcmd.rst b/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/getcmd.rst new file mode 100644 index 00000000..427fbd98 --- /dev/null +++ b/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/getcmd.rst @@ -0,0 +1,8 @@ + +GET command +=========== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v1arch.asyncore.getCmd diff --git a/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/nextcmd.rst b/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/nextcmd.rst new file mode 100644 index 00000000..3d023b64 --- /dev/null +++ b/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/nextcmd.rst @@ -0,0 +1,8 @@ + +GETNEXT command +=============== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v1arch.asyncore.nextCmd diff --git a/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/setcmd.rst b/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/setcmd.rst new file mode 100644 index 00000000..89460d52 --- /dev/null +++ b/docs/source/docs/hlapi/v1arch/asyncore/manager/cmdgen/setcmd.rst @@ -0,0 +1,8 @@ + +SET command +=========== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v1arch.asyncore.setCmd diff --git a/docs/source/docs/hlapi/asyncio/agent/ntforg/notification.rst b/docs/source/docs/hlapi/v1arch/asyncore/sync/agent/ntforg/notification.rst similarity index 59% rename from docs/source/docs/hlapi/asyncio/agent/ntforg/notification.rst rename to docs/source/docs/hlapi/v1arch/asyncore/sync/agent/ntforg/notification.rst index 954c9232..91099176 100644 --- a/docs/source/docs/hlapi/asyncio/agent/ntforg/notification.rst +++ b/docs/source/docs/hlapi/v1arch/asyncore/sync/agent/ntforg/notification.rst @@ -5,4 +5,4 @@ TRAP/INFORM notification .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncio.sendNotification +.. autofunction:: pysnmp.hlapi.v1arch.sendNotification diff --git a/docs/source/docs/hlapi/asyncio/manager/cmdgen/bulkcmd.rst b/docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/bulkcmd.rst similarity index 57% rename from docs/source/docs/hlapi/asyncio/manager/cmdgen/bulkcmd.rst rename to docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/bulkcmd.rst index 970cfb11..ff578d8c 100644 --- a/docs/source/docs/hlapi/asyncio/manager/cmdgen/bulkcmd.rst +++ b/docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/bulkcmd.rst @@ -5,4 +5,4 @@ GETBULK command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncio.bulkCmd +.. autofunction:: pysnmp.hlapi.v1arch.bulkCmd diff --git a/docs/source/docs/hlapi/twisted/manager/cmdgen/getcmd.rst b/docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/getcmd.rst similarity index 54% rename from docs/source/docs/hlapi/twisted/manager/cmdgen/getcmd.rst rename to docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/getcmd.rst index 53d3a142..1bcfd07d 100644 --- a/docs/source/docs/hlapi/twisted/manager/cmdgen/getcmd.rst +++ b/docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/getcmd.rst @@ -5,4 +5,4 @@ GET command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.twisted.getCmd +.. autofunction:: pysnmp.hlapi.v1arch.getCmd diff --git a/docs/source/docs/hlapi/twisted/manager/cmdgen/nextcmd.rst b/docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/nextcmd.rst similarity index 57% rename from docs/source/docs/hlapi/twisted/manager/cmdgen/nextcmd.rst rename to docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/nextcmd.rst index 54aa5401..533c3872 100644 --- a/docs/source/docs/hlapi/twisted/manager/cmdgen/nextcmd.rst +++ b/docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/nextcmd.rst @@ -5,4 +5,4 @@ GETNEXT command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.twisted.nextCmd +.. autofunction:: pysnmp.hlapi.v1arch.nextCmd diff --git a/docs/source/docs/hlapi/asyncio/manager/cmdgen/setcmd.rst b/docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/setcmd.rst similarity index 54% rename from docs/source/docs/hlapi/asyncio/manager/cmdgen/setcmd.rst rename to docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/setcmd.rst index c34fc44b..78a7886a 100644 --- a/docs/source/docs/hlapi/asyncio/manager/cmdgen/setcmd.rst +++ b/docs/source/docs/hlapi/v1arch/asyncore/sync/manager/cmdgen/setcmd.rst @@ -5,4 +5,4 @@ SET command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncio.setCmd +.. autofunction:: pysnmp.hlapi.v1arch.setCmd diff --git a/docs/source/docs/hlapi/asyncore/agent/ntforg/notification.rst b/docs/source/docs/hlapi/v3arch/asyncio/agent/ntforg/notification.rst similarity index 56% rename from docs/source/docs/hlapi/asyncore/agent/ntforg/notification.rst rename to docs/source/docs/hlapi/v3arch/asyncio/agent/ntforg/notification.rst index e9d55cfd..f701eca6 100644 --- a/docs/source/docs/hlapi/asyncore/agent/ntforg/notification.rst +++ b/docs/source/docs/hlapi/v3arch/asyncio/agent/ntforg/notification.rst @@ -5,4 +5,4 @@ TRAP/INFORM notification .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncore.sendNotification +.. autofunction:: pysnmp.hlapi.v3arch.asyncio.sendNotification diff --git a/docs/source/docs/hlapi/asyncore/manager/cmdgen/bulkcmd.rst b/docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/bulkcmd.rst similarity index 54% rename from docs/source/docs/hlapi/asyncore/manager/cmdgen/bulkcmd.rst rename to docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/bulkcmd.rst index 59bee11f..51e93801 100644 --- a/docs/source/docs/hlapi/asyncore/manager/cmdgen/bulkcmd.rst +++ b/docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/bulkcmd.rst @@ -5,4 +5,4 @@ GETBULK command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncore.bulkCmd +.. autofunction:: pysnmp.hlapi.v3arch.asyncio.bulkCmd diff --git a/docs/source/docs/hlapi/asyncore/manager/cmdgen/getcmd.rst b/docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/getcmd.rst similarity index 51% rename from docs/source/docs/hlapi/asyncore/manager/cmdgen/getcmd.rst rename to docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/getcmd.rst index c2244913..821c5e66 100644 --- a/docs/source/docs/hlapi/asyncore/manager/cmdgen/getcmd.rst +++ b/docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/getcmd.rst @@ -5,4 +5,4 @@ GET command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncore.getCmd +.. autofunction:: pysnmp.hlapi.v3arch.asyncio.getCmd diff --git a/docs/source/docs/hlapi/asyncore/manager/cmdgen/nextcmd.rst b/docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/nextcmd.rst similarity index 54% rename from docs/source/docs/hlapi/asyncore/manager/cmdgen/nextcmd.rst rename to docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/nextcmd.rst index 1a8856a7..285c1f10 100644 --- a/docs/source/docs/hlapi/asyncore/manager/cmdgen/nextcmd.rst +++ b/docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/nextcmd.rst @@ -5,4 +5,4 @@ GETNEXT command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncore.nextCmd +.. autofunction:: pysnmp.hlapi.v3arch.asyncio.nextCmd diff --git a/docs/source/docs/hlapi/twisted/manager/cmdgen/setcmd.rst b/docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/setcmd.rst similarity index 51% rename from docs/source/docs/hlapi/twisted/manager/cmdgen/setcmd.rst rename to docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/setcmd.rst index 8a7890a0..d170d5f4 100644 --- a/docs/source/docs/hlapi/twisted/manager/cmdgen/setcmd.rst +++ b/docs/source/docs/hlapi/v3arch/asyncio/manager/cmdgen/setcmd.rst @@ -5,4 +5,4 @@ SET command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.twisted.setCmd +.. autofunction:: pysnmp.hlapi.v3arch.asyncio.setCmd diff --git a/docs/source/docs/hlapi/v3arch/asyncore/agent/ntforg/notification.rst b/docs/source/docs/hlapi/v3arch/asyncore/agent/ntforg/notification.rst new file mode 100644 index 00000000..13c76a72 --- /dev/null +++ b/docs/source/docs/hlapi/v3arch/asyncore/agent/ntforg/notification.rst @@ -0,0 +1,8 @@ + +TRAP/INFORM notification +======================== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v3arch.asyncore.sendNotification diff --git a/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/bulkcmd.rst b/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/bulkcmd.rst new file mode 100644 index 00000000..a139211d --- /dev/null +++ b/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/bulkcmd.rst @@ -0,0 +1,8 @@ + +GETBULK command +=============== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v3arch.asyncore.bulkCmd diff --git a/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/getcmd.rst b/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/getcmd.rst new file mode 100644 index 00000000..8688df99 --- /dev/null +++ b/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/getcmd.rst @@ -0,0 +1,8 @@ + +GET command +=========== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v3arch.asyncore.getCmd diff --git a/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/nextcmd.rst b/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/nextcmd.rst new file mode 100644 index 00000000..5a703cba --- /dev/null +++ b/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/nextcmd.rst @@ -0,0 +1,8 @@ + +GETNEXT command +=============== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v3arch.asyncore.nextCmd diff --git a/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/setcmd.rst b/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/setcmd.rst new file mode 100644 index 00000000..0b548afe --- /dev/null +++ b/docs/source/docs/hlapi/v3arch/asyncore/manager/cmdgen/setcmd.rst @@ -0,0 +1,8 @@ + +SET command +=========== + +.. toctree:: + :maxdepth: 2 + +.. autofunction:: pysnmp.hlapi.v3arch.asyncore.setCmd diff --git a/docs/source/docs/hlapi/asyncore/sync/agent/ntforg/notification.rst b/docs/source/docs/hlapi/v3arch/asyncore/sync/agent/ntforg/notification.rst similarity index 100% rename from docs/source/docs/hlapi/asyncore/sync/agent/ntforg/notification.rst rename to docs/source/docs/hlapi/v3arch/asyncore/sync/agent/ntforg/notification.rst diff --git a/docs/source/docs/hlapi/asyncore/sync/manager/cmdgen/bulkcmd.rst b/docs/source/docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/bulkcmd.rst similarity index 100% rename from docs/source/docs/hlapi/asyncore/sync/manager/cmdgen/bulkcmd.rst rename to docs/source/docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/bulkcmd.rst diff --git a/docs/source/docs/hlapi/asyncore/sync/manager/cmdgen/getcmd.rst b/docs/source/docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/getcmd.rst similarity index 100% rename from docs/source/docs/hlapi/asyncore/sync/manager/cmdgen/getcmd.rst rename to docs/source/docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/getcmd.rst diff --git a/docs/source/docs/hlapi/asyncore/sync/manager/cmdgen/nextcmd.rst b/docs/source/docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/nextcmd.rst similarity index 100% rename from docs/source/docs/hlapi/asyncore/sync/manager/cmdgen/nextcmd.rst rename to docs/source/docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/nextcmd.rst diff --git a/docs/source/docs/hlapi/asyncore/sync/manager/cmdgen/setcmd.rst b/docs/source/docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/setcmd.rst similarity index 100% rename from docs/source/docs/hlapi/asyncore/sync/manager/cmdgen/setcmd.rst rename to docs/source/docs/hlapi/v3arch/asyncore/sync/manager/cmdgen/setcmd.rst diff --git a/docs/source/docs/hlapi/twisted/agent/ntforg/notification.rst b/docs/source/docs/hlapi/v3arch/twisted/agent/ntforg/notification.rst similarity index 56% rename from docs/source/docs/hlapi/twisted/agent/ntforg/notification.rst rename to docs/source/docs/hlapi/v3arch/twisted/agent/ntforg/notification.rst index 7928912e..b565c46e 100644 --- a/docs/source/docs/hlapi/twisted/agent/ntforg/notification.rst +++ b/docs/source/docs/hlapi/v3arch/twisted/agent/ntforg/notification.rst @@ -5,4 +5,4 @@ TRAP/INFORM notification .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.twisted.sendNotification +.. autofunction:: pysnmp.hlapi.v3arch.twisted.sendNotification diff --git a/docs/source/docs/hlapi/twisted/manager/cmdgen/bulkcmd.rst b/docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/bulkcmd.rst similarity index 54% rename from docs/source/docs/hlapi/twisted/manager/cmdgen/bulkcmd.rst rename to docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/bulkcmd.rst index 24fff6e1..f0f80e34 100644 --- a/docs/source/docs/hlapi/twisted/manager/cmdgen/bulkcmd.rst +++ b/docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/bulkcmd.rst @@ -5,4 +5,4 @@ GETBULK command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.twisted.bulkCmd +.. autofunction:: pysnmp.hlapi.v3arch.twisted.bulkCmd diff --git a/docs/source/docs/hlapi/asyncio/manager/cmdgen/getcmd.rst b/docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/getcmd.rst similarity index 51% rename from docs/source/docs/hlapi/asyncio/manager/cmdgen/getcmd.rst rename to docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/getcmd.rst index 4ac0a524..b5d419bb 100644 --- a/docs/source/docs/hlapi/asyncio/manager/cmdgen/getcmd.rst +++ b/docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/getcmd.rst @@ -5,4 +5,4 @@ GET command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncio.getCmd +.. autofunction:: pysnmp.hlapi.v3arch.twisted.getCmd diff --git a/docs/source/docs/hlapi/asyncio/manager/cmdgen/nextcmd.rst b/docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/nextcmd.rst similarity index 54% rename from docs/source/docs/hlapi/asyncio/manager/cmdgen/nextcmd.rst rename to docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/nextcmd.rst index b88291c1..d161358a 100644 --- a/docs/source/docs/hlapi/asyncio/manager/cmdgen/nextcmd.rst +++ b/docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/nextcmd.rst @@ -5,4 +5,4 @@ GETNEXT command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncio.nextCmd +.. autofunction:: pysnmp.hlapi.v3arch.twisted.nextCmd diff --git a/docs/source/docs/hlapi/asyncore/manager/cmdgen/setcmd.rst b/docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/setcmd.rst similarity index 51% rename from docs/source/docs/hlapi/asyncore/manager/cmdgen/setcmd.rst rename to docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/setcmd.rst index 92f6c912..238537ae 100644 --- a/docs/source/docs/hlapi/asyncore/manager/cmdgen/setcmd.rst +++ b/docs/source/docs/hlapi/v3arch/twisted/manager/cmdgen/setcmd.rst @@ -5,4 +5,4 @@ SET command .. toctree:: :maxdepth: 2 -.. autofunction:: pysnmp.hlapi.asyncore.setCmd +.. autofunction:: pysnmp.hlapi.v3arch.twisted.setCmd diff --git a/docs/source/docs/pysnmp-hlapi-tutorial.rst b/docs/source/docs/pysnmp-hlapi-tutorial.rst index 22075810..82ff55a2 100644 --- a/docs/source/docs/pysnmp-hlapi-tutorial.rst +++ b/docs/source/docs/pysnmp-hlapi-tutorial.rst @@ -242,7 +242,7 @@ in `SNMPv2-MIB `_ module. By default PySNMP will search your local filesystem for ASN.1 MIB files you refer to. It can also be configured to automatically download them from remote hosts, as -:doc:`shown ` +:doc:`shown ` in the examples. We maintain a `collection `_ of ASN.1 MIB modules that you can use in your SNMP projects. diff --git a/docs/source/docs/tutorial.rst b/docs/source/docs/tutorial.rst index f6548818..b96f6e08 100644 --- a/docs/source/docs/tutorial.rst +++ b/docs/source/docs/tutorial.rst @@ -1,6 +1,6 @@ -Documentation -============= +Overview +======== .. toctree:: :maxdepth: 2 diff --git a/docs/source/download.rst b/docs/source/download.rst index 4026d891..849873f9 100644 --- a/docs/source/download.rst +++ b/docs/source/download.rst @@ -50,6 +50,7 @@ operational: MIB download and compilation. That helps visualizing more SNMP objects Optional: + * `pysnmpcrypto `_, for strong SNMPv3 crypto support diff --git a/docs/source/examples/contents.rst b/docs/source/examples/contents.rst index f179e13b..7007fee8 100644 --- a/docs/source/examples/contents.rst +++ b/docs/source/examples/contents.rst @@ -9,51 +9,82 @@ SNMP is not simple (PySNMP implementation takes over 15K lines of Python code), but PySNMP tries to hide the complexities and let you carry out typical SNMP operations in a quick and intuitive way. -PySNMP offers three groups of programming interfaces to deal with -SNMP protocol. In the order from most concise to most detailed those -APIs follow. +PySNMP offers high and low-level programming interfaces to deal with +SNMP protocol. + +The other dimension of differences in the PySNMP APIs is that there are +two different SNMP implementations - the initial architecture +(`RFC1901 `_ .. +`RFC1905 `_) also known as SNMP v1 architecture +and the redesigned variant (`RFC3413 `_ +and others) -- SNMPv3 architecture. + +.. note:: + + The SNMP v1 architecture supports SNMP protocol versions 1 and 2c, + while SNMP v3 architecture supports versions 1, 2c and 3. Whatever + new amendments to the SNMP protocol may come up in the future, they + will be implemented within the v3 model. High-level SNMP --------------- -The so called high-level API (hlapi) is designed to be simple, concise and -suitable for the most frequent operations. For that matter only -Command Generator and Notification Originator Applications are currently +The high-level API (`hlapi`) is designed to be simple, concise and +suitable for the most typical client-side operations. For that matter, +only Command Generator and Notification Originator Applications are wrapped into a nearly one-line Python expression. -It comes in several flavours: one synchronous and a bunch of bindings to -popular asynchronous I/O frameworks. Those varieties of APIs bring -subtile differences, mostly to better match particular I/O framework -customs. Unless you have a very specific task, the high-level API might -solve your SNMP needs. +The `hlapi` interfaces come in several flavours: one synchronous +and a bunch of asynchronous, adapted to work withing the event loops +of popular asynchronous I/O frameworks. + +The primary reason for maintaining high-level API over both `v1arch` and +`v3arch` is performance - `v3arch` machinery is much more functional and complicated +internally, that translates to being heavier on resources and therefore slower. + +The v3 architecture ++++++++++++++++++++ .. toctree:: :maxdepth: 2 - /examples/hlapi/asyncore/sync/contents + /examples/hlapi/v3arch/asyncore/sync/contents .. toctree:: :maxdepth: 2 - /examples/hlapi/asyncore/contents + /examples/hlapi/v3arch/asyncore/contents .. toctree:: :maxdepth: 2 - /examples/hlapi/asyncio/contents + /examples/hlapi/v3arch/asyncio/contents .. toctree:: :maxdepth: 2 - /examples/hlapi/trollius/contents + /examples/hlapi/v3arch/trollius/contents .. toctree:: :maxdepth: 2 - /examples/hlapi/twisted/contents + /examples/hlapi/v3arch/twisted/contents -Native SNMP API ---------------- +The v1 architecture ++++++++++++++++++++ + +.. toctree:: + :maxdepth: 2 + + /examples/hlapi/v1arch/asyncore/sync/contents + +.. toctree:: + :maxdepth: 2 + + /examples/hlapi/v1arch/asyncore/contents + +Low-level v3 architecture +------------------------- Complete implementation of all official Standard SNMP Applications. It should let you implement any SNMP operation defined in the standard @@ -70,8 +101,8 @@ framework being used. /examples/v3arch/trollius/contents /examples/v3arch/twisted/contents -Packet-level SNMP ------------------ +Low-level v1 architecture +------------------------- In cases where performance is your top priority and you only need to work with SNMP v1 and v2c systems and you do not mind writing much @@ -116,15 +147,14 @@ Notification Receiver /examples/v1arch/asyncore/manager/ntfrcv/transport-tweaks -Low-level MIB access --------------------- +Low-level SMI/MIB +----------------- .. toctree:: /examples/smi/manager/browsing-mib-tree /examples/smi/agent/implementing-mib-objects - Using these examples -------------------- diff --git a/docs/source/examples/hlapi/asyncio/agent/ntforg/advanced-topics.rst b/docs/source/examples/hlapi/asyncio/agent/ntforg/advanced-topics.rst deleted file mode 100644 index e1a14dea..00000000 --- a/docs/source/examples/hlapi/asyncio/agent/ntforg/advanced-topics.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Advanced Notification Originator --------------------------------- - -.. include:: /../../examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncio/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/asyncio/agent/ntforg/common-notifications.rst deleted file mode 100644 index 1dbf13c1..00000000 --- a/docs/source/examples/hlapi/asyncio/agent/ntforg/common-notifications.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Common notifications --------------------- - -.. include:: /../../examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncio/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/asyncio/manager/cmdgen/advanced-topics.rst deleted file mode 100644 index b75d6e5d..00000000 --- a/docs/source/examples/hlapi/asyncio/manager/cmdgen/advanced-topics.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Advanced Command Generator --------------------------- - -.. include:: /../../examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-queries.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-queries.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncio/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/asyncio/manager/cmdgen/snmp-versions.rst deleted file mode 100644 index 20d34606..00000000 --- a/docs/source/examples/hlapi/asyncio/manager/cmdgen/snmp-versions.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Various SNMP versions ----------------------- - -.. include:: /../../examples/hlapi/asyncio/manager/cmdgen/v1-get.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncio/manager/cmdgen/v1-get.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncio/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/asyncio/manager/cmdgen/walking-operations.rst deleted file mode 100644 index 3a588cad..00000000 --- a/docs/source/examples/hlapi/asyncio/manager/cmdgen/walking-operations.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Walking operations ------------------- - -.. include:: /../../examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/agent/ntforg/advanced-topics.rst b/docs/source/examples/hlapi/asyncore/agent/ntforg/advanced-topics.rst deleted file mode 100644 index e87cd833..00000000 --- a/docs/source/examples/hlapi/asyncore/agent/ntforg/advanced-topics.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Advanced Notification Originator --------------------------------- - -.. include:: /../../examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/asyncore/agent/ntforg/common-notifications.rst deleted file mode 100644 index 3f615bd3..00000000 --- a/docs/source/examples/hlapi/asyncore/agent/ntforg/common-notifications.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Common notifications --------------------- - -.. include:: /../../examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/asyncore/manager/cmdgen/advanced-topics.rst deleted file mode 100644 index 17a01f97..00000000 --- a/docs/source/examples/hlapi/asyncore/manager/cmdgen/advanced-topics.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Advanced Command Generator --------------------------- - -.. include:: /../../examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/asyncore/manager/cmdgen/snmp-versions.rst deleted file mode 100644 index b5c3bdea..00000000 --- a/docs/source/examples/hlapi/asyncore/manager/cmdgen/snmp-versions.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Various SNMP versions ----------------------- - -.. include:: /../../examples/hlapi/asyncore/manager/cmdgen/v2c-get.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/manager/cmdgen/v2c-get.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/asyncore/manager/cmdgen/walking-operations.rst deleted file mode 100644 index 3cc19a07..00000000 --- a/docs/source/examples/hlapi/asyncore/manager/cmdgen/walking-operations.rst +++ /dev/null @@ -1,18 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Walking operations ------------------- - -.. include:: /../../examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/advanced-topics.rst b/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/advanced-topics.rst deleted file mode 100644 index 2163690d..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/advanced-topics.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Advanced Notification Originator --------------------------------- - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/common-notifications.rst deleted file mode 100644 index 7b09fa90..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/common-notifications.rst +++ /dev/null @@ -1,49 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Common notifications --------------------- - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py - :start-after: """# - :language: python - -:download:`Download` script. - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/evaluating-notification-type.rst b/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/evaluating-notification-type.rst deleted file mode 100644 index f5ac1bf1..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/evaluating-notification-type.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Evaluating NOTIFICATION-TYPE ----------------------------- - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/snmp-v1-trap-variants.rst b/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/snmp-v1-trap-variants.rst deleted file mode 100644 index 68a01e9c..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/agent/ntforg/snmp-v1-trap-variants.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -SNMPv1 TRAP variants --------------------- - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/advanced-topics.rst deleted file mode 100644 index 9854bc52..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/advanced-topics.rst +++ /dev/null @@ -1,84 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Advanced Command Generator --------------------------- - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/mib-tweaks.rst b/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/mib-tweaks.rst deleted file mode 100644 index d1ea7ff8..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/mib-tweaks.rst +++ /dev/null @@ -1,48 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -MIB tweaks ----------- - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py - :start-after: """# - :language: python - -:download:`Download` script. - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py - :start-after: """# - :language: python - -:download:`Download` script. - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py - :start-after: """# - :language: python - -:download:`Download` script. - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/modifying-variables.rst b/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/modifying-variables.rst deleted file mode 100644 index 95ee0451..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/modifying-variables.rst +++ /dev/null @@ -1,30 +0,0 @@ - -.. toctree:: - :maxdepth: 2 - -Modifying variables -------------------- - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library-reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions.rst deleted file mode 100644 index d1fee8dc..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions.rst +++ /dev/null @@ -1,72 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -SNMP versions -------------- - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/transport-tweaks.rst b/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/transport-tweaks.rst deleted file mode 100644 index e3309f6b..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/transport-tweaks.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Transport tweaks ----------------- - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/walking-operations.rst deleted file mode 100644 index fa7ed380..00000000 --- a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/walking-operations.rst +++ /dev/null @@ -1,18 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Walking operations ------------------- - -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/trollius/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/trollius/agent/ntforg/common-notifications.rst deleted file mode 100644 index c0b78924..00000000 --- a/docs/source/examples/hlapi/trollius/agent/ntforg/common-notifications.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Common notifications --------------------- - -.. include:: /../../examples/hlapi/trollius/agent/ntforg/default-v1-trap.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/trollius/agent/ntforg/default-v1-trap.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/trollius/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/trollius/manager/cmdgen/snmp-versions.rst deleted file mode 100644 index 769bd7a0..00000000 --- a/docs/source/examples/hlapi/trollius/manager/cmdgen/snmp-versions.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Various SNMP versions ----------------------- - -.. include:: /../../examples/hlapi/trollius/manager/cmdgen/v1-get.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/trollius/manager/cmdgen/v1-get.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/trollius/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/trollius/manager/cmdgen/walking-operations.rst deleted file mode 100644 index dcc7672a..00000000 --- a/docs/source/examples/hlapi/trollius/manager/cmdgen/walking-operations.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Walking operations ------------------- - -.. include:: /../../examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/twisted/agent/ntforg/advanced-topics.rst b/docs/source/examples/hlapi/twisted/agent/ntforg/advanced-topics.rst deleted file mode 100644 index 8be4effa..00000000 --- a/docs/source/examples/hlapi/twisted/agent/ntforg/advanced-topics.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Advanced Notification Originator --------------------------------- - -.. include:: /../../examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/twisted/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/twisted/agent/ntforg/common-notifications.rst deleted file mode 100644 index 61d8b3f5..00000000 --- a/docs/source/examples/hlapi/twisted/agent/ntforg/common-notifications.rst +++ /dev/null @@ -1,27 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Common notifications --------------------- - -.. include:: /../../examples/hlapi/twisted/agent/ntforg/default-v1-trap.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/agent/ntforg/default-v1-trap.py - :start-after: """# - :language: python - -:download:`Download` script. - -.. include:: /../../examples/hlapi/twisted/agent/ntforg/v2c-trap-inline-callbacks.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/agent/ntforg/v2c-trap-inline-callbacks.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/twisted/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/twisted/manager/cmdgen/advanced-topics.rst deleted file mode 100644 index 135ab533..00000000 --- a/docs/source/examples/hlapi/twisted/manager/cmdgen/advanced-topics.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Advanced Command Generator --------------------------- - -.. include:: /../../examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/twisted/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/twisted/manager/cmdgen/snmp-versions.rst deleted file mode 100644 index b2d94b09..00000000 --- a/docs/source/examples/hlapi/twisted/manager/cmdgen/snmp-versions.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Various SNMP versions ----------------------- - -.. include:: /../../examples/hlapi/twisted/manager/cmdgen/v1-get.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/manager/cmdgen/v1-get.py - :start-after: """# - :language: python - -:download:`Download` script. - - -.. include:: /../../examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py - :start-after: """# - :language: python - -:download:`Download` script. - - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/twisted/manager/cmdgen/transport-tweaks.rst b/docs/source/examples/hlapi/twisted/manager/cmdgen/transport-tweaks.rst deleted file mode 100644 index bddd96c9..00000000 --- a/docs/source/examples/hlapi/twisted/manager/cmdgen/transport-tweaks.rst +++ /dev/null @@ -1,17 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Transport tweaks ----------------- - -.. include:: /../../examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/twisted/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/twisted/manager/cmdgen/walking-operations.rst deleted file mode 100644 index 71058bb9..00000000 --- a/docs/source/examples/hlapi/twisted/manager/cmdgen/walking-operations.rst +++ /dev/null @@ -1,27 +0,0 @@ -.. toctree:: - :maxdepth: 2 - -Walking operations ------------------- - -.. include:: /../../examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py - :start-after: """# - :language: python - -:download:`Download` script. - -.. include:: /../../examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py - :start-after: """ - :end-before: """# - -.. literalinclude:: /../../examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py - :start-after: """# - :language: python - -:download:`Download` script. - -See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/agent/ntforg/advanced-topics.rst b/docs/source/examples/hlapi/v1arch/asyncore/agent/ntforg/advanced-topics.rst new file mode 100644 index 00000000..a1dec24c --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/agent/ntforg/advanced-topics.rst @@ -0,0 +1,7 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Notification Originator +-------------------------------- + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/v1arch/asyncore/agent/ntforg/common-notifications.rst new file mode 100644 index 00000000..3bfbde3a --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/agent/ntforg/common-notifications.rst @@ -0,0 +1,49 @@ +.. toctree:: + :maxdepth: 2 + +Common notifications +-------------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/agent/ntforg/evaluating-notification-type.rst b/docs/source/examples/hlapi/v1arch/asyncore/agent/ntforg/evaluating-notification-type.rst new file mode 100644 index 00000000..b3b14adf --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/agent/ntforg/evaluating-notification-type.rst @@ -0,0 +1,18 @@ +.. toctree:: + :maxdepth: 2 + +Evaluating NOTIFICATION-TYPE +---------------------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/contents.rst b/docs/source/examples/hlapi/v1arch/asyncore/contents.rst new file mode 100644 index 00000000..5f1e16d9 --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/contents.rst @@ -0,0 +1,60 @@ + +Asynchronous SNMP (asyncore, v1arch) +==================================== + +Applications build around :mod:`asyncore` get CPU time on :mod:`socket` +events being watched for by :mod:`select` dispatcher. User code +lives mostly in isolated functions (or any callable objects). + +As it is with any asynchronous I/O system, `asyncore` lets you run +many SNMP queries in parallel and/or sequentially, interleave SNMP +queries with other I/O operations for as long as they are managed +within the same event loop. + +The :mod:`pysnmp.hlapi.v1arch.asyncore` package implements `asyncore` +binding to pysnmp's `v1arch` services. + +In most examples approximate analogues of well known Net-SNMP snmp* tools +command line options are shown. That may help those readers who, by chance +are familiar with Net-SNMP tools, better understanding what example code doe + +Here's a quick example on a simple SNMP GET by high-level API: + +.. include:: /../../examples/hlapi/v1arch/asyncore/manager/cmdgen/v2c-get.py + :start-after: options: + :end-before: Functionally + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/manager/cmdgen/v2c-get.py + :start-after: """# + :language: python + +.. toctree:: + + /examples/hlapi/v1arch/asyncore/manager/cmdgen/snmp-versions + /examples/hlapi/v1arch/asyncore/manager/cmdgen/modifying-variables + /examples/hlapi/v1arch/asyncore/manager/cmdgen/walking-operations + /examples/hlapi/v1arch/asyncore/manager/cmdgen/table-operations + /examples/hlapi/v1arch/asyncore/manager/cmdgen/mib-tweaks + /examples/hlapi/v1arch/asyncore/manager/cmdgen/transport-tweaks + /examples/hlapi/v1arch/asyncore/manager/cmdgen/advanced-topics + +The following code sends SNMP TRAP: + + .. include:: /../../examples/hlapi/v1arch/asyncore/agent/ntforg/generic-v1-trap.py + :start-after: options: + :end-before: Functionally + + .. literalinclude:: /../../examples/hlapi/v1arch/asyncore/agent/ntforg/generic-v1-trap.py + :start-after: """# + :language: python + +More examples on Notification Originator API usage follow. + +.. toctree:: + + /examples/hlapi/v1arch/asyncore/agent/ntforg/common-notifications + /examples/hlapi/v1arch/asyncore/agent/ntforg/evaluating-notification-type + /examples/hlapi/v1arch/asyncore/agent/ntforg/advanced-topics + +More sophisticated SNMP operations can still be performed with +PySNMP via its Native API to Standard SNMP Applications. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/advanced-topics.rst new file mode 100644 index 00000000..aec0b85b --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/advanced-topics.rst @@ -0,0 +1,39 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Command Generator +-------------------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/mib-tweaks.rst b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/mib-tweaks.rst new file mode 100644 index 00000000..3bc98656 --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/mib-tweaks.rst @@ -0,0 +1,48 @@ +.. toctree:: + :maxdepth: 2 + +MIB tweaks +---------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/modifying-variables.rst b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/modifying-variables.rst new file mode 100644 index 00000000..b6aa9add --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/modifying-variables.rst @@ -0,0 +1,30 @@ + +.. toctree:: + :maxdepth: 2 + +Modifying variables +------------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library-reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/snmp-versions.rst new file mode 100644 index 00000000..9f9c0ec5 --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/snmp-versions.rst @@ -0,0 +1,30 @@ +.. toctree:: + :maxdepth: 2 + +Various SNMP versions +---------------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/manager/cmdgen/v2c-get.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/manager/cmdgen/v2c-get.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. comment + + .. include:: /../../examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py + :start-after: """ + :end-before: """# + + .. literalinclude:: /../../examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py + :start-after: """# + :language: python + + :download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/table-operations.rst b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/table-operations.rst new file mode 100644 index 00000000..ede8a8ed --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/table-operations.rst @@ -0,0 +1,50 @@ +.. toctree:: + :maxdepth: 2 + +Table operations +---------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/transport-tweaks.rst b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/transport-tweaks.rst new file mode 100644 index 00000000..5c948d51 --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/transport-tweaks.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Transport tweaks +---------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/walking-operations.rst new file mode 100644 index 00000000..e843fb42 --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/manager/cmdgen/walking-operations.rst @@ -0,0 +1,18 @@ +.. toctree:: + :maxdepth: 2 + +Walking operations +------------------ + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/common-notifications.rst new file mode 100644 index 00000000..bf3b4fbc --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/common-notifications.rst @@ -0,0 +1,59 @@ +.. toctree:: + :maxdepth: 2 + +Common notifications +-------------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/evaluating-notification-type.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/evaluating-notification-type.rst new file mode 100644 index 00000000..c40ca45e --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/evaluating-notification-type.rst @@ -0,0 +1,17 @@ +.. toctree:: + :maxdepth: 2 + +Evaluating NOTIFICATION-TYPE +---------------------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/contents.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/contents.rst new file mode 100644 index 00000000..046138ff --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/contents.rst @@ -0,0 +1,74 @@ + +Synchronous SNMP (v1arch) +========================= + +This chapter illustrates various uses of the synchronous high-level +programming interface to client-side SNMP entities along the lines +of `RFC1905 `_. + +.. note:: The following examples involve creating Python iterator, + the next() call is used to invoke iterator just once. + +In most examples approximate analogues of well known Net-SNMP snmp* tools +command line options are shown. That may help those readers who, by chance +are familiar with Net-SNMP tools, better understanding what the example +code does. + +Here's a quick example on a simple SNMP GET by high-level API: + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py + :start-after: options: + :end-before: Functionally + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py + :start-after: """# + :language: python + +.. note:: + + If MIB lookup is required (e.g. when :py:class:`~pysnmp.smi.rfc1902.ObjectIdentity`, + :py:class:`~pysnmp.smi.rfc1902.ObjectType` or :py:class:`~pysnmp.smi.rfc1902.NotificationType` + objects being used), the `lookupMib=True` should also be passed. + +The following code performs a series of SNMP GETNEXT operations +fetching a table of SNMP variables from SNMP Agent: + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py + :start-after: options: + :end-before: Functionally + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py + :start-after: """# + :language: python + +More examples on Command Generator API usage follow. + +.. toctree:: + + /examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/snmp-versions + /examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/modifying-variables + /examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/walking-operations + /examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/table-operations + /examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/mib-tweaks + /examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/transport-tweaks + /examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/advanced-topics + +The following code sends SNMP TRAP: + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py + :start-after: options: + :end-before: Functionally + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py + :start-after: """# + :language: python + +More examples on Notification Originator API usage follow. + +.. toctree:: + + /examples/hlapi/v1arch/asyncore/sync/agent/ntforg/common-notifications + /examples/hlapi/v1arch/asyncore/sync/agent/ntforg/evaluating-notification-type + +More specific SNMP operations can still be performed with PySNMP via +its Native API to Standard SNMP Applications. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/advanced-topics.rst new file mode 100644 index 00000000..aec0b85b --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/advanced-topics.rst @@ -0,0 +1,39 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Command Generator +-------------------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/mib-tweaks.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/mib-tweaks.rst new file mode 100644 index 00000000..3bc98656 --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/mib-tweaks.rst @@ -0,0 +1,48 @@ +.. toctree:: + :maxdepth: 2 + +MIB tweaks +---------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/modifying-variables.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/modifying-variables.rst new file mode 100644 index 00000000..b6aa9add --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/modifying-variables.rst @@ -0,0 +1,30 @@ + +.. toctree:: + :maxdepth: 2 + +Modifying variables +------------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library-reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/snmp-versions.rst new file mode 100644 index 00000000..2d408866 --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/snmp-versions.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +SNMP versions +------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/table-operations.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/table-operations.rst new file mode 100644 index 00000000..ede8a8ed --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/table-operations.rst @@ -0,0 +1,50 @@ +.. toctree:: + :maxdepth: 2 + +Table operations +---------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/table-operations.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/table-operations.rst- similarity index 100% rename from docs/source/examples/hlapi/asyncore/sync/manager/cmdgen/table-operations.rst rename to docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/table-operations.rst- diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/transport-tweaks.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/transport-tweaks.rst new file mode 100644 index 00000000..5c948d51 --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/transport-tweaks.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Transport tweaks +---------------- + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/walking-operations.rst new file mode 100644 index 00000000..e843fb42 --- /dev/null +++ b/docs/source/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/walking-operations.rst @@ -0,0 +1,18 @@ +.. toctree:: + :maxdepth: 2 + +Walking operations +------------------ + +.. include:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncio/agent/ntforg/advanced-topics.rst b/docs/source/examples/hlapi/v3arch/asyncio/agent/ntforg/advanced-topics.rst new file mode 100644 index 00000000..37a23b64 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncio/agent/ntforg/advanced-topics.rst @@ -0,0 +1,17 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Notification Originator +-------------------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncio/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/v3arch/asyncio/agent/ntforg/common-notifications.rst new file mode 100644 index 00000000..b56622f4 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncio/agent/ntforg/common-notifications.rst @@ -0,0 +1,17 @@ +.. toctree:: + :maxdepth: 2 + +Common notifications +-------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncio/contents.rst b/docs/source/examples/hlapi/v3arch/asyncio/contents.rst similarity index 61% rename from docs/source/examples/hlapi/asyncio/contents.rst rename to docs/source/examples/hlapi/v3arch/asyncio/contents.rst index 4283d67e..2057d56f 100644 --- a/docs/source/examples/hlapi/asyncio/contents.rst +++ b/docs/source/examples/hlapi/v3arch/asyncio/contents.rst @@ -1,6 +1,6 @@ -Asynchronous: asyncio -===================== +Asynchronous SNMP (asynio, v3arch) +================================== The :mod:`asyncio` module first appeared in standard library since Python 3.3 (in provisional basis). Its main design feature is that it @@ -8,8 +8,8 @@ makes asynchronous code looking like synchronous one thus eliminating "callback hell". With `asyncio` built-in facilities, you could run many SNMP queries -in parallel and/or sequentially, interleave SNMP queries with I/O -operations with other systems. See `asyncio resources `_ +in parallel and/or sequentially, interleave SNMP queries with other I/O +operations. See `asyncio resources `_ repository for other `asyncio`-compatible modules. In most examples approximate analogues of well known Net-SNMP snmp* tools @@ -18,11 +18,11 @@ are familiar with Net-SNMP tools, better understanding what example code doe Here's a quick example on a simple SNMP GET by high-level API: -.. include:: /../../examples/hlapi/asyncio/manager/cmdgen/v1-get.py +.. include:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/asyncio/manager/cmdgen/v1-get.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py :start-after: """# :language: python @@ -30,11 +30,11 @@ To make use of SNMPv3 and USM, the following code performs a series of SNMP GETNEXT operations effectively fetching a table of SNMP variables from SNMP Agent: -.. include:: /../../examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py +.. include:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py :start-after: """# :language: python @@ -42,18 +42,18 @@ More examples on Command Generator API usage follow. .. toctree:: - /examples/hlapi/asyncio/manager/cmdgen/snmp-versions - /examples/hlapi/asyncio/manager/cmdgen/walking-operations - /examples/hlapi/asyncio/manager/cmdgen/advanced-topics + /examples/hlapi/v3arch/asyncio/manager/cmdgen/snmp-versions + /examples/hlapi/v3arch/asyncio/manager/cmdgen/walking-operations + /examples/hlapi/v3arch/asyncio/manager/cmdgen/advanced-topics Sending SNMP TRAP's and INFORM's is as easy with PySNMP library. The following code sends SNMP TRAP: -.. include:: /../../examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py +.. include:: /../../examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py :start-after: """# :language: python @@ -61,8 +61,8 @@ More examples on Notification Originator API usage follow. .. toctree:: - /examples/hlapi/asyncio/agent/ntforg/common-notifications - /examples/hlapi/asyncio/agent/ntforg/advanced-topics + /examples/hlapi/v3arch/asyncio/agent/ntforg/common-notifications + /examples/hlapi/v3arch/asyncio/agent/ntforg/advanced-topics More sophisticated or less popular SNMP operations can still be performed with PySNMP through its Native API to Standard SNMP Applications. diff --git a/docs/source/examples/hlapi/v3arch/asyncio/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/v3arch/asyncio/manager/cmdgen/advanced-topics.rst new file mode 100644 index 00000000..ed74be3b --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncio/manager/cmdgen/advanced-topics.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Command Generator +-------------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncio/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/v3arch/asyncio/manager/cmdgen/snmp-versions.rst new file mode 100644 index 00000000..e2496ed2 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncio/manager/cmdgen/snmp-versions.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Various SNMP versions +---------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncio/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/v3arch/asyncio/manager/cmdgen/walking-operations.rst new file mode 100644 index 00000000..68d05dc0 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncio/manager/cmdgen/walking-operations.rst @@ -0,0 +1,17 @@ +.. toctree:: + :maxdepth: 2 + +Walking operations +------------------ + +.. include:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/agent/ntforg/advanced-topics.rst b/docs/source/examples/hlapi/v3arch/asyncore/agent/ntforg/advanced-topics.rst new file mode 100644 index 00000000..60d45a08 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/agent/ntforg/advanced-topics.rst @@ -0,0 +1,40 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Notification Originator +-------------------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/v3arch/asyncore/agent/ntforg/common-notifications.rst new file mode 100644 index 00000000..75c614d3 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/agent/ntforg/common-notifications.rst @@ -0,0 +1,17 @@ +.. toctree:: + :maxdepth: 2 + +Common notifications +-------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/default-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/default-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/contents.rst b/docs/source/examples/hlapi/v3arch/asyncore/contents.rst similarity index 53% rename from docs/source/examples/hlapi/asyncore/contents.rst rename to docs/source/examples/hlapi/v3arch/asyncore/contents.rst index c589cd09..f9d70c49 100644 --- a/docs/source/examples/hlapi/asyncore/contents.rst +++ b/docs/source/examples/hlapi/v3arch/asyncore/contents.rst @@ -1,22 +1,30 @@ -Asynchronous: asyncore -====================== +Asynchronous SNMP (asyncore, v3arch) +==================================== With :mod:`asyncore` API your scripts get CPU time on :mod:`socket` events being watched for by :mod:`select` dispatcher. Your code live mostly in isolated functions (or any callable objects). +As it is with any asynchronous I/O system, `asyncore` lets you run +many SNMP queries in parallel and/or sequentially, interleave SNMP +queries with other I/O operations for as long as they are managed +within the same event loop. + +The :mod:`pysnmp.hlapi.v3arch.asyncore` package implements `asyncore` +binding to pysnmp's `v3arch` services. + In most examples approximate analogues of well known Net-SNMP snmp* tools command line options are shown. That may help those readers who, by chance are familiar with Net-SNMP tools, better understanding what example code doe Here's a quick example on a simple SNMP GET by high-level API: -.. include:: /../../examples/hlapi/asyncore/manager/cmdgen/v2c-get.py +.. include:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/asyncore/manager/cmdgen/v2c-get.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py :start-after: """# :language: python @@ -24,11 +32,11 @@ To make use of SNMPv3 and USM, the following code performs a series of SNMP GETNEXT operations effectively fetching a table of SNMP variables from SNMP Agent: -.. include:: /../../examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py +.. include:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py :start-after: """# :language: python @@ -36,18 +44,18 @@ More examples on Command Generator API usage follow. .. toctree:: - /examples/hlapi/asyncore/manager/cmdgen/snmp-versions - /examples/hlapi/asyncore/manager/cmdgen/walking-operations - /examples/hlapi/asyncore/manager/cmdgen/advanced-topics + /examples/hlapi/v3arch/asyncore/manager/cmdgen/snmp-versions + /examples/hlapi/v3arch/asyncore/manager/cmdgen/walking-operations + /examples/hlapi/v3arch/asyncore/manager/cmdgen/advanced-topics Sending SNMP TRAP's and INFORM's is as easy with PySNMP library. The following code sends SNMP TRAP: -.. include:: /../../examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py +.. include:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/default-v1-trap.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/agent/ntforg/default-v1-trap.py :start-after: """# :language: python @@ -55,8 +63,8 @@ More examples on Notification Originator API usage follow. .. toctree:: - /examples/hlapi/asyncore/agent/ntforg/common-notifications - /examples/hlapi/asyncore/agent/ntforg/advanced-topics + /examples/hlapi/v3arch/asyncore/agent/ntforg/common-notifications + /examples/hlapi/v3arch/asyncore/agent/ntforg/advanced-topics More sophisticated or less popular SNMP operations can still be performed with PySNMP through its Native API to Standard SNMP Applications. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/v3arch/asyncore/manager/cmdgen/advanced-topics.rst new file mode 100644 index 00000000..7249f918 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/manager/cmdgen/advanced-topics.rst @@ -0,0 +1,40 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Command Generator +-------------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/v3arch/asyncore/manager/cmdgen/snmp-versions.rst new file mode 100644 index 00000000..b9dddb22 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/manager/cmdgen/snmp-versions.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Various SNMP versions +---------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/v3arch/asyncore/manager/cmdgen/walking-operations.rst new file mode 100644 index 00000000..dcd5da25 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/manager/cmdgen/walking-operations.rst @@ -0,0 +1,18 @@ +.. toctree:: + :maxdepth: 2 + +Walking operations +------------------ + +.. include:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/advanced-topics.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/advanced-topics.rst new file mode 100644 index 00000000..d7a82b2c --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/advanced-topics.rst @@ -0,0 +1,28 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Notification Originator +-------------------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/common-notifications.rst new file mode 100644 index 00000000..4aabf1b1 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/common-notifications.rst @@ -0,0 +1,49 @@ +.. toctree:: + :maxdepth: 2 + +Common notifications +-------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/evaluating-notification-type.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/evaluating-notification-type.rst new file mode 100644 index 00000000..255bd7d1 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/evaluating-notification-type.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Evaluating NOTIFICATION-TYPE +---------------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/snmp-v1-trap-variants.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/snmp-v1-trap-variants.rst new file mode 100644 index 00000000..90bf0941 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/snmp-v1-trap-variants.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +SNMPv1 TRAP variants +-------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/asyncore/sync/contents.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/contents.rst similarity index 50% rename from docs/source/examples/hlapi/asyncore/sync/contents.rst rename to docs/source/examples/hlapi/v3arch/asyncore/sync/contents.rst index 29211c7c..031cae7d 100644 --- a/docs/source/examples/hlapi/asyncore/sync/contents.rst +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/contents.rst @@ -1,6 +1,6 @@ -Synchronous SNMP -================ +Synchronous SNMP (v3arch) +========================= This chapter illustrates various uses of the synchronous high-level programming interface to some of Standard SNMP Applications, as defined in @@ -11,15 +11,16 @@ programming interface to some of Standard SNMP Applications, as defined in In most examples approximate analogues of well known Net-SNMP snmp* tools command line options are shown. That may help those readers who, by chance -are familiar with Net-SNMP tools, better understanding what example code doe +are familiar with Net-SNMP tools, better understanding what the example code +does. Here's a quick example on a simple SNMP GET by high-level API: -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py :start-after: """# :language: python @@ -27,11 +28,11 @@ To make use of SNMPv3 and USM, the following code performs a series of SNMP GETNEXT operations effectively fetching a table of SNMP variables from SNMP Agent: -.. include:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py :start-after: """# :language: python @@ -39,22 +40,22 @@ More examples on Command Generator API usage follow. .. toctree:: - /examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions - /examples/hlapi/asyncore/sync/manager/cmdgen/modifying-variables - /examples/hlapi/asyncore/sync/manager/cmdgen/walking-operations - /examples/hlapi/asyncore/sync/manager/cmdgen/table-operations - /examples/hlapi/asyncore/sync/manager/cmdgen/mib-tweaks - /examples/hlapi/asyncore/sync/manager/cmdgen/transport-tweaks - /examples/hlapi/asyncore/sync/manager/cmdgen/advanced-topics + /examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/snmp-versions + /examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/modifying-variables + /examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/walking-operations + /examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/table-operations + /examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/mib-tweaks + /examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/transport-tweaks + /examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/advanced-topics Sending SNMP TRAP's and INFORM's is as easy with PySNMP library. The following code sends SNMP TRAP: -.. include:: /../../examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py :start-after: """# :language: python @@ -62,10 +63,10 @@ More examples on Notification Originator API usage follow. .. toctree:: - /examples/hlapi/asyncore/sync/agent/ntforg/common-notifications - /examples/hlapi/asyncore/sync/agent/ntforg/snmp-v1-trap-variants - /examples/hlapi/asyncore/sync/agent/ntforg/evaluating-notification-type - /examples/hlapi/asyncore/sync/agent/ntforg/advanced-topics + /examples/hlapi/v3arch/asyncore/sync/agent/ntforg/common-notifications + /examples/hlapi/v3arch/asyncore/sync/agent/ntforg/snmp-v1-trap-variants + /examples/hlapi/v3arch/asyncore/sync/agent/ntforg/evaluating-notification-type + /examples/hlapi/v3arch/asyncore/sync/agent/ntforg/advanced-topics More sophisticated or less popular SNMP operations can still be performed with PySNMP through its Native API to Standard SNMP Applications. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/advanced-topics.rst new file mode 100644 index 00000000..0b9c5df0 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/advanced-topics.rst @@ -0,0 +1,84 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Command Generator +-------------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/mib-tweaks.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/mib-tweaks.rst new file mode 100644 index 00000000..34e8988a --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/mib-tweaks.rst @@ -0,0 +1,48 @@ +.. toctree:: + :maxdepth: 2 + +MIB tweaks +---------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/modifying-variables.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/modifying-variables.rst new file mode 100644 index 00000000..384fc3b8 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/modifying-variables.rst @@ -0,0 +1,30 @@ + +.. toctree:: + :maxdepth: 2 + +Modifying variables +------------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library-reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/snmp-versions.rst new file mode 100644 index 00000000..087df557 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/snmp-versions.rst @@ -0,0 +1,72 @@ +.. toctree:: + :maxdepth: 2 + +SNMP versions +------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/table-operations.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/table-operations.rst new file mode 100644 index 00000000..59066848 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/table-operations.rst @@ -0,0 +1,50 @@ +.. toctree:: + :maxdepth: 2 + +Table operations +---------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/transport-tweaks.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/transport-tweaks.rst new file mode 100644 index 00000000..5d6a29a7 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/transport-tweaks.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Transport tweaks +---------------- + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/walking-operations.rst new file mode 100644 index 00000000..44a4888e --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/walking-operations.rst @@ -0,0 +1,18 @@ +.. toctree:: + :maxdepth: 2 + +Walking operations +------------------ + +.. include:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/trollius/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/v3arch/trollius/agent/ntforg/common-notifications.rst new file mode 100644 index 00000000..169af765 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/trollius/agent/ntforg/common-notifications.rst @@ -0,0 +1,17 @@ +.. toctree:: + :maxdepth: 2 + +Common notifications +-------------------- + +.. include:: /../../examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/trollius/contents.rst b/docs/source/examples/hlapi/v3arch/trollius/contents.rst similarity index 65% rename from docs/source/examples/hlapi/trollius/contents.rst rename to docs/source/examples/hlapi/v3arch/trollius/contents.rst index 1424c7d0..159d4cda 100644 --- a/docs/source/examples/hlapi/trollius/contents.rst +++ b/docs/source/examples/hlapi/v3arch/trollius/contents.rst @@ -1,6 +1,6 @@ -Asynchronous: trollius -====================== +Asynchronous SNMP (trollius, v3arch) +==================================== In order to use :mod:`asyncio` features with older Python (2.6+), you could download and install `Trollius `_ @@ -12,11 +12,11 @@ are familiar with Net-SNMP tools, better understanding what example code doe Here's a quick example on a simple SNMP GET by high-level API: -.. include:: /../../examples/hlapi/trollius/manager/cmdgen/v1-get.py +.. include:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/trollius/manager/cmdgen/v1-get.py +.. literalinclude:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py :start-after: """# :language: python @@ -24,11 +24,11 @@ To make use of SNMPv3 and USM, the following code performs a series of SNMP GETNEXT operations effectively fetching a table of SNMP variables from SNMP Agent: -.. include:: /../../examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py +.. include:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py +.. literalinclude:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py :start-after: """# :language: python @@ -36,17 +36,17 @@ More examples on Command Generator API usage follow. .. toctree:: - /examples/hlapi/trollius/manager/cmdgen/snmp-versions - /examples/hlapi/trollius/manager/cmdgen/walking-operations + /examples/hlapi/v3arch/trollius/manager/cmdgen/snmp-versions + /examples/hlapi/v3arch/trollius/manager/cmdgen/walking-operations Sending SNMP TRAP's and INFORM's is as easy with PySNMP library. The following code sends SNMP TRAP: -.. include:: /../../examples/hlapi/trollius/agent/ntforg/default-v1-trap.py +.. include:: /../../examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/trollius/agent/ntforg/default-v1-trap.py +.. literalinclude:: /../../examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py :start-after: """# :language: python @@ -54,7 +54,7 @@ More examples on Notification Originator API usage follow. .. toctree:: - /examples/hlapi/trollius/agent/ntforg/common-notifications + /examples/hlapi/v3arch/trollius/agent/ntforg/common-notifications More sophisticated or less popular SNMP operations can still be performed with PySNMP through its Native API to Standard SNMP Applications. diff --git a/docs/source/examples/hlapi/v3arch/trollius/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/v3arch/trollius/manager/cmdgen/snmp-versions.rst new file mode 100644 index 00000000..3b70a61c --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/trollius/manager/cmdgen/snmp-versions.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Various SNMP versions +---------------------- + +.. include:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/trollius/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/v3arch/trollius/manager/cmdgen/walking-operations.rst new file mode 100644 index 00000000..ec416080 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/trollius/manager/cmdgen/walking-operations.rst @@ -0,0 +1,17 @@ +.. toctree:: + :maxdepth: 2 + +Walking operations +------------------ + +.. include:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/twisted/agent/ntforg/advanced-topics.rst b/docs/source/examples/hlapi/v3arch/twisted/agent/ntforg/advanced-topics.rst new file mode 100644 index 00000000..fd209711 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/twisted/agent/ntforg/advanced-topics.rst @@ -0,0 +1,17 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Notification Originator +-------------------------------- + +.. include:: /../../examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/twisted/agent/ntforg/common-notifications.rst b/docs/source/examples/hlapi/v3arch/twisted/agent/ntforg/common-notifications.rst new file mode 100644 index 00000000..d02ca5e6 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/twisted/agent/ntforg/common-notifications.rst @@ -0,0 +1,27 @@ +.. toctree:: + :maxdepth: 2 + +Common notifications +-------------------- + +.. include:: /../../examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/twisted/contents.rst b/docs/source/examples/hlapi/v3arch/twisted/contents.rst similarity index 63% rename from docs/source/examples/hlapi/twisted/contents.rst rename to docs/source/examples/hlapi/v3arch/twisted/contents.rst index 1b06d576..e4d221de 100644 --- a/docs/source/examples/hlapi/twisted/contents.rst +++ b/docs/source/examples/hlapi/v3arch/twisted/contents.rst @@ -1,8 +1,8 @@ -Asynchronous: Twisted -===================== +Asynchronous SNMP (twisted, v3arch) +=================================== -`Twisted `_ is quite old and widly used +`Twisted `_ is quite old but still widely used I/O framework. With Twisted, your code will mostly live in isolated functions, but unlike as it is with callback-based design, with Twisted work-in-progress is represented by a @@ -20,11 +20,11 @@ are familiar with Net-SNMP tools, better understanding what example code doe Here's a quick example on a simple SNMP GET by high-level API: -.. include:: /../../examples/hlapi/twisted/manager/cmdgen/v1-get.py +.. include:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/twisted/manager/cmdgen/v1-get.py +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py :start-after: """# :language: python @@ -32,11 +32,11 @@ To make use of SNMPv3 and USM, the following code performs a series of SNMP GETNEXT operations effectively fetching a table of SNMP variables from SNMP Agent: -.. include:: /../../examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py +.. include:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py :start-after: """# :language: python @@ -44,19 +44,19 @@ More examples on Command Generator API usage follow. .. toctree:: - /examples/hlapi/twisted/manager/cmdgen/snmp-versions - /examples/hlapi/twisted/manager/cmdgen/walking-operations - /examples/hlapi/twisted/manager/cmdgen/transport-tweaks - /examples/hlapi/twisted/manager/cmdgen/advanced-topics + /examples/hlapi/v3arch/twisted/manager/cmdgen/snmp-versions + /examples/hlapi/v3arch/twisted/manager/cmdgen/walking-operations + /examples/hlapi/v3arch/twisted/manager/cmdgen/transport-tweaks + /examples/hlapi/v3arch/twisted/manager/cmdgen/advanced-topics Sending SNMP TRAP's and INFORM's is as easy with PySNMP library. The following code sends SNMP TRAP: -.. include:: /../../examples/hlapi/twisted/agent/ntforg/default-v1-trap.py +.. include:: /../../examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py :start-after: options: :end-before: Functionally -.. literalinclude:: /../../examples/hlapi/twisted/agent/ntforg/default-v1-trap.py +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py :start-after: """# :language: python @@ -64,8 +64,8 @@ More examples on Notification Originator API usage follow. .. toctree:: - /examples/hlapi/twisted/agent/ntforg/common-notifications - /examples/hlapi/twisted/agent/ntforg/advanced-topics + /examples/hlapi/v3arch/twisted/agent/ntforg/common-notifications + /examples/hlapi/v3arch/twisted/agent/ntforg/advanced-topics More sophisticated or less popular SNMP operations can still be performed with PySNMP through its Native API to Standard SNMP Applications. diff --git a/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/advanced-topics.rst b/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/advanced-topics.rst new file mode 100644 index 00000000..e094ac67 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/advanced-topics.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Advanced Command Generator +-------------------------- + +.. include:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/snmp-versions.rst b/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/snmp-versions.rst new file mode 100644 index 00000000..7b1746e0 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/snmp-versions.rst @@ -0,0 +1,29 @@ +.. toctree:: + :maxdepth: 2 + +Various SNMP versions +---------------------- + +.. include:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py + :start-after: """# + :language: python + +:download:`Download` script. + + +.. include:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py + :start-after: """# + :language: python + +:download:`Download` script. + + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/transport-tweaks.rst b/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/transport-tweaks.rst new file mode 100644 index 00000000..dbadb831 --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/transport-tweaks.rst @@ -0,0 +1,17 @@ +.. toctree:: + :maxdepth: 2 + +Transport tweaks +---------------- + +.. include:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/walking-operations.rst b/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/walking-operations.rst new file mode 100644 index 00000000..7c87bc5a --- /dev/null +++ b/docs/source/examples/hlapi/v3arch/twisted/manager/cmdgen/walking-operations.rst @@ -0,0 +1,27 @@ +.. toctree:: + :maxdepth: 2 + +Walking operations +------------------ + +.. include:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py + :start-after: """# + :language: python + +:download:`Download` script. + +.. include:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py + :start-after: """ + :end-before: """# + +.. literalinclude:: /../../examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py + :start-after: """# + :language: python + +:download:`Download` script. + +See also: :doc:`library reference `. diff --git a/docs/source/examples/v3arch/asyncio/contents.rst b/docs/source/examples/v3arch/asyncio/contents.rst index 21b00a88..c64fec52 100644 --- a/docs/source/examples/v3arch/asyncio/contents.rst +++ b/docs/source/examples/v3arch/asyncio/contents.rst @@ -1,6 +1,6 @@ -Asynchronous: asyncio -===================== +Asynchronous SNMP (asyncio, v3arch) +=================================== Python 3.4 introduced a new module - `asyncio `_ (former Tulip, PEP 3156) featuring infrastructure for writing single-threaded concurrent @@ -26,7 +26,7 @@ remains available to asyncio-backed applications. We do not provide Command Generator and Notification Originator examples, as it is much easier to use -:doc:`high-level interfaces ` instead. +:doc:`high-level interfaces ` instead. Command Responder Applications ------------------------------ diff --git a/docs/source/examples/v3arch/asyncore/contents.rst b/docs/source/examples/v3arch/asyncore/contents.rst index 17ebfc70..e677029b 100644 --- a/docs/source/examples/v3arch/asyncore/contents.rst +++ b/docs/source/examples/v3arch/asyncore/contents.rst @@ -1,6 +1,6 @@ -Asynchronous: asyncore -====================== +Asynchronous SNMP (asyncore, v3arch) +==================================== If you find yourself unable to use particular SNMP feature with the high-level (hlapi) API, your next step would be to use SNMPv3 diff --git a/docs/source/examples/v3arch/trollius/contents.rst b/docs/source/examples/v3arch/trollius/contents.rst index 89be5185..68ad70a3 100644 --- a/docs/source/examples/v3arch/trollius/contents.rst +++ b/docs/source/examples/v3arch/trollius/contents.rst @@ -1,6 +1,6 @@ -Asynchronous: trollius -====================== +Asynchronous SNMP (trollius, v3arch) +==================================== `Trollius `_ framework offers infrastructure that allows you writing single-threaded, concurrent code @@ -16,7 +16,7 @@ remains available to asyncio-backed applications. We do not provide Command Generator and Notification Originator examples, as it is much easier to use -:doc:`high-level interfaces ` instead. +:doc:`high-level interfaces ` instead. As for Command Responder and Notification Receiver, those could be use in the same way as with :doc:`asyncio `. diff --git a/docs/source/examples/v3arch/twisted/contents.rst b/docs/source/examples/v3arch/twisted/contents.rst index 6127b373..60626c29 100644 --- a/docs/source/examples/v3arch/twisted/contents.rst +++ b/docs/source/examples/v3arch/twisted/contents.rst @@ -1,6 +1,6 @@ -Asynchronous: Twisted -===================== +Asynchronous SNMP (twisted, v3arch) +=================================== `Twisted `_ is event-driven networking engine written in Python. It takes shape of a Python library which is used by many @@ -11,7 +11,7 @@ remains available to Twisted applications. We do not provide Command Generator and Notification Originator examples, as it is much easier to use -:doc:`high-level interfaces ` instead. +:doc:`high-level interfaces ` instead. Command Responder Applications ------------------------------ diff --git a/docs/source/faq/pass-custom-mib-to-manager.rst b/docs/source/faq/pass-custom-mib-to-manager.rst index b42e6839..ded4de29 100644 --- a/docs/source/faq/pass-custom-mib-to-manager.rst +++ b/docs/source/faq/pass-custom-mib-to-manager.rst @@ -17,7 +17,7 @@ A. Starting from PySNMP 4.3.x, plain-text (ASN.1) MIBs can be `http://mibs.snmplabs.com/asn1/ `_ as shown below. -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py :start-after: """# :language: python @@ -36,7 +36,7 @@ A. Starting from PySNMP 4.3.x, plain-text (ASN.1) MIBs can be 'http://mibs.snmplabs.com/asn1/@mib@', ]) -:download:`Download` script. +:download:`Download` script. Alternatively, you can invoke the `mibdump.py `_ diff --git a/docs/source/quick-start.rst b/docs/source/quick-start.rst index 73040e4c..9fbda6ab 100644 --- a/docs/source/quick-start.rst +++ b/docs/source/quick-start.rst @@ -18,11 +18,11 @@ code will performs SNMP GET operation for a sysDescr.0 object at a publically available SNMP Command Responder at `demo.snmplabs.com `_: -.. literalinclude:: /../../examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py :start-after: """# :language: python -:download:`Download` script. +:download:`Download` script. If everything works as it should you will get: @@ -41,11 +41,11 @@ To send a trivial TRAP message to our hosted Notification Receiver at `demo.snmplabs.com `_ , just cut&paste the following code into your interactive Python session: -.. literalinclude:: /../../examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py +.. literalinclude:: /../../examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py :start-after: """# :language: python -:download:`Download` script. +:download:`Download` script. Many ASN.1 MIB files could be downloaded from `mibs.snmplabs.com `_ or PySNMP could diff --git a/examples/hlapi/v1arch/asyncore/agent/ntforg/generic-v1-trap.py b/examples/hlapi/v1arch/asyncore/agent/ntforg/generic-v1-trap.py new file mode 100644 index 00000000..ca969f10 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/agent/ntforg/generic-v1-trap.py @@ -0,0 +1,52 @@ +""" +Generic SNMPv1 TRAP ++++++++++++++++++++ + +Send SNMPv1 TRAP using the following options: + +* SNMPv1 +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with Uptime 12345 +* with Generic Trap #1 (warmStart) and Specific Trap 0 +* with Agent Address 127.0.0.1 +* with Enterprise OID 1.3.6.1.4.1.20408.4.1.1.2 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v1 -c public demo.snmplabs.com 1.3.6.1.4.1.20408.4.1.1.2 0.0.0.0 1 0 0 1.3.6.1.2.1.1.1.0 s "my system" + +"""# +from pysnmp.hlapi.v1arch.asyncore import * + + +def cbFun(errorIndication, errorStatus, errorIndex, varBinds, **context): + if errorIndication: + print(errorIndication) + + +snmpDispatcher = SnmpDispatcher() + +sendNotification( + snmpDispatcher, + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 162)), + 'trap', + # SNMPv2-MIB::sysUpTime.0 = 12345 + ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)), + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart + ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')), + # SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = 127.0.0.1 + ('1.3.6.1.6.3.18.1.3.0', IpAddress('127.0.0.1')), + # SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = public + ('1.3.6.1.6.3.18.1.4.0', OctetString('public')), + # SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = 1.3.6.1.4.1.20408.4.1.1.2 + ('1.3.6.1.6.3.1.1.4.3.0', ObjectIdentifier('1.3.6.1.4.1.20408.4.1.1.2')), + # SNMPv2-MIB::sysName.0 + ('1.3.6.1.2.1.1.1.0', OctetString('my system')), + cbFun=cbFun +) + +snmpDispatcher.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/v1arch/asyncore/agent/ntforg/generic-v2c-trap.py b/examples/hlapi/v1arch/asyncore/agent/ntforg/generic-v2c-trap.py new file mode 100644 index 00000000..36c01e60 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/agent/ntforg/generic-v2c-trap.py @@ -0,0 +1,44 @@ +""" +Generic SNMPv2c TRAP +++++++++++++++++++++ + +Send SNMPv1 TRAP using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with Uptime 12345 +* with Generic Trap #1 (warmStart) and Specific Trap 0 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v2c -c public demo.snmplabs.com 12345 1.3.6.1.6.3.1.1.5.2 1.3.6.1.2.1.1.1.0 s "my system" + +"""# +from pysnmp.hlapi.v1arch.asyncore import * + + +def cbFun(errorIndication, errorStatus, errorIndex, varBinds, **context): + if errorIndication: + print(errorIndication) + + +snmpDispatcher = SnmpDispatcher() + +sendNotification( + snmpDispatcher, + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + 'trap', + # SNMPv2-MIB::sysUpTime.0 = 12345 + ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)), + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart + ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')), + # SNMPv2-MIB::sysName.0 + ('1.3.6.1.2.1.1.1.0', OctetString('my system')), + cbFun=cbFun +) + +snmpDispatcher.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/v1arch/asyncore/agent/ntforg/v2c-inform.py b/examples/hlapi/v1arch/asyncore/agent/ntforg/v2c-inform.py new file mode 100644 index 00000000..8271a9f5 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/agent/ntforg/v2c-inform.py @@ -0,0 +1,51 @@ +""" +SNMPv2c INFORM +++++++++++++++ + +Send SNMP INFORM notification using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send INFORM notification +* with TRAP ID 'warmStart' specified as a string OID +* include managed object information 1.3.6.1.2.1.1.5.0 = 'system name' + +Functionally similar to: + +| $ snmpinform -v2c -c public demo.snmplabs.com 12345 1.3.6.1.4.1.20408.4.1.1.2 1.3.6.1.2.1.1.1.0 s "my system" + +"""# +from pysnmp.hlapi.v1arch.asyncore import * + + +def cbFun(errorIndication, errorStatus, errorIndex, varBinds, **context): + if errorIndication: + print(errorIndication) + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) + + +snmpDispatcher = SnmpDispatcher() + +sendNotification( + snmpDispatcher, + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + 'inform', + # SNMPv2-MIB::sysUpTime.0 = 12345 + ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)), + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart + ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')), + # SNMPv2-MIB::sysName.0 + ('1.3.6.1.2.1.1.1.0', OctetString('my system')), + cbFun=cbFun +) + +snmpDispatcher.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/v1arch/asyncore/agent/ntforg/v2c-trap-with-notification-objects.py b/examples/hlapi/v1arch/asyncore/agent/ntforg/v2c-trap-with-notification-objects.py new file mode 100644 index 00000000..a3bc18ae --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/agent/ntforg/v2c-trap-with-notification-objects.py @@ -0,0 +1,53 @@ +""" +Generic SNMPv2c TRAP +++++++++++++++++++++ + +Send SNMPv1 TRAP using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with Uptime 12345 +* with Generic Trap #1 (warmStart) and Specific Trap 0 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v2c -c public demo.snmplabs.com 12345 1.3.6.1.6.3.1.1.5.2 1.3.6.1.2.1.1.1.0 s "my system" + +"""# +from pysnmp.hlapi.v1arch.asyncore import * + + +def cbFun(errorIndication, errorStatus, errorIndex, varBinds, **context): + if errorIndication: + print(errorIndication) + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) + + +snmpDispatcher = SnmpDispatcher() + +sendNotification( + snmpDispatcher, + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + 'trap', + # SNMPv2-MIB::sysUpTime.0 = 12345 + ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)), + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart + NotificationType(ObjectIdentity('SNMPv2-MIB', 'warmStart')), + # SNMPv2-MIB::sysName.0 + ('1.3.6.1.2.1.1.1.0', OctetString('my system')), + cbFun=cbFun, + lookupMib=True +) + +snmpDispatcher.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/v1arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py b/examples/hlapi/v1arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py new file mode 100644 index 00000000..7c282a81 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py @@ -0,0 +1,63 @@ +""" +Multiple concurrent queries ++++++++++++++++++++++++++++ + +Send a bunch of different SNMP GET requests to different peers all at once, +wait for responses asynchronously: + +* with SNMPv1, community 'public' and + with SNMPv2c, community 'public' and +* over IPv4/UDP and + over IPv6/UDP +* to an Agent at demo.snmplabs.com:161 and + to an Agent at [::1]:161 +* for instances of SNMPv2-MIB::system + SNMPv2-MIB::sysLocation.0 MIB objects +* Enable MIB lookup feature +"""# +from pysnmp.hlapi.v1arch.asyncore import * + +# List of targets in the following format: +# ((authData, transportTarget, varNames), ...) +targets = ( + # 1-st target (SNMPv1 over IPv4/UDP) + (CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), + # 2-nd target (SNMPv2c over IPv4/UDP) + (CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), + # 3-nd target (SNMPv2c over IPv4/UDP) - same community and + # different transport address. + (CommunityData('public'), + Udp6TransportTarget(('::1', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))), + # N-th target + # ... +) + + +def cbFun(errorIndication, errorStatus, errorIndex, varBinds, **context): + if errorIndication: + print(errorIndication) + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) + +snmpDispatcher = SnmpDispatcher() + +# Submit a bunch of initial GET requests +for authData, transportTarget, varBinds in targets: + getCmd(snmpDispatcher, authData, transportTarget, *varBinds, + **dict(cbFun=cbFun, lookupMib=True)) + +snmpDispatcher.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py b/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py new file mode 100644 index 00000000..eaf1755d --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py @@ -0,0 +1,63 @@ +""" +Walk multiple Agents at once +++++++++++++++++++++++++++++ + +Iterate over MIBs of multiple SNMP Agents asynchronously using the +following options: + +* with SNMPv1, community 'public' and + with SNMPv2c, community 'public' and +* over IPv4/UDP and + over IPv6/UDP +* to an Agent at demo.snmplabs.com:161 and + to an Agent at [::1]:161 +* pull MIB variables till EOM +* Enable MIB lookup feature + +"""# +from pysnmp.hlapi.v1arch.asyncore import * + +# List of targets in the following format: +# ((authData, transportTarget, varNames), ...) +targets = ( + # 1-st target (SNMPv1 over IPv4/UDP) + (CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + (ObjectType(ObjectIdentity('1.3.6.1.2.1')), + ObjectType(ObjectIdentity('1.3.6.1.3.1')))), + # 2-nd target (SNMPv2c over IPv4/UDP) + (CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + (ObjectType(ObjectIdentity('1.3.6.1.4.1')),)), + # 3-th target (SNMPv3 over IPv6/UDP) + (CommunityData('public'), + Udp6TransportTarget(('::1', 161)), + (ObjectType(ObjectIdentity('IF-MIB', 'ifTable')),)) + # N-th target + # ... +) + + +def cbFun(errorIndication, errorStatus, errorIndex, varBindTable, **context): + if errorIndication: + print(errorIndication) + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + + else: + for varBindRow in varBindTable: + for varBind in varBindRow: + print(' = '.join([x.prettyPrint() for x in varBind])) + + return context.get('nextVarBinds') + +snmpDispatcher = SnmpDispatcher() + +# Submit a bunch of initial GETNEXT requests +for authData, transportTarget, varBinds in targets: + nextCmd(snmpDispatcher, authData, transportTarget, *varBinds, + **dict(cbFun=cbFun, lookupMib=True)) + +snmpDispatcher.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py new file mode 100644 index 00000000..c5731570 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py @@ -0,0 +1,44 @@ +""" +Walk whole MIB +++++++++++++++ + +Send a series of SNMP GETBULK requests using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for all OIDs past 1.3.6.1.4.1 + +Functionally similar to: + +| $ snmpwalk -v2c -c public demo.snmplabs.com 1.3.6.1.4.1 +"""# +from pysnmp.hlapi.v1arch.asyncore import * + + +def cbFun(errorIndication, errorStatus, errorIndex, varBindTable, **context): + if errorIndication: + print(errorIndication) + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + + else: + for varBindRow in varBindTable: + for varBind in varBindRow: + print(' = '.join([x.prettyPrint() for x in varBind])) + + return context.get('nextVarBinds') + +snmpDispatcher = SnmpDispatcher() + +# Submit initial GETBULK request +bulkCmd(snmpDispatcher, + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + 0, 25, + ('1.3.6.1.4.1', None), + **dict(cbFun=cbFun)) + +snmpDispatcher.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/v1arch/asyncore/manager/cmdgen/v1-getnext.py b/examples/hlapi/v1arch/asyncore/manager/cmdgen/v1-getnext.py new file mode 100644 index 00000000..385e869c --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/manager/cmdgen/v1-getnext.py @@ -0,0 +1,48 @@ +""" +SNMP GETNEXT over SNMPv1 +++++++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests using the following options: + + * with SNMPv1, community 'public' + * over IPv4/UDP + * to an Agent at demo.snmplabs.com:161 + * for the 1.3.6.1.2.1.1 OID (e.g. SNMPv2-MIB::system MIB branch) + +Functionally similar to: + +| $ snmpwalk -v1 -c public demo.snmplabs.com 1.3.6.1.2.1.1 + +"""# + +from pysnmp.hlapi.v1arch.asyncore import * + + +def cbFun(errorIndication, errorStatus, errorIndex, varBindTable, **context): + if errorIndication: + print(errorIndication) + return + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?')) + return + + else: + for varBindRow in varBindTable: + for varBind in varBindRow: + print(' = '.join([x.prettyPrint() for x in varBind])) + + return context.get('nextVarBinds') + +snmpDispatcher = SnmpDispatcher() + +stateHandle = nextCmd( + snmpDispatcher, + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ('1.3.6.1.5.1.1', None), + cbFun=cbFun +) + +snmpDispatcher.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/v1arch/asyncore/manager/cmdgen/v2c-get.py b/examples/hlapi/v1arch/asyncore/manager/cmdgen/v2c-get.py new file mode 100644 index 00000000..9ce8d7dd --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/manager/cmdgen/v2c-get.py @@ -0,0 +1,44 @@ +""" +SNMP GET over SNMPv2c ++++++++++++++++++++++ + +Send SNMP GET request using the following options: + + * with SNMPv2c, community 'public' + * over IPv4/UDP + * to an Agent at demo.snmplabs.com:161 + * for the 1.3.6.1.2.1.1.1.0 OID (e.g. SNMPv2-MIB::sysDescr.0 MIB object) + +Functionally similar to: + +| $ snmpget -v2c -c public demo.snmplabs.com 1.3.6.1.2.1.1.1.0 + +"""# + +from pysnmp.hlapi.v1arch.asyncore import * + + +def cbFun(errorIndication, errorStatus, errorIndex, varBinds, **context): + if errorIndication: + print(errorIndication) + return + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?')) + return + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) + + +snmpDispatcher = SnmpDispatcher() + +stateHandle = getCmd( + snmpDispatcher, + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ('1.3.6.1.2.1.1.1.0', None), + cbFun=cbFun +) + +snmpDispatcher.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py new file mode 100644 index 00000000..2f1fa0fd --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py @@ -0,0 +1,46 @@ +""" +Generic SNMPv1 TRAP ++++++++++++++++++++ + +Send SNMPv1 TRAP using the following options: + +* SNMPv1 +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with Uptime 12345 +* with Generic Trap #1 (warmStart) and Specific Trap 0 +* with Agent Address 127.0.0.1 +* with Enterprise OID 1.3.6.1.4.1.20408.4.1.1.2 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v1 -c public demo.snmplabs.com 1.3.6.1.4.1.20408.4.1.1.2 0.0.0.0 1 0 0 1.3.6.1.2.1.1.1.0 s "my system" + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification( + SnmpDispatcher(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 162)), + 'trap', + # SNMPv2-MIB::sysUpTime.0 = 12345 + ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)), + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart + ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')), + # SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = 127.0.0.1 + ('1.3.6.1.6.3.18.1.3.0', IpAddress('127.0.0.1')), + # SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = public + ('1.3.6.1.6.3.18.1.4.0', OctetString('public')), + # SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = 1.3.6.1.4.1.20408.4.1.1.2 + ('1.3.6.1.6.3.1.1.4.3.0', ObjectIdentifier('1.3.6.1.4.1.20408.4.1.1.2')), + # SNMPv2-MIB::sysName.0 + ('1.3.6.1.2.1.1.1.0', OctetString('my system')) + ) +) + +if errorIndication: + print(errorIndication) diff --git a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py new file mode 100644 index 00000000..10a04ed4 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py @@ -0,0 +1,38 @@ +""" +Generic SNMPv2c TRAP +++++++++++++++++++++ + +Send SNMPv1 TRAP using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with Uptime 12345 +* with Generic Trap #1 (warmStart) and Specific Trap 0 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v2c -c public demo.snmplabs.com 12345 1.3.6.1.6.3.1.1.5.2 1.3.6.1.2.1.1.1.0 s "my system" + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification( + SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + 'trap', + # SNMPv2-MIB::sysUpTime.0 = 12345 + ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)), + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart + ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')), + # SNMPv2-MIB::sysName.0 + ('1.3.6.1.2.1.1.1.0', OctetString('my system')) + ) +) + +if errorIndication: + print(errorIndication) diff --git a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py new file mode 100644 index 00000000..c1799993 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py @@ -0,0 +1,45 @@ +""" +SNMPv2c INFORM +++++++++++++++ + +Send SNMP INFORM notification using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send INFORM notification +* with TRAP ID 'warmStart' specified as a string OID +* include managed object information 1.3.6.1.2.1.1.5.0 = 'system name' + +Functionally similar to: + +| $ snmpinform -v2c -c public demo.snmplabs.com 12345 1.3.6.1.4.1.20408.4.1.1.2 1.3.6.1.2.1.1.1.0 s "my system" + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification( + SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + 'inform', + # SNMPv2-MIB::sysUpTime.0 = 12345 + ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)), + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart + ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')), + # SNMPv2-MIB::sysName.0 + ('1.3.6.1.2.1.1.1.0', OctetString('my system')) + ) +) + +if errorIndication: + print(errorIndication) + +elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + +else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py new file mode 100644 index 00000000..052946bc --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py @@ -0,0 +1,39 @@ +""" +Generic SNMPv2c TRAP +++++++++++++++++++++ + +Send SNMPv1 TRAP using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with Uptime 12345 +* with Generic Trap #1 (warmStart) and Specific Trap 0 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v2c -c public demo.snmplabs.com 12345 1.3.6.1.6.3.1.1.5.2 1.3.6.1.2.1.1.1.0 s "my system" + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification( + SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + 'trap', + # SNMPv2-MIB::sysUpTime.0 = 12345 + ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)), + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart + NotificationType(ObjectIdentity('SNMPv2-MIB', 'warmStart')), + # SNMPv2-MIB::sysName.0 + ('1.3.6.1.2.1.1.1.0', OctetString('my system')), + lookupMib=True + ) +) + +if errorIndication: + print(errorIndication) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py new file mode 100644 index 00000000..a6789f7f --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py @@ -0,0 +1,38 @@ +""" +Coerce value to SET to MIB spec ++++++++++++++++++++++++++++++++ + +Send SNMP SET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* with MIB lookup enabled +* setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB) + +Functionally similar to: + +| $ snmpset -v2c -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 = "new system name" + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + setCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), + 'new description'), + lookupMib=True) +) + +if errorIndication: + print(errorIndication) + +elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + +else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py new file mode 100644 index 00000000..759171c1 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py @@ -0,0 +1,40 @@ +""" +Custom ASN.1 MIB path ++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for IF-MIB::ifInOctets.1 MIB object +* pass non-default ASN.1 MIB source to MIB compiler +* with MIB lookup enabled + +Functionally similar to: + +| $ snmpget -v2c -c public -M /usr/share/snmp demo.snmplabs.com IF-MIB::ifInOctets.1 + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource( + 'file:///usr/share/snmp', + 'http://mibs.snmplabs.com/asn1/@mib@')), + lookupMib=True) +) + +if errorIndication: + print(errorIndication) + +elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + +else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py new file mode 100644 index 00000000..a3686d69 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py @@ -0,0 +1,49 @@ +""" +Custom PySNMP MIBs location ++++++++++++++++++++++++++++ + +Send a series of SNMP GETBULK requests using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for all OIDs within TCP-MIB::tcpConnTable column +* TCP-MIB Python module will be searched by a user-specified filesystem + path (/opt/mib/pysnmp) and in Python package (python_packaged_mibs) + which should be in sys.path +* with MIB lookup enabled + +Functionally similar to: + +| $ snmpbulkwalk -v2c -c public -Cn0 -Cr50 demo.snmplabs.com TCP-MIB::tcpConnTable + +"""# +from pysnmp.hlapi.v1arch import * + +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in bulkCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + 0, 50, + ObjectType( + ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource( + '/opt/mibs/pysnmp').addMibSource( + 'python_packaged_mibs') + ), + lookupMib=True, + lexicographicMode=False): + + if errorIndication: + print(errorIndication) + break + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + break + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py new file mode 100644 index 00000000..7a4253cf --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py @@ -0,0 +1,51 @@ +""" +Custom request timeout +++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for an OID in string form +* use custom timeout and request retries values + +Transport timing settings (maximum number of request retries and +individual request timeout in seconds) can be set on a per-target basis +as explained by the code that follows. + +Keep in mind that while timeout value can be specified in fractions of a +second, default pysnmp timer resolution is quite low (about 0.5 sec) +so there's no much point in using timeouts which is not a multiple of 0.5 +Internal timer can be programmatically adjusted to finer resolution if needed. + +If retries value is set to 0, pysnmp will issue a single request. Even +if no response arrives, there will be no retry. Likewise, retries=1 +means one initial request plus one retry. + +Functionally similar to: + +| $ snmpget -v1 -c public -t 2 -r 0 demo.snmplabs.com 1.3.6.1.2.1.1.1.0 + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget( + ('demo.snmplabs.com', 161), timeout=2.0, retries=0 + ), + (('1.3.6.1.2.1.1.1.0', None))) +) + +if errorIndication: + print(errorIndication) + +elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + +else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py new file mode 100644 index 00000000..2f4f8edb --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py @@ -0,0 +1,43 @@ +""" +Enable MIB lookup ++++++++++++++++++ + +Perform SNMP GETNEXT operation with the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for an OID in string form +* resolve request and response OIDs and values from/to human-friendly form + +The `lookupMib=True` keyword argument makes pysnmp resolving +request and response variable-bindings from/to human-friendly form. + +Functionally similar to: + +| $ snmpwalk -v2c -c public -ObentU demo.snmplabs.com 1.3.6.1.2.1 + +"""# +from pysnmp.hlapi.v1arch import * + +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in nextCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1')), + lookupMib=True): + + if errorIndication: + print(errorIndication) + break + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + break + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py new file mode 100644 index 00000000..bd8d9ca2 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py @@ -0,0 +1,36 @@ +""" +GET over IPv6 ++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv6/UDP +* to an Agent at [::1]:161 +* for three OIDs in string form + +Functionally similar to: + +| $ snmpget -v2c -c public udp6:[::1]:161 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.2.0 1.3.6.1.2.1.1.3.0 +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpDispatcher(), + CommunityData('public'), + Udp6TransportTarget(('::1', 161)), + ('1.3.6.1.2.1.1.1.0', None), + ('1.3.6.1.2.1.1.2.0', None), + ('1.3.6.1.2.1.1.3.0', None)) +) + +if errorIndication: + print(errorIndication) + +elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + +else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py new file mode 100644 index 00000000..b7fccdcb --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py @@ -0,0 +1,38 @@ +""" +GET table row ++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv2c, community name "public" +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* with MIB lookup enabled +* for IF-MIB::ifInOctets.1 and IF-MIB::ifOutOctets.1 MIB object + +Functionally similar to: + +| $ snmpget -v 2c -c public demo.snmplabs.com IF-MIB::ifInOctets.1 IF-MIB::ifOutOctets.1 + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)), + ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1)), + lookupMib=True) +) + +if errorIndication: + print(errorIndication) + +elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + +else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py new file mode 100644 index 00000000..cec5ad25 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py @@ -0,0 +1,40 @@ +""" +Fetch table row by composite index +++++++++++++++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 MIB object +* with MIB lookup enabled + +Functionally similar to: + +| $ snmpget -v2c -c public demo.snmplabs.com TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('TCP-MIB', + 'tcpConnLocalAddress', + '0.0.0.0', 22, + '0.0.0.0', 0)), + lookupMib=True) +) + +if errorIndication: + print(errorIndication) + +elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + +else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py new file mode 100644 index 00000000..49257a1c --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py @@ -0,0 +1,45 @@ +""" +Fetch scalar and table variables +++++++++++++++++++++++++++++++++ + +Send a series of SNMP GETBULK requests using the following options: + +* with SNMPv2c, community name "public" +* over IPv6/UDP +* to an Agent at demo.snmplabs.com:161 +* with MIB lookup enabled +* with values non-repeaters = 1, max-repetitions = 25 +* for IP-MIB::ipAdEntAddr and all columns of the IF-MIB::ifEntry table +* stop when response OIDs leave the scopes of the table + +Functionally similar to: + +| $ snmpbulkwalk -v2c -c public -Cn1, -Cr25 demo.snmplabs.com IP-MIB::ipAdEntAddr IP-MIB::ipAddrEntry + +"""# +from pysnmp.hlapi.v1arch import * + +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in bulkCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + 1, 25, + ObjectType(ObjectIdentity('IP-MIB', 'ipAdEntAddr')), + ObjectType(ObjectIdentity('IP-MIB', 'ipAddrEntry')), + lookupMib=True, + lexicographicMode=False): + + if errorIndication: + print(errorIndication) + break + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + break + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py new file mode 100644 index 00000000..22d52589 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py @@ -0,0 +1,44 @@ +""" +Walk Agent, limit number of packets ++++++++++++++++++++++++++++++++++++ + +Send a series of SNMP GETBULK requests using the following options: + +* with SNMPv2c, community name "public" +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for all OIDs past SNMPv2-MIB::system +* with MIB lookup enabled +* run till end-of-mib condition is reported by Agent OR + maxCalls == 10 request-response interactions occur + +Functionally similar to: + +| $ snmpbulkwalk -v2c -c public -Cn0 -Cr50 demo.snmplabs.com SNMPv2-MIB::system + +"""# +from pysnmp.hlapi.v1arch import * + +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in bulkCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + 0, 50, + ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')), + lookupMib=True, + maxCalls=10): + + if errorIndication: + print(errorIndication) + break + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + break + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py new file mode 100644 index 00000000..57a1132b --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py @@ -0,0 +1,48 @@ +""" +Sequence Of GET's ++++++++++++++++++ + +Send two SNMP GET requests in a row using the following options: + +* with SNMPv2c, community name "public" +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for IF-MIB::ifInOctets.1 and IF-MIB::ifOutOctets.1 MIB objects +* with MIB lookup enabled + +Use a queue of MIB objects to query. + +The next() call is used to forward Python iterator to the position where it +could consume input + +Functionally similar to: + +| $ snmpget -v2c -c public demo.snmplabs.com IF-MIB::ifInOctets.1 + +"""# +from pysnmp.hlapi.v1arch import * + +queue = [ + [ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))], + [ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1))] +] + +iterator = getCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + lookupMib=True) + +next(iterator) + +while queue: + errorIndication, errorStatus, errorIndex, varBinds = iterator.send(queue.pop()) + if errorIndication: + print(errorIndication) + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py new file mode 100644 index 00000000..39d1e7dd --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py @@ -0,0 +1,41 @@ +""" +Preload PySNMP MIBs ++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests using the following options: + +* with SNMPv2c, community name "public" +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for all OIDs starting from 1.3.6 +* with MIB lookup enabled +* preload all Python MIB modules found in search path + +Functionally similar to: + +| $ snmpwalk -v2c -c public -m ALL demo.snmplabs.com:161 1.3.6 + +"""# +from pysnmp.hlapi.v1arch import * + +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in nextCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('1.3.6').loadMibs()), + lookupMib=True): + + if errorIndication: + print(errorIndication) + break + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + break + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py new file mode 100644 index 00000000..69e943d9 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py @@ -0,0 +1,39 @@ +""" +Walk whole MIB +++++++++++++++ + +Send a series of SNMP GETNEXT requests using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for all OIDs in IF-MIB +* with MIB lookup enabled + +Functionally similar to: + +| $ snmpwalk -v2c -c public demo.snmplabs.com IF-MIB:: + +"""# +from pysnmp.hlapi.v1arch import * + +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in nextCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('IF-MIB'))): + + if errorIndication: + print(errorIndication) + break + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + break + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py new file mode 100644 index 00000000..8d81b1e5 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py @@ -0,0 +1,47 @@ +""" +Fetch whole SNMP table +++++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests using the following options: + +* with SNMPv1, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for some columns of the IF-MIB::ifEntry table +* with MIB lookup enabled +* stop when response OIDs leave the scopes of initial OIDs + +Functionally similar to: + +| $ snmpwalk -v1 -c public demo.snmplabs.com IF-MIB::ifDescr IF-MIB::ifType IF-MIB::ifMtu IF-MIB::ifSpeed IF-MIB::ifPhysAddress IF-MIB::ifType + +"""# +from pysnmp.hlapi.v1arch import * + +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in nextCmd(SnmpDispatcher(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('IF-MIB', 'ifDescr')), + ObjectType(ObjectIdentity('IF-MIB', 'ifType')), + ObjectType(ObjectIdentity('IF-MIB', 'ifMtu')), + ObjectType(ObjectIdentity('IF-MIB', 'ifSpeed')), + ObjectType(ObjectIdentity('IF-MIB', 'ifPhysAddress')), + ObjectType(ObjectIdentity('IF-MIB', 'ifType')), + lookupMib=True, + lexicographicMode=False): + + if errorIndication: + print(errorIndication) + break + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?')) + break + + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py new file mode 100644 index 00000000..29ec78b6 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py @@ -0,0 +1,130 @@ +""" +Query Agents from multiple threads +++++++++++++++++++++++++++++++++++ + +Send a bunch of SNMP GET requests simultaneously using the following options: + +* process 4 GET requests in 3 parallel threads +* with SNMPv1, community 'public' and + with SNMPv2c, community 'public' and +* over IPv4/UDP and + over IPv6/UDP +* to an Agent at demo.snmplabs.com:161 and + to an Agent at demo.snmplabs.com:1161 and + to an Agent at [::1]:161 +* for instances of SNMPv2-MIB::sysDescr.0 and + SNMPv2-MIB::sysLocation.0 MIB objects +* with MIB lookup enabled + +Functionally similar to: + +| $ snmpget -v1 -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 SNMPv2-MIB::sysLocation.0 +| $ snmpget -v2c -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 SNMPv2-MIB::sysLocation.0 +| $ snmpget -v2c -c public demo.snmplabs.com:1161 SNMPv2-MIB::sysDescr.0 SNMPv2-MIB::sysLocation.0 +| $ snmpget -v2c -c public '[::1]' SNMPv2-MIB::sysDescr.0 SNMPv2-MIB::sysLocation.0 + +"""# +from sys import version_info +from threading import Thread +from pysnmp.hlapi.v1arch import * + +if version_info[0] == 2: + from Queue import Queue +else: + from queue import Queue + +# List of targets in the following format: +# ( ( authData, transportTarget, varNames ), ... ) +targets = ( + # 1-st target (SNMPv1 over IPv4/UDP) + (CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), + # 2-nd target (SNMPv2c over IPv4/UDP) + (CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), + # 3-nd target (SNMPv2c over IPv4/UDP) - same community and + # different transport address. + (CommunityData('public'), + Udp6TransportTarget(('localhost', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))), + # 4-th target (SNMPv2c over IPv4/UDP) - same community and + # different transport port. + (CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 1161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), + # N-th target + # ... +) + + +class Worker(Thread): + def __init__(self, requests, responses): + Thread.__init__(self) + self.snmpDispatcher = SnmpDispatcher() + self.requests = requests + self.responses = responses + self.setDaemon(True) + self.start() + + def run(self): + while True: + authData, transportTarget, varBinds = self.requests.get() + + self.responses.append( + next(getCmd(self.snmpDispatcher, + authData, transportTarget, *varBinds, lookupMib=True)) + ) + + if hasattr(self.requests, 'task_done'): # 2.5+ + self.requests.task_done() + + +class ThreadPool(object): + def __init__(self, num_threads): + self.requests = Queue(num_threads) + self.responses = [] + for _ in range(num_threads): + Worker(self.requests, self.responses) + + def addRequest(self, authData, transportTarget, varBinds): + self.requests.put((authData, transportTarget, varBinds)) + + def getResponses(self): + return self.responses + + def waitCompletion(self): + if hasattr(self.requests, 'join'): + self.requests.join() # 2.5+ + else: + from time import sleep + # this is a lame substitute for missing .join() + # adding an explicit synchronization might be a better solution + while not self.requests.empty(): + sleep(1) + + +pool = ThreadPool(3) + +# Submit GET requests +for authData, transportTarget, varBinds in targets: + pool.addRequest(authData, transportTarget, varBinds) + +# Wait for responses or errors +pool.waitCompletion() + +# Walk through responses +for errorIndication, errorStatus, errorIndex, varBinds in pool.getResponses(): + if errorIndication: + print(errorIndication) + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py new file mode 100644 index 00000000..b5498003 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py @@ -0,0 +1,46 @@ +""" +SET scalars values +++++++++++++++++++ + +Send SNMP SET request using the following options: + +* with SNMPv1, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* with MIB lookup enabled +* setting three var-bindings to new values + +Please note, that in this example MIB lookup is only used +for the second var-bindins. For the rest, value types are +inferred from passed objects. + +Functionally similar to: + +| $ snmpset -v1 -c public demo.snmplabs.com 1.3.6.1.2.1.1.9.1.2.1 o 1.3.6.1.4.1.20408.1.1 1.3.6.1.2.1.1.9.1.2.1 = 1.3.6.1.4.1.20408.1.1 1.3.6.1.2.1.1.9.1.3.1 s "new system name" + +"""# +from pysnmp.hlapi.v1arch import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + setCmd(SnmpDispatcher(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORID', 1), + ObjectIdentifier('1.3.6.1.4.1.20408.1.1')), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'), + '1.3.6.1.4.1.20408.1.1'), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.3.1'), + OctetString('new system name')), + lookupMib=True) +) + +if errorIndication: + print(errorIndication) + +elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + +else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py new file mode 100644 index 00000000..b54802af --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py @@ -0,0 +1,36 @@ +""" +SNMPv1 +++++++ + +Send SNMP GET request using the following options: + + * with SNMPv1, community 'public' + * over IPv4/UDP + * to an Agent at demo.snmplabs.com:161 + * for an instance of SNMPv2-MIB::sysDescr.0 MIB object + * having MIB lookup feature enabled + +Functionally similar to: + +| $ snmpget -v1 -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 + +"""# +from pysnmp.hlapi.v1arch import * + +for response in getCmd(SnmpDispatcher(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + lookupMib=True): + + errorIndication, errorStatus, errorIndex, varBinds = response + + if errorIndication: + print(errorIndication) + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py new file mode 100644 index 00000000..e2ec5815 --- /dev/null +++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py @@ -0,0 +1,35 @@ +""" +SNMPv2c ++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for two var-bindings with OIDs in string form + +Functionally similar to: + +| $ snmpget -v2c -c public demo.snmplabs.com 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.6.0 + +"""# +from pysnmp.hlapi.v1arch import * + +for response in getCmd(SnmpDispatcher(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ('1.3.6.1.2.1.1.1.0', None), + ('1.3.6.1.2.1.1.6.0', None)): + + errorIndication, errorStatus, errorIndex, varBinds = response + + if errorIndication: + print(errorIndication) + + elif errorStatus: + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: + for varBind in varBinds: + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py similarity index 93% rename from examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py rename to examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py index 92d3e70e..6a0fefda 100644 --- a/examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py @@ -21,7 +21,7 @@ Functionally similar to: """# import asyncio -from pysnmp.hlapi.asyncio import * +from pysnmp.hlapi.v3arch.asyncio import * @asyncio.coroutine @@ -35,6 +35,8 @@ def run(): 'trap', NotificationType( ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).loadMibs( + 'SNMPv2-MIB' ).addVarBinds( ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), ('1.3.6.1.2.1.1.1.0', OctetString('my system')) diff --git a/examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py similarity index 95% rename from examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py rename to examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py index 74cedeea..f1cae2b8 100644 --- a/examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py +++ b/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py @@ -24,7 +24,7 @@ Functionally similar to: """# import asyncio -from pysnmp.hlapi.asyncio import * +from pysnmp.hlapi.v3arch.asyncio import * @asyncio.coroutine @@ -40,6 +40,8 @@ def sendone(snmpEngine, hostname, notifyType): notifyType, NotificationType( ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).loadMibs( + 'SNMPv2-MIB' ).addVarBinds( ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), ('1.3.6.1.2.1.1.1.0', OctetString('my system')) diff --git a/examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py similarity index 97% rename from examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py rename to examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py index e453e6b5..c60d6e12 100644 --- a/examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py @@ -18,7 +18,7 @@ Functionally similar to: """# import asyncio -from pysnmp.hlapi.asyncio import * +from pysnmp.hlapi.v3arch.asyncio import * @asyncio.coroutine diff --git a/examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py similarity index 97% rename from examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py rename to examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py index ad9c441b..a1b5d9a0 100644 --- a/examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py @@ -18,7 +18,7 @@ Functionally similar to: """# import asyncio -from pysnmp.hlapi.asyncio import * +from pysnmp.hlapi.v3arch.asyncio import * @asyncio.coroutine diff --git a/examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-queries.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py similarity index 97% rename from examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-queries.py rename to examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py index 4a43bc49..d546870d 100644 --- a/examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-queries.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py @@ -18,7 +18,7 @@ Functionally similar to: """# import asyncio -from pysnmp.hlapi.asyncio import * +from pysnmp.hlapi.v3arch.asyncio import * @asyncio.coroutine diff --git a/examples/hlapi/asyncio/manager/cmdgen/v1-get.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py similarity index 96% rename from examples/hlapi/asyncio/manager/cmdgen/v1-get.py rename to examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py index 6147706d..f14a9f63 100644 --- a/examples/hlapi/asyncio/manager/cmdgen/v1-get.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py @@ -16,7 +16,7 @@ Functionally similar to: """# import asyncio -from pysnmp.hlapi.asyncio import * +from pysnmp.hlapi.v3arch.asyncio import * @asyncio.coroutine diff --git a/examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/asyncore/agent/ntforg/default-v1-trap.py similarity index 92% rename from examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py rename to examples/hlapi/v3arch/asyncore/agent/ntforg/default-v1-trap.py index 3b806d6d..21ac77b3 100644 --- a/examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/v3arch/asyncore/agent/ntforg/default-v1-trap.py @@ -20,7 +20,7 @@ Functionally similar to: | $ snmptrap -v1 -c public demo.snmplabs.com 1.3.6.1.4.1.20408.4.1.1.2 0.0.0.0 1 0 0 1.3.6.1.2.1.1.1.0 s "my system" """# -from pysnmp.hlapi.asyncore import * +from pysnmp.hlapi.v3arch.asyncore import * snmpEngine = SnmpEngine() @@ -35,6 +35,8 @@ sendNotification( ).addVarBinds( ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), ('1.3.6.1.2.1.1.1.0', OctetString('my system')) + ).loadMibs( + 'SNMPv2-MIB' ) ) diff --git a/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py b/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py similarity index 97% rename from examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py rename to examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py index 58c5bfb8..9690c2e4 100644 --- a/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py +++ b/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py @@ -16,7 +16,7 @@ Send multiple SNMP notifications at once using the following options: | $ snmpinform -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com 123 1.3.6.1.6.3.1.1.5.1 """# -from pysnmp.hlapi.asyncore import * +from pysnmp.hlapi.v3arch.asyncore import * # List of targets in the followin format: # ( ( authData, transportTarget ), ... ) diff --git a/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py b/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py similarity index 97% rename from examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py rename to examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py index 7aa63f68..ad873868 100644 --- a/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py +++ b/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py @@ -17,7 +17,7 @@ wait for responses asynchronously: | $ snmptrap -v2c -c public demo.snmplabs.com 123 1.3.6.1.6.3.1.1.5.1 """# -from pysnmp.hlapi.asyncore import * +from pysnmp.hlapi.v3arch.asyncore import * # List of targets in the followin format: # ( ( authData, transportTarget ), ... ) diff --git a/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py b/examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py similarity index 98% rename from examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py rename to examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py index ba65d60a..10a96756 100644 --- a/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py +++ b/examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py @@ -29,7 +29,7 @@ criterias are also possible. | $ snmpinform -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com 123 1.3.6.1.6.3.1.1.5.1 """# -from pysnmp.hlapi.asyncore import * +from pysnmp.hlapi.v3arch.asyncore import * from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher # List of targets in the following format: diff --git a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py similarity index 98% rename from examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py rename to examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py index 2b4b0eb3..c6132711 100644 --- a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py +++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py @@ -16,7 +16,7 @@ wait for responses asynchronously: SNMPv2-MIB::sysLocation.0 MIB objects """# -from pysnmp.hlapi.asyncore import * +from pysnmp.hlapi.v3arch.asyncore import * # List of targets in the followin format: # ( ( authData, transportTarget, varNames ), ... ) diff --git a/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py similarity index 94% rename from examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py rename to examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py index d87d55c5..eef035d1 100644 --- a/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py +++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py @@ -15,10 +15,10 @@ following options: * pull variables till EOM """# -from pysnmp.hlapi.asyncore import * +from pysnmp.hlapi.v3arch.asyncore import * -# List of targets in the followin format: -# ( ( authData, transportTarget, varNames ), ... ) +# List of targets in the following format: +# ((authData, transportTarget, varNames), ...) targets = ( # 1-st target (SNMPv1 over IPv4/UDP) (CommunityData('public', mpModel=0), diff --git a/examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py similarity index 97% rename from examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py rename to examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py index 8d9ff19e..a0aa02b9 100644 --- a/examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py +++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py @@ -15,7 +15,7 @@ Functionally similar to: | demo.snmplabs.com IF-MIB:: """# -from pysnmp.hlapi.asyncore import * +from pysnmp.hlapi.v3arch.asyncore import * # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal diff --git a/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py similarity index 97% rename from examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py rename to examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py index 4a732041..87591b4e 100644 --- a/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py +++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py @@ -3,7 +3,7 @@ Multiple SNMP engines +++++++++++++++++++++ Send multiple SNMP GET requests to multiple peers using multiple -independend SNMP engines. Deal with peers asynchronously. SNMP options +independent SNMP engines. Deal with peers asynchronously. SNMP options are: * with SNMPv1, community 'public' and @@ -28,7 +28,7 @@ employ here is based on peer's UDP port number. Other selection criterias are also possible. """# -from pysnmp.hlapi.asyncore import * +from pysnmp.hlapi.v3arch.asyncore import * from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher # List of targets in the following format: diff --git a/examples/hlapi/asyncore/manager/cmdgen/v2c-get.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py similarity index 96% rename from examples/hlapi/asyncore/manager/cmdgen/v2c-get.py rename to examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py index d752b540..ae8f8262 100644 --- a/examples/hlapi/asyncore/manager/cmdgen/v2c-get.py +++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py @@ -14,7 +14,7 @@ Functionally similar to: | $ snmpget -v2c -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 """# -from pysnmp.hlapi.asyncore import * +from pysnmp.hlapi.v3arch.asyncore import * # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py similarity index 89% rename from examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py rename to examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py index 6c4e7adc..1b9e12d5 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py @@ -28,7 +28,10 @@ errorIndication, errorStatus, errorIndex, varBinds = next( UdpTransportTarget(('demo.snmplabs.com', 162)), ContextData(OctetString(hexValue='8000000004030201')), 'inform', - NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2'))) + NotificationType( + ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).loadMibs('SNMPv2-MIB') + ) ) if errorIndication: diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py similarity index 97% rename from examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py rename to examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py index 729c9b83..96abba48 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py @@ -28,7 +28,7 @@ errorIndication, errorStatus, errorIndex, varBinds = next( UdpTransportTarget(('demo.snmplabs.com', 162)), ContextData(contextName='my-context'), 'inform', - NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2'))) + NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2')).loadMibs('SNMPv2-MIB')) ) if errorIndication: diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py similarity index 95% rename from examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py rename to examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py index 8693f13f..c6d84303 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py @@ -38,6 +38,8 @@ errorIndication, errorStatus, errorIndex, varBinds = next( ('1.3.6.1.6.3.18.1.3.0', '127.0.0.1'), ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), ('1.3.6.1.2.1.1.1.0', OctetString('my system')) + ).loadMibs( + 'SNMPv2-MIB', 'SNMP-COMMUNITY-MIB' ) ) ) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py similarity index 96% rename from examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py rename to examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py index 18cc2c77..552ad877 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py @@ -34,6 +34,8 @@ errorIndication, errorStatus, errorIndex, varBinds = next( ).addVarBinds( ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), ('1.3.6.1.2.1.1.1.0', OctetString('my system')) + ).loadMibs( + 'SNMPv2-MIB' ) ) ) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py similarity index 100% rename from examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py rename to examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py similarity index 100% rename from examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py rename to examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py similarity index 96% rename from examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py rename to examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py index 46153978..6f02024f 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py @@ -29,6 +29,8 @@ errorIndication, errorStatus, errorIndex, varBinds = next( ObjectIdentity('1.3.6.1.6.3.1.1.5.2') ).addVarBinds( ObjectType(ObjectIdentity('1.3.6.1.2.1.1.5.0'), 'system name') + ).loadMibs( + 'SNMPv2-MIB' ) ) ) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py similarity index 100% rename from examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py rename to examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py similarity index 77% rename from examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py index c08b9f47..d883d16a 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py @@ -8,6 +8,7 @@ Send two SNMP GET requests in a row using the following options: * over IPv4/UDP * to an Agent at demo.snmplabs.com:161 * for IF-MIB::ifInOctets.1 and IF-MIB::ifOutOctets.1 MIB objects +* with MIB lookup enabled Use a queue of MIB objects to query. @@ -24,15 +25,15 @@ from pysnmp.hlapi import * queue = [[ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))], [ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1))]] -iter = getCmd(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData()) +iterator = getCmd(SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData()) -next(iter) +next(iterator) while queue: - errorIndication, errorStatus, errorIndex, varBinds = iter.send(queue.pop()) + errorIndication, errorStatus, errorIndex, varBinds = iterator.send(queue.pop()) if errorIndication: print(errorIndication) elif errorStatus: diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py similarity index 95% rename from examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py index b5fc1912..be4ffeab 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py @@ -25,7 +25,7 @@ errorIndication, errorStatus, errorIndex, varBinds = next( CommunityData('public', mpModel=0), UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORID', 1), ObjectIdentifier('1.3.6.1.4.1.20408.1.1')), ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'), '1.3.6.1.4.1.20408.1.1'), diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py similarity index 100% rename from examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py similarity index 83% rename from examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py rename to examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py index 17194552..f44d160b 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py @@ -8,11 +8,10 @@ Perform SNMP GETNEXT operation with the following options: * over IPv4/UDP * to an Agent at demo.snmplabs.com:161 * for an OID in string form -* do not resolve response OIDs and values into human-freidly form +* do not resolve request/response OIDs and values from/toto human-friendly form -False lookupMib keyword arguments could make pysnmp waiving -OIDs and values resolution in response variable-bindings, into human -friendly form. +The `lookupMib=False` keyword argument makes pysnmp NOT resolving +request and response variable-bindings from/to human-friendly form. Functionally similar to: diff --git a/examples/hlapi/trollius/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py similarity index 94% rename from examples/hlapi/trollius/agent/ntforg/default-v1-trap.py rename to examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py index 514cff2f..64e61b1d 100644 --- a/examples/hlapi/trollius/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py @@ -22,7 +22,7 @@ Functionally similar to: """# import trollius -from pysnmp.hlapi.asyncio import * +from pysnmp.hlapi.v3arch.asyncio import * @trollius.coroutine @@ -40,6 +40,8 @@ def run(): 'inform', NotificationType( ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).loadMibs( + 'SNMPv2-MIB' ).addVarBinds( ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), ('1.3.6.1.2.1.1.1.0', OctetString('my system')) diff --git a/examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py similarity index 97% rename from examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py rename to examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py index b380b283..f084e398 100644 --- a/examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py +++ b/examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py @@ -17,7 +17,7 @@ Functionally similar to: """# import trollius -from pysnmp.hlapi.asyncio import * +from pysnmp.hlapi.v3arch.asyncio import * @trollius.coroutine diff --git a/examples/hlapi/trollius/manager/cmdgen/v1-get.py b/examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py similarity index 96% rename from examples/hlapi/trollius/manager/cmdgen/v1-get.py rename to examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py index d7406963..771e48c6 100644 --- a/examples/hlapi/trollius/manager/cmdgen/v1-get.py +++ b/examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py @@ -16,7 +16,7 @@ Functionally similar to: """# import trollius -from pysnmp.hlapi.asyncio import * +from pysnmp.hlapi.v3arch.asyncio import * @trollius.coroutine diff --git a/examples/hlapi/twisted/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py similarity index 95% rename from examples/hlapi/twisted/agent/ntforg/default-v1-trap.py rename to examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py index 4d1a2700..756ce58d 100644 --- a/examples/hlapi/twisted/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py @@ -21,7 +21,7 @@ Functionally similar to: """# from twisted.internet.task import react -from pysnmp.hlapi.twisted import * +from pysnmp.hlapi.v3arch.twisted import * def success(args, hostname): @@ -53,6 +53,8 @@ def run(reactor, hostname): 'trap', NotificationType( ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).loadMibs( + 'SNMPv2-MIB' ).addVarBinds( ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), ('1.3.6.1.2.1.1.1.0', OctetString('my system')) diff --git a/examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py similarity index 96% rename from examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py rename to examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py index e9d199e9..c234a827 100644 --- a/examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py +++ b/examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py @@ -24,7 +24,7 @@ Functionally similar to: """# from twisted.internet.defer import DeferredList from twisted.internet.task import react -from pysnmp.hlapi.twisted import * +from pysnmp.hlapi.v3arch.twisted import * def success(args, hostname): @@ -53,6 +53,8 @@ def sendone(reactor, snmpEngine, hostname, notifyType): notifyType, NotificationType( ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).loadMibs( + 'SNMPv2-MIB' ).addVarBinds( ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), ('1.3.6.1.2.1.1.1.0', OctetString('my system')) diff --git a/examples/hlapi/twisted/agent/ntforg/v2c-trap-inline-callbacks.py b/examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py similarity index 93% rename from examples/hlapi/twisted/agent/ntforg/v2c-trap-inline-callbacks.py rename to examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py index e326108c..39b15c57 100644 --- a/examples/hlapi/twisted/agent/ntforg/v2c-trap-inline-callbacks.py +++ b/examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py @@ -18,7 +18,7 @@ Functionally similar to: """# from twisted.internet.task import react, defer -from pysnmp.hlapi.twisted import * +from pysnmp.hlapi.v3arch.twisted import * @defer.inlineCallbacks @@ -32,6 +32,8 @@ def sendtrap(reactor, snmpEngine, hostname): 'trap', NotificationType( ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).loadMibs( + 'SNMPv2-MIB' ).addVarBinds( ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'), OctetString('Hello from Twisted')) ) diff --git a/examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py similarity index 97% rename from examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py rename to examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py index a1ff7850..9c8c6eb9 100644 --- a/examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py +++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py @@ -16,7 +16,7 @@ Functionally similar to: """# from twisted.internet.task import react -from pysnmp.hlapi.twisted import * +from pysnmp.hlapi.v3arch.twisted import * def success(args, hostname): diff --git a/examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py similarity index 97% rename from examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py rename to examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py index d3675451..89542793 100644 --- a/examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py +++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py @@ -17,7 +17,7 @@ Functionally similar to: """# from twisted.internet.task import react -from pysnmp.hlapi.twisted import * +from pysnmp.hlapi.v3arch.twisted import * def success(args, reactor, snmpEngine): diff --git a/examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py similarity index 97% rename from examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py rename to examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py index 07fb08ea..90561015 100644 --- a/examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py +++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py @@ -19,7 +19,7 @@ Functionally similar to: """# from twisted.internet.defer import DeferredList from twisted.internet.task import react -from pysnmp.hlapi.twisted import * +from pysnmp.hlapi.v3arch.twisted import * def success(args, hostname): diff --git a/examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py similarity index 97% rename from examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py rename to examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py index 41d779e6..2e501262 100644 --- a/examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py +++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py @@ -17,7 +17,7 @@ Functionally similar to: """# from twisted.internet.defer import DeferredList from twisted.internet.task import react -from pysnmp.hlapi.twisted import * +from pysnmp.hlapi.v3arch.twisted import * def success(args, reactor, snmpEngine, hostname): diff --git a/examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py similarity index 97% rename from examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py rename to examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py index b2b245e6..9e3f1791 100644 --- a/examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py +++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py @@ -16,7 +16,7 @@ Functionally similar to: """# from twisted.internet.task import react -from pysnmp.hlapi.twisted import * +from pysnmp.hlapi.v3arch.twisted import * def success(args, reactor, snmpEngine): diff --git a/examples/hlapi/twisted/manager/cmdgen/v1-get.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py similarity index 96% rename from examples/hlapi/twisted/manager/cmdgen/v1-get.py rename to examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py index 21719ff7..e483354d 100644 --- a/examples/hlapi/twisted/manager/cmdgen/v1-get.py +++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py @@ -16,7 +16,7 @@ Functionally similar to: """# from twisted.internet.task import react -from pysnmp.hlapi.twisted import * +from pysnmp.hlapi.v3arch.twisted import * def success(args, hostname): diff --git a/examples/v1arch/asyncore/agent/ntforg/send-inform-over-ipv4-and-ipv6.py b/examples/v1arch/asyncore/agent/ntforg/send-inform-over-ipv4-and-ipv6.py index 69d9b43b..43d37e5f 100644 --- a/examples/v1arch/asyncore/agent/ntforg/send-inform-over-ipv4-and-ipv6.py +++ b/examples/v1arch/asyncore/agent/ntforg/send-inform-over-ipv4-and-ipv6.py @@ -41,7 +41,6 @@ def cbTimerFun(timeNow): raise Exception("Request timed out") -# noinspection PyUnusedLocal,PyUnusedLocal def cbRecvFun(transportDispatcher, transportDomain, transportAddress, wholeMsg, reqPDU=reqPDU): while wholeMsg: diff --git a/pysnmp/entity/rfc3413/cmdgen.py b/pysnmp/entity/rfc3413/cmdgen.py index 90180c67..9f5d891d 100644 --- a/pysnmp/entity/rfc3413/cmdgen.py +++ b/pysnmp/entity/rfc3413/cmdgen.py @@ -18,28 +18,6 @@ getNextHandle = nextid.Integer(0x7fffffff) __null = univ.Null('') -def getNextVarBinds(varBinds, origVarBinds=None): - errorIndication = None - idx = nonNulls = len(varBinds) - rspVarBinds = [] - while idx: - idx -= 1 - if varBinds[idx][1].tagSet in (rfc1905.NoSuchObject.tagSet, - rfc1905.NoSuchInstance.tagSet, - rfc1905.EndOfMibView.tagSet): - nonNulls -= 1 - elif origVarBinds is not None: - if v2c.ObjectIdentifier(origVarBinds[idx][0]).asTuple() >= varBinds[idx][0].asTuple(): - errorIndication = errind.oidNotIncreasing - - rspVarBinds.insert(0, (varBinds[idx][0], __null)) - - if not nonNulls: - rspVarBinds = [] - - return errorIndication, rspVarBinds - - class CommandGenerator(object): _null = univ.Null('') @@ -289,9 +267,7 @@ class NextCommandGenerator(NextCommandGeneratorSingleRun): elif not varBindTable: errorIndication, varBinds = errind.emptyResponse, () else: - errorIndication, varBinds = getNextVarBinds( - varBindTable[-1], v2c.apiPDU.getVarBinds(reqPDU) - ) + errorIndication, varBinds = v2c.apiPDU.getNextVarBinds(varBindTable[-1]) if not cbFun(snmpEngine, sendRequestHandle, errorIndication, v2c.apiPDU.getErrorStatus(PDU), @@ -371,9 +347,7 @@ class BulkCommandGenerator(BulkCommandGeneratorSingleRun): elif not varBindTable: errorIndication, varBinds = errind.emptyResponse, () else: - errorIndication, varBinds = getNextVarBinds( - varBindTable[-1], v2c.apiPDU.getVarBinds(reqPDU) - ) + errorIndication, varBinds = v2c.apiBulkPDU.getNextVarBinds(varBindTable[-1]) nonRepeaters = v2c.apiBulkPDU.getNonRepeaters(reqPDU) if nonRepeaters: varBinds = v2c.apiBulkPDU.getVarBinds(reqPDU)[:int(nonRepeaters)] + varBinds[int(nonRepeaters):] diff --git a/pysnmp/hlapi/__init__.py b/pysnmp/hlapi/__init__.py index f60b0ed4..da9788e3 100644 --- a/pysnmp/hlapi/__init__.py +++ b/pysnmp/hlapi/__init__.py @@ -4,12 +4,6 @@ # Copyright (c) 2005-2018, Ilya Etingof # License: http://snmplabs.com/pysnmp/license.html # -from pysnmp.proto.rfc1902 import * -from pysnmp.proto.rfc1905 import NoSuchInstance, NoSuchObject, EndOfMibView -from pysnmp.smi.rfc1902 import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.entity.engine import * # default is synchronous asyncore-based API -from pysnmp.hlapi.asyncore.sync import * +from pysnmp.hlapi.v3arch import * diff --git a/pysnmp/hlapi/asyncore/sync/__init__.py b/pysnmp/hlapi/asyncore/sync/__init__.py deleted file mode 100644 index f412713a..00000000 --- a/pysnmp/hlapi/asyncore/sync/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -# This file is part of pysnmp software. -# -# Copyright (c) 2005-2018, Ilya Etingof -# License: http://snmplabs.com/pysnmp/license.html -# -from pysnmp.proto.rfc1902 import * -from pysnmp.smi.rfc1902 import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.asyncore.transport import * -from pysnmp.entity.engine import * - -try: - from pysnmp.hlapi.asyncore.sync.cmdgen import * - from pysnmp.hlapi.asyncore.sync.ntforg import * -except SyntaxError: - from pysnmp.hlapi.asyncore.sync.compat.cmdgen import * - from pysnmp.hlapi.asyncore.sync.compat.ntforg import * diff --git a/pysnmp/hlapi/twisted/__init__.py b/pysnmp/hlapi/twisted/__init__.py deleted file mode 100644 index 4e3e129f..00000000 --- a/pysnmp/hlapi/twisted/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from pysnmp.proto.rfc1902 import * -from pysnmp.smi.rfc1902 import * -from pysnmp.entity.engine import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.twisted.transport import * -from pysnmp.hlapi.twisted.cmdgen import * -from pysnmp.hlapi.twisted.ntforg import * diff --git a/pysnmp/hlapi/v1arch/__init__.py b/pysnmp/hlapi/v1arch/__init__.py new file mode 100644 index 00000000..22290a8f --- /dev/null +++ b/pysnmp/hlapi/v1arch/__init__.py @@ -0,0 +1,14 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from pysnmp.proto.rfc1902 import * +from pysnmp.proto.rfc1905 import NoSuchInstance, NoSuchObject, EndOfMibView +from pysnmp.smi.rfc1902 import * +from pysnmp.hlapi.v1arch.auth import * +from pysnmp.hlapi.v1arch.asyncore.dispatch import * + +# default is synchronous asyncore-based API +from pysnmp.hlapi.v1arch.asyncore.sync import * diff --git a/pysnmp/hlapi/v1arch/asyncore/__init__.py b/pysnmp/hlapi/v1arch/asyncore/__init__.py new file mode 100644 index 00000000..d58bee7b --- /dev/null +++ b/pysnmp/hlapi/v1arch/asyncore/__init__.py @@ -0,0 +1,13 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from pysnmp.proto.rfc1902 import * +from pysnmp.smi.rfc1902 import * +from pysnmp.hlapi.v1arch.auth import * +from pysnmp.hlapi.v1arch.asyncore.transport import * +from pysnmp.hlapi.v1arch.asyncore.cmdgen import * +from pysnmp.hlapi.v1arch.asyncore.ntforg import * +from pysnmp.hlapi.v1arch.asyncore.dispatch import * diff --git a/pysnmp/hlapi/v1arch/asyncore/cmdgen.py b/pysnmp/hlapi/v1arch/asyncore/cmdgen.py new file mode 100644 index 00000000..ddce3b7e --- /dev/null +++ b/pysnmp/hlapi/v1arch/asyncore/cmdgen.py @@ -0,0 +1,627 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# + +from pysnmp.hlapi.varbinds import * +from pysnmp.hlapi.v1arch.auth import * +from pysnmp.hlapi.v1arch.asyncore import * +from pysnmp.smi.rfc1902 import * +from pysnmp.proto import api +from pysnmp import error + +__all__ = ['getCmd', 'nextCmd', 'setCmd', 'bulkCmd'] + +vbProcessor = CommandGeneratorVarBinds() + + +def getCmd(snmpDispatcher, authData, transportTarget, *varBinds, **options): + """Initiate SNMP GET query over SNMPv1/v2c. + + Based on passed parameters, prepares SNMP GET packet + (:RFC:`1905#section-4.2.1`) and schedules its transmission by + I/O framework at a later point of time. + + Parameters + ---------- + snmpDispatcher: :py:class:`~pysnmp.hlapi.v1arch.asyncore.SnmpDispatcher` + Class instance representing asyncore-based asynchronous event loop and + associated state information. + + authData: :py:class:`~pysnmp.hlapi.v1arch.CommunityData` + Class instance representing SNMPv1/v2c credentials. + + transportTarget: :py:class:`~pysnmp.hlapi.v1arch.asyncore.UdpTransportTarget` or + :py:class:`~pysnmp.hlapi.v1arch.asyncore.Udp6TransportTarget` Class instance representing + transport type along with SNMP peer address. + + \*varBinds: :class:`tuple` of OID-value pairs or :py:class:`~pysnmp.smi.rfc1902.ObjectType` + One or more class instances representing MIB variables to place + into SNMP request. + + Other Parameters + ---------------- + \*\*options : + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `False`. + * `cbFun` (callable) - user-supplied callable that is invoked + to pass SNMP response data or error to user at a later point + of time. Default is `None`. + * `cbCtx` (object) - user-supplied object passing additional + parameters to/from `cbFun`. Default is `None`. + + Note + ---- + The `SnmpDispatcher` object may be expensive to create, therefore it is + advised to maintain it for the lifecycle of the application/thread for + as long as possible. + + Note + ---- + User-supplied `cbFun` callable must have the following call + signature: + + * snmpDispatcher: :py:class:`~pysnmp.hlapi.v1arch.asyncore.SnmpDispatcher` + Class instance representing asyncore-based asynchronous event loop and + associated state information. + * stateHandle (int): Unique request identifier. Can be used + for matching multiple ongoing requests with received responses. + * errorIndication (str): evaluates to `True` to indicate SNMP dispatcher + error. + * errorStatus (int): evaluates to `True` to indicate SNMP PDU error. + * errorIndex (int): Non-zero value refers to `varBinds[errorIndex-1]` + * varBinds (tuple): A sequence of + :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + representing MIB variables returned in SNMP response in exactly + the same order as `varBinds` in request. + * `cbCtx` (object): Original user-supplied object. + + Returns + ------- + stateHandle: int + Unique request identifier. Can be used for matching received + responses with ongoing requests. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Examples + -------- + >>> from pysnmp.hlapi.v1arch.asyncore import * + >>> + >>> def cbFun(snmpDispatcher, stateHandle, errorIndication, + >>> errorStatus, errorIndex, varBinds, cbCtx): + >>> print(errorIndication, errorStatus, errorIndex, varBinds) + >>> + >>> snmpDispatcher = SnmpDispatcher() + >>> + >>> stateHandle = getCmd( + >>> snmpDispatcher, + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 161)), + >>> ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + >>> cbFun=cbFun + >>> ) + >>> + >>> snmpDispatcher.transportDispatcher.runDispatcher() + """ + + def _cbFun(snmpDispatcher, stateHandle, errorIndication, rspPdu, _cbCtx): + if not cbFun: + return + + if errorIndication: + cbFun(errorIndication, pMod.Integer(0), pMod.Integer(0), None, + cbCtx=cbCtx, snmpDispatcher=snmpDispatcher, stateHandle=stateHandle) + return + + errorStatus = pMod.apiPDU.getErrorStatus(rspPdu) + errorIndex = pMod.apiPDU.getErrorIndex(rspPdu) + + varBinds = pMod.apiPDU.getVarBinds(rspPdu) + + if lookupMib: + varBinds = vbProcessor.unmakeVarBinds(snmpDispatcher.cache, varBinds) + + nextStateHandle = pMod.getNextRequestID() + + nextVarBinds = cbFun(errorIndication, errorStatus, errorIndex, varBinds, + cbCtx=cbCtx, + snmpDispatcher=snmpDispatcher, + stateHandle=stateHandle, + nextStateHandle=nextStateHandle) + + if not nextVarBinds: + return + + pMod.apiPDU.setRequestID(reqPdu, nextStateHandle) + pMod.apiPDU.setVarBinds(reqPdu, nextVarBinds) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) + + lookupMib, cbFun, cbCtx = [options.get(x) for x in ('lookupMib', 'cbFun', 'cbCtx')] + + if lookupMib: + varBinds = vbProcessor.makeVarBinds(snmpDispatcher.cache, varBinds) + + pMod = api.protoModules[authData.mpModel] + + reqPdu = pMod.GetRequestPDU() + pMod.apiPDU.setDefaults(reqPdu) + pMod.apiPDU.setVarBinds(reqPdu, varBinds) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) + + +def setCmd(snmpDispatcher, authData, transportTarget, + *varBinds, **options): + """Initiate SNMP SET query over SNMPv1/v2c. + + Based on passed parameters, prepares SNMP SET packet + (:RFC:`1905#section-4.2.5`) and schedules its transmission by + I/O framework at a later point of time. + + Parameters + ---------- + snmpDispatcher: :py:class:`~pysnmp.hlapi.v1arch.asyncore.SnmpDispatcher` + Class instance representing asyncore-based asynchronous event loop and + associated state information. + + authData: :py:class:`~pysnmp.hlapi.v1arch.CommunityData` + Class instance representing SNMP credentials. + + transportTarget: :py:class:`~pysnmp.hlapi.v1arch.asyncore.UdpTransportTarget` or :py:class:`~pysnmp.hlapi.v1arch.asyncore.Udp6TransportTarget` + Class instance representing transport type along with SNMP peer + address. + + \*varBinds: :class:`tuple` of OID-value pairs or :py:class:`~pysnmp.smi.rfc1902.ObjectType` + One or more class instances representing MIB variables to place + into SNMP request. + + Other Parameters + ---------------- + \*\*options : + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `False`. + * `cbFun` (callable) - user-supplied callable that is invoked + to pass SNMP response data or error to user at a later point + of time. Default is `None`. + * `cbCtx` (object) - user-supplied object passing additional + parameters to/from `cbFun`. Default is `None`. + + Note + ---- + The `SnmpDispatcher` object may be expensive to create, therefore it is + advised to maintain it for the lifecycle of the application/thread for + as long as possible. + + Note + ---- + User-supplied `cbFun` callable must have the following call + signature: + + * snmpDispatcher: :py:class:`~pysnmp.hlapi.v1arch.asyncore.SnmpDispatcher` + Class instance representing asyncore-based asynchronous event loop and + associated state information. + * stateHandle (int): Unique request identifier. Can be used + for matching multiple ongoing requests with received responses. + * errorIndication (str): evaluates to `True` to indicate SNMP dispatcher + error. + * errorStatus (int): evaluates to `True` to indicate SNMP PDU error. + * errorIndex (int): Non-zero value refers to `varBinds[errorIndex-1]` + * varBinds (tuple): A sequence of + :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + representing MIB variables returned in SNMP response in exactly + the same order as `varBinds` in request. + * `cbCtx` (object): Original user-supplied object. + + Returns + ------- + stateHandle: int + Unique request identifier. Can be used for matching received + responses with ongoing requests. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Examples + -------- + >>> from pysnmp.hlapi.v1arch.asyncore import * + >>> + >>> def cbFun(snmpDispatcher, stateHandle, errorIndication, + >>> errorStatus, errorIndex, varBinds, cbCtx): + >>> print(errorIndication, errorStatus, errorIndex, varBinds) + >>> + >>> snmpDispatcher = SnmpDispatcher() + >>> + >>> stateHandle = setCmd( + >>> snmpDispatcher, + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 161)), + >>> ('1.3.6.1.2.1.1.4.0', OctetString('info@snmplabs.com')), + >>> cbFun=cbFun + >>> ) + >>> + >>> snmpDispatcher.transportDispatcher.runDispatcher() + """ + + def _cbFun(snmpDispatcher, stateHandle, errorIndication, rspPdu, _cbCtx): + if not cbFun: + return + + if errorIndication: + cbFun(errorIndication, pMod.Integer(0), pMod.Integer(0), None, + cbCtx=cbCtx, snmpDispatcher=snmpDispatcher, stateHandle=stateHandle) + return + + errorStatus = pMod.apiPDU.getErrorStatus(rspPdu) + errorIndex = pMod.apiPDU.getErrorIndex(rspPdu) + + varBinds = pMod.apiPDU.getVarBinds(rspPdu) + + if lookupMib: + varBinds = vbProcessor.unmakeVarBinds(snmpDispatcher.cache, varBinds) + + nextStateHandle = pMod.getNextRequestID() + + nextVarBinds = cbFun(errorIndication, errorStatus, errorIndex, varBinds, + cbCtx=cbCtx, + snmpDispatcher=snmpDispatcher, + stateHandle=stateHandle, + nextStateHandle=nextStateHandle) + + if not nextVarBinds: + return + + pMod.apiPDU.setRequestID(reqPdu, nextStateHandle) + pMod.apiPDU.setVarBinds(reqPdu, nextVarBinds) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) + + lookupMib, cbFun, cbCtx = [options.get(x) for x in ('lookupMib', 'cbFun', 'cbCtx')] + + if lookupMib: + varBinds = vbProcessor.makeVarBinds(snmpDispatcher.cache, varBinds) + + pMod = api.protoModules[authData.mpModel] + + reqPdu = pMod.SetRequestPDU() + pMod.apiPDU.setDefaults(reqPdu) + pMod.apiPDU.setVarBinds(reqPdu, varBinds) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) + + +def nextCmd(snmpDispatcher, authData, transportTarget, + *varBinds, **options): + """Initiate SNMP GETNEXT query over SNMPv1/v2c. + + Based on passed parameters, prepares SNMP GETNEXT packet + (:RFC:`1905#section-4.2.2`) and schedules its transmission by + I/O framework at a later point of time. + + Parameters + ---------- + snmpDispatcher: :py:class:`~pysnmp.hlapi.v1arch.asyncore.SnmpDispatcher` + Class instance representing SNMP dispatcher. + + authData: :py:class:`~pysnmp.hlapi.v1arch.CommunityData` or :py:class:`~pysnmp.hlapi.v1arch.UsmUserData` + Class instance representing SNMP credentials. + + transportTarget: :py:class:`~pysnmp.hlapi.v1arch.asyncore.UdpTransportTarget` or :py:class:`~pysnmp.hlapi.v1arch.asyncore.Udp6TransportTarget` + Class instance representing transport type along with SNMP peer + address. + + \*varBinds: :class:`tuple` of OID-value pairs or :py:class:`~pysnmp.smi.rfc1902.ObjectType` + One or more class instances representing MIB variables to place + into SNMP request. + + Other Parameters + ---------------- + \*\*options : + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `True`. + * `cbFun` (callable) - user-supplied callable that is invoked + to pass SNMP response data or error to user at a later point + of time. Default is `None`. + * `cbCtx` (object) - user-supplied object passing additional + parameters to/from `cbFun`. Default is `None`. + + Notes + ----- + User-supplied `cbFun` callable must have the following call + signature: + + * snmpDispatcher (:py:class:`~pysnmp.hlapi.v1arch.snmpDispatcher`): + Class instance representing SNMP dispatcher. + * stateHandle (int): Unique request identifier. Can be used + for matching multiple ongoing requests with received responses. + * errorIndication (str): True value indicates SNMP dispatcher error. + * errorStatus (str): True value indicates SNMP PDU error. + * errorIndex (int): Non-zero value refers to `varBinds[errorIndex-1]` + * varBindTable (tuple): A sequence of sequences (e.g. 2-D array) of + variable-bindings represented as :class:`tuple` or + :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + representing a table of MIB variables returned in SNMP response. + Inner sequences represent table rows and ordered exactly the same + as `varBinds` in request. Response to GETNEXT always contain a + single row. + * `cbCtx` (object): Original user-supplied object. + + Returns + ------- + stateHandle: int + Unique request identifier. Can be used for matching received + responses with ongoing requests. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Examples + -------- + >>> from pysnmp.hlapi.v1arch.asyncore import * + >>> + >>> def cbFun(snmpDispatcher, stateHandle, errorIndication, + >>> errorStatus, errorIndex, varBinds, cbCtx): + >>> print(errorIndication, errorStatus, errorIndex, varBinds) + >>> + >>> snmpDispatcher = snmpDispatcher() + >>> + >>> stateHandle = nextCmd( + >>> snmpDispatcher, + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 161)), + >>> ('1.3.6.1.2.1.1', None), + >>> cbFun=cbFun + >>> ) + >>> + >>> snmpDispatcher.transportDispatcher.runDispatcher() + """ + + def _cbFun(snmpDispatcher, stateHandle, errorIndication, rspPdu, _cbCtx): + if not cbFun: + return + + if errorIndication: + cbFun(errorIndication, pMod.Integer(0), pMod.Integer(0), None, + cbCtx=cbCtx, snmpDispatcher=snmpDispatcher, stateHandle=stateHandle) + return + + errorStatus = pMod.apiPDU.getErrorStatus(rspPdu) + errorIndex = pMod.apiPDU.getErrorIndex(rspPdu) + + varBindTable = pMod.apiPDU.getVarBindTable(reqPdu, rspPdu) + + errorIndication, nextVarBinds = pMod.apiPDU.getNextVarBinds( + varBindTable[-1], errorIndex=errorIndex + ) + + if options.get('lookupMib'): + varBindTable = [ + vbProcessor.unmakeVarBinds(snmpDispatcher.cache, vbs) for vbs in varBindTable + ] + + nextStateHandle = pMod.getNextRequestID() + + nextVarBinds = cbFun(errorIndication, errorStatus, errorIndex, varBindTable, + cbCtx=cbCtx, + snmpDispatcher=snmpDispatcher, + stateHandle=stateHandle, + nextStateHandle=nextStateHandle, + nextVarBinds=nextVarBinds) + + if not nextVarBinds: + return + + pMod.apiPDU.setRequestID(reqPdu, nextStateHandle) + pMod.apiPDU.setVarBinds(reqPdu, nextVarBinds) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) + + lookupMib, cbFun, cbCtx = [options.get(x) for x in ('lookupMib', 'cbFun', 'cbCtx')] + + if lookupMib: + varBinds = vbProcessor.makeVarBinds(snmpDispatcher.cache, varBinds) + + pMod = api.protoModules[authData.mpModel] + + reqPdu = pMod.GetNextRequestPDU() + pMod.apiPDU.setDefaults(reqPdu) + pMod.apiPDU.setVarBinds(reqPdu, varBinds) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) + + +def bulkCmd(snmpDispatcher, authData, transportTarget, + nonRepeaters, maxRepetitions, *varBinds, **options): + """Initiate SNMP GETBULK query over SNMPv2c. + + Based on passed parameters, prepares SNMP GETBULK packet + (:RFC:`1905#section-4.2.3`) and schedules its transmission by + I/O framework at a later point of time. + + Parameters + ---------- + snmpDispatcher: :py:class:`~pysnmp.hlapi.v1arch.asyncore.SnmpDispatcher` + Class instance representing SNMP dispatcher. + + authData: :py:class:`~pysnmp.hlapi.v1arch.CommunityData` or :py:class:`~pysnmp.hlapi.v1arch.UsmUserData` + Class instance representing SNMP credentials. + + transportTarget: :py:class:`~pysnmp.hlapi.v1arch.asyncore.UdpTransportTarget` or :py:class:`~pysnmp.hlapi.v1arch.asyncore.Udp6TransportTarget` + Class instance representing transport type along with SNMP peer + address. + + nonRepeaters: int + One MIB variable is requested in response for the first + `nonRepeaters` MIB variables in request. + + maxRepetitions: int + `maxRepetitions` MIB variables are requested in response for each + of the remaining MIB variables in the request (e.g. excluding + `nonRepeaters`). Remote SNMP dispatcher may choose lesser value than + requested. + + \*varBinds: :py:class:`~pysnmp.smi.rfc1902.ObjectType` + One or more class instances representing MIB variables to place + into SNMP request. + + Other Parameters + ---------------- + \*\*options : + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `True`. + * `cbFun` (callable) - user-supplied callable that is invoked + to pass SNMP response data or error to user at a later point + of time. Default is `None`. + * `cbCtx` (object) - user-supplied object passing additional + parameters to/from `cbFun`. Default is `None`. + + Notes + ----- + User-supplied `cbFun` callable must have the following call + signature: + + * snmpDispatcher (:py:class:`~pysnmp.hlapi.v1arch.snmpDispatcher`): + Class instance representing SNMP dispatcher. + * stateHandle (int): Unique request identifier. Can be used + for matching multiple ongoing requests with received responses. + * errorIndication (str): True value indicates SNMP dispatcher error. + * errorStatus (str): True value indicates SNMP PDU error. + * errorIndex (int): Non-zero value refers to `varBinds[errorIndex-1]` + * varBindTable (tuple): A sequence of sequences (e.g. 2-D array) of + variable-bindings represented as :class:`tuple` or + :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + representing a table of MIB variables returned in SNMP response, with + up to ``maxRepetitions`` rows, i.e. ``len(varBindTable) <= maxRepetitions``. + + For ``0 <= i < len(varBindTable)`` and ``0 <= j < len(varBinds)``, + ``varBindTable[i][j]`` represents: + + - For non-repeaters (``j < nonRepeaters``), the first lexicographic + successor of ``varBinds[j]``, regardless the value of ``i``, or an + :py:class:`~pysnmp.smi.rfc1902.ObjectType` instance with the + :py:obj:`~pysnmp.proto.rfc1905.endOfMibView` value if no such successor + exists; + - For repeaters (``j >= nonRepeaters``), the ``i``-th lexicographic + successor of ``varBinds[j]``, or an + :py:class:`~pysnmp.smi.rfc1902.ObjectType` instance with the + :py:obj:`~pysnmp.proto.rfc1905.endOfMibView` value if no such successor + exists. + + See :rfc:`3416#section-4.2.3` for details on the underlying + ``GetBulkRequest-PDU`` and the associated ``GetResponse-PDU``, such as + specific conditions under which the server may truncate the response, + causing ``varBindTable`` to have less than ``maxRepetitions`` rows. + * `cbCtx` (object): Original user-supplied object. + + Returns + ------- + stateHandle : int + Unique request identifier. Can be used for matching received + responses with ongoing requests. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Examples + -------- + >>> from pysnmp.hlapi.v1arch.asyncore import * + >>> + >>> def cbFun(snmpDispatcher, stateHandle, errorIndication, + >>> errorStatus, errorIndex, varBinds, cbCtx): + >>> print(errorIndication, errorStatus, errorIndex, varBinds) + >>> + >>> snmpDispatcher = snmpDispatcher() + >>> + >>> stateHandle = bulkCmd( + >>> snmpDispatcher, + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 161)), + >>> 0, 2, + >>> ('1.3.6.1.2.1.1', None), + >>> cbFun=cbFun + >>> ) + >>> + >>> snmpDispatcher.transportDispatcher.runDispatcher() + """ + + def _cbFun(snmpDispatcher, stateHandle, errorIndication, rspPdu, _cbCtx): + if not cbFun: + return + + if errorIndication: + cbFun(errorIndication, pMod.Integer(0), pMod.Integer(0), None, + cbCtx=cbCtx, snmpDispatcher=snmpDispatcher, stateHandle=stateHandle) + return + + errorStatus = pMod.apiBulkPDU.getErrorStatus(rspPdu) + errorIndex = pMod.apiBulkPDU.getErrorIndex(rspPdu) + + varBindTable = pMod.apiBulkPDU.getVarBindTable(reqPdu, rspPdu) + + errorIndication, nextVarBinds = pMod.apiBulkPDU.getNextVarBinds( + varBindTable[-1], errorIndex=errorIndex + ) + + if options.get('lookupMib'): + varBindTable = [ + vbProcessor.unmakeVarBinds(snmpDispatcher.cache, vbs) for vbs in varBindTable + ] + + nextStateHandle = pMod.getNextRequestID() + + nextVarBinds = cbFun(errorIndication, errorStatus, errorIndex, varBindTable, + cbCtx=cbCtx, + snmpDispatcher=snmpDispatcher, + stateHandle=stateHandle, + nextStateHandle=nextStateHandle, + nextVarBinds=nextVarBinds) + + if not nextVarBinds: + return + + pMod.apiBulkPDU.setRequestID(reqPdu, nextStateHandle) + pMod.apiBulkPDU.setVarBinds(reqPdu, nextVarBinds) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) + + if authData.mpModel < 1: + raise error.PySnmpError('GETBULK PDU is only supported in SNMPv2c and SNMPv3') + + lookupMib, cbFun, cbCtx = [options.get(x) for x in ('lookupMib', 'cbFun', 'cbCtx')] + + if lookupMib: + varBinds = vbProcessor.makeVarBinds(snmpDispatcher.cache, varBinds) + + pMod = api.protoModules[authData.mpModel] + + reqPdu = pMod.GetBulkRequestPDU() + pMod.apiBulkPDU.setDefaults(reqPdu) + pMod.apiBulkPDU.setNonRepeaters(reqPdu, nonRepeaters) + pMod.apiBulkPDU.setMaxRepetitions(reqPdu, maxRepetitions) + pMod.apiBulkPDU.setVarBinds(reqPdu, varBinds) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) diff --git a/pysnmp/hlapi/v1arch/asyncore/dispatch.py b/pysnmp/hlapi/v1arch/asyncore/dispatch.py new file mode 100644 index 00000000..d77b8551 --- /dev/null +++ b/pysnmp/hlapi/v1arch/asyncore/dispatch.py @@ -0,0 +1,29 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher +from pysnmp.hlapi.v1arch.dispatch import AbstractSnmpDispatcher + +__all__ = ['SnmpDispatcher'] + + +class SnmpDispatcher(AbstractSnmpDispatcher): + """Creates SNMP message dispatcher object. + + `SnmpDispatcher` object manages send and receives SNMP PDU + messages through underlying transport dispatcher and dispatches + them to the callers. + + `SnmpDispatcher` is the only stateful object, all `hlapi.v1arch` SNMP + operations require an instance of `SnmpDispatcher`. Users do not normally + request services directly from `SnmpDispather`, but pass it around to + other `hlapi.v1arch` interfaces. + + It is possible to run multiple instances of `SnmpDispatcher` in the + application. In a multithreaded environment, each thread that + works with SNMP must have its own `SnmpDispatcher` instance. + """ + protoDispatcher = AsyncoreDispatcher diff --git a/pysnmp/hlapi/v1arch/asyncore/ntforg.py b/pysnmp/hlapi/v1arch/asyncore/ntforg.py new file mode 100644 index 00000000..a7767051 --- /dev/null +++ b/pysnmp/hlapi/v1arch/asyncore/ntforg.py @@ -0,0 +1,188 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from pysnmp.hlapi.varbinds import * +from pysnmp.hlapi.v1arch.auth import * +from pysnmp.hlapi.v1arch.asyncore import * +from pysnmp.smi.rfc1902 import * +from pysnmp.proto import api +from pysnmp.proto.proxy import rfc2576 +from pysnmp import error + +__all__ = ['sendNotification'] + +vbProcessor = NotificationOriginatorVarBinds() + + +def sendNotification(snmpDispatcher, authData, transportTarget, + notifyType, *varBinds, **options): + """Send SNMP notification. + + Based on passed parameters, prepares SNMP TRAP or INFORM + notification (:RFC:`1905#section-4.2.6`) and schedules its + transmission by I/O framework at a later point of time. + + Parameters + ---------- + snmpDispatcher: :py:class:`~pysnmp.hlapi.v1arch.asyncore.SnmpDispatcher` + Class instance representing asyncore-based asynchronous event loop and + associated state information. + + authData: :py:class:`~pysnmp.hlapi.CommunityData` or :py:class:`~pysnmp.hlapi.UsmUserData` + Class instance representing SNMP credentials. + + transportTarget: :py:class:`~pysnmp.hlapi.asyncore.UdpTransportTarget` or + :py:class:`~pysnmp.hlapi.asyncore.Udp6TransportTarget` + Class instance representing transport type along with SNMP peer address. + + notifyType: str + Indicates type of notification to be sent. Recognized literal + values are *trap* or *inform*. + + \*varBinds: :class:`tuple` of OID-value pairs or :py:class:`~pysnmp.smi.rfc1902.ObjectType` or :py:class:`~pysnmp.smi.rfc1902.NotificationType` + One or more objects representing MIB variables to place + into SNMP notification. It could be tuples of OID-values + or :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + of :py:class:`~pysnmp.smi.rfc1902.NotificationType` objects. + + SNMP Notification PDU places rigid requirement on the ordering of + the variable-bindings. + + Mandatory variable-bindings: + + 0. SNMPv2-MIB::sysUpTime.0 = + 1. SNMPv2-SMI::snmpTrapOID.0 = {SNMPv2-MIB::coldStart, ...} + + Optional variable-bindings (applicable to SNMP v1 TRAP): + + 2. SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = + 3. SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = + 4. SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = + + Informational variable-bindings: + + * SNMPv2-SMI::NOTIFICATION-TYPE + * SNMPv2-SMI::OBJECT-TYPE + + Other Parameters + ---------------- + \*\*options : + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `False`. + * `cbFun` (callable) - user-supplied callable that is invoked + to pass SNMP response data or error to user at a later point + of time. Default is `None`. + * `cbCtx` (object) - user-supplied object passing additional + parameters to/from `cbFun`. Default is `None`. + + Note + ---- + The `SnmpDispatcher` object may be expensive to create, therefore it is + advised to maintain it for the lifecycle of the application/thread for + as long as possible. + + + Returns + ------- + sendRequestHandle: int + Unique request identifier. Can be used for matching received + responses with ongoing *INFORM* requests. Returns `None` for + *TRAP* notifications. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Examples + -------- + >>> from pysnmp.hlapi.v1arch.asyncore import * + >>> + >>> snmpDispatcher = SnmpDispatcher() + >>> + >>> sendNotification( + >>> snmpDispatcher, + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 162)), + >>> 'trap', + >>> NotificationType(ObjectIdentity('SNMPv2-MIB', 'coldStart')), + >>> lookupMib=True + >>> ) + >>> snmpDispatcher.transportDispatcher.runDispatcher() + """ + + def _cbFun(snmpDispatcher, stateHandle, errorIndication, rspPdu, _cbCtx): + if not cbFun: + return + + if errorIndication: + cbFun(errorIndication, pMod.Integer(0), pMod.Integer(0), None, + cbCtx=cbCtx, snmpDispatcher=snmpDispatcher, stateHandle=stateHandle) + return + + errorStatus = pMod.apiTrapPDU.getErrorStatus(rspPdu) + errorIndex = pMod.apiTrapPDU.getErrorIndex(rspPdu) + + varBinds = pMod.apiTrapPDU.getVarBinds(rspPdu) + + if lookupMib: + varBinds = vbProcessor.unmakeVarBinds(snmpDispatcher.cache, varBinds) + + nextStateHandle = pMod.getNextRequestID() + + nextVarBinds = cbFun(errorIndication, errorStatus, errorIndex, varBinds, + cbCtx=cbCtx, + snmpDispatcher=snmpDispatcher, + stateHandle=stateHandle, + nextStateHandle=nextStateHandle) + + if not nextVarBinds: + return + + pMod.apiTrapPDU.setRequestID(reqPdu, nextStateHandle) + pMod.apiTrapPDU.setVarBinds(reqPdu, nextVarBinds) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) + + lookupMib, cbFun, cbCtx = [options.get(x) for x in ('lookupMib', 'cbFun', 'cbCtx')] + + if lookupMib: + varBinds = vbProcessor.makeVarBinds(snmpDispatcher.cache, varBinds) + + # # make sure required PDU payload is in place + # completeVarBinds = [] + # + # # ensure sysUpTime + # if len(varBinds) < 1 or varBinds[0][0] != pMod.apiTrapPDU.sysUpTime: + # varBinds.insert(0, (ObjectIdentifier(pMod.apiTrapPDU.sysUpTime), pMod.Integer(0))) + # + # # ensure sysUpTime + # if len(varBinds) < 1 or varBinds[0][0] != pMod.apiTrapPDU.sysUpTime: + # varBinds.insert(0, (ObjectIdentifier(pMod.apiTrapPDU.sysUpTime), pMod.Integer(0))) + # + # # ensure snmpTrapOID + # if len(varBinds) < 2 or varBinds[1][0] != pMod.apiTrapPDU.snmpTrapOID: + # varBinds.insert(0, (ObjectIdentifier(pMod.apiTrapPDU.sysUpTime), pMod.Integer(0))) + + # input PDU is always v2c + pMod = api.protoModules[api.protoVersion2c] + + if notifyType == 'trap': + reqPdu = pMod.TrapPDU() + else: + reqPdu = pMod.InformRequestPDU() + + pMod.apiTrapPDU.setDefaults(reqPdu) + pMod.apiTrapPDU.setVarBinds(reqPdu, varBinds) + + if authData.mpModel == 0: + reqPdu = rfc2576.v2ToV1(reqPdu) + + return snmpDispatcher.sendPdu(authData, transportTarget, reqPdu, cbFun=_cbFun) + diff --git a/pysnmp/hlapi/v1arch/asyncore/sync/__init__.py b/pysnmp/hlapi/v1arch/asyncore/sync/__init__.py new file mode 100644 index 00000000..5481cb96 --- /dev/null +++ b/pysnmp/hlapi/v1arch/asyncore/sync/__init__.py @@ -0,0 +1,21 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from pysnmp.proto.rfc1902 import * +from pysnmp.smi.rfc1902 import * +from pysnmp.hlapi.v1arch.auth import * +from pysnmp.hlapi.v1arch.asyncore.transport import * +from pysnmp.hlapi.v1arch.asyncore.cmdgen import * +from pysnmp.hlapi.v1arch.asyncore.ntforg import * +from pysnmp.hlapi.v1arch.asyncore.dispatch import * + +try: + from pysnmp.hlapi.v1arch.asyncore.sync.cmdgen import * + from pysnmp.hlapi.v1arch.asyncore.sync.ntforg import * + +except SyntaxError: + from pysnmp.hlapi.v1arch.asyncore.sync.compat.cmdgen import * + from pysnmp.hlapi.v1arch.asyncore.sync.compat.ntforg import * diff --git a/pysnmp/hlapi/v1arch/asyncore/sync/cmdgen.py b/pysnmp/hlapi/v1arch/asyncore/sync/cmdgen.py new file mode 100644 index 00000000..9b6b2b24 --- /dev/null +++ b/pysnmp/hlapi/v1arch/asyncore/sync/cmdgen.py @@ -0,0 +1,570 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from sys import version_info +from pysnmp.hlapi.v1arch.asyncore import cmdgen +from pysnmp.hlapi.varbinds import * +from pysnmp.proto.rfc1905 import endOfMibView +from pysnmp.proto import errind +from pyasn1.type.univ import Null + +__all__ = ['getCmd', 'nextCmd', 'setCmd', 'bulkCmd'] + +if version_info[:2] < (2, 6): + __all__.append('next') + + # noinspection PyShadowingBuiltins + def next(iter): + return iter.next() + +vbProcessor = CommandGeneratorVarBinds() + + +def getCmd(snmpDispatcher, authData, transportTarget, + *varBinds, **options): + """Creates a generator to perform one or more SNMP GET queries. + + On each iteration, new SNMP GET request is send (:RFC:`1905#section-4.2.1`). + The iterator blocks waiting for response to arrive or error to occur. + + Parameters + ---------- + snmpDispatcher: :py:class:`~pysnmp.hlapi.v1arch.asyncore.SnmpDispatcher` + Class instance representing asyncore-based asynchronous event loop and + associated state information. + + authData: :py:class:`~pysnmp.hlapi.CommunityData` or :py:class:`~pysnmp.hlapi.UsmUserData` + Class instance representing SNMP credentials. + + transportTarget: :py:class:`~pysnmp.hlapi.asyncore.UdpTransportTarget` or :py:class:`~pysnmp.hlapi.asyncore.Udp6TransportTarget` + Class instance representing transport type along with SNMP peer address. + + \*varBinds: :py:class:`~pysnmp.smi.rfc1902.ObjectType` + One or more class instances representing MIB variables to place + into SNMP request. + + Other Parameters + ---------------- + \*\*options: + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `False`. + + Yields + ------ + errorIndication: str + True value indicates local SNMP error. + errorStatus: str + True value indicates SNMP PDU error reported by remote. + errorIndex: int + Non-zero value refers to `varBinds[errorIndex-1]` + varBinds: tuple + A sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` class + instances representing MIB variables returned in SNMP response. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Notes + ----- + The `getCmd` generator will be exhausted immediately unless + a new sequence of `varBinds` are send back into running generator + (supported since Python 2.6). + + Examples + -------- + >>> from pysnmp.hlapi.v1arch import * + >>> + >>> g = getCmd(snmpDispatcher(), + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 161)), + >>> ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) + >>> + >>> next(g) + (None, 0, 0, [ObjectType(ObjectIdentity(ObjectName('1.3.6.1.2.1.1.1.0')), + DisplayString('SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'))]) + """ + + def cbFun(*args, **kwargs): + response[:] = args + + options['cbFun'] = cbFun + + errorIndication, errorStatus, errorIndex = None, 0, 0 + response = [] + + while True: + if varBinds: + cmdgen.getCmd(snmpDispatcher, authData, transportTarget, + *varBinds, **options) + + snmpDispatcher.transportDispatcher.runDispatcher() + + errorIndication, errorStatus, errorIndex, varBinds = response + + varBinds = (yield errorIndication, errorStatus, errorIndex, varBinds) + + if not varBinds: + break + + +def setCmd(snmpDispatcher, authData, transportTarget, + *varBinds, **options): + """Creates a generator to perform one or more SNMP SET queries. + + On each iteration, new SNMP SET request is send (:RFC:`1905#section-4.2.5`). + The iterator blocks waiting for response to arrive or error to occur. + + Parameters + ---------- + snmpDispatcher : :py:class:`~pysnmp.hlapi.snmpDispatcher` + Class instance representing SNMP engine. + + authData : :py:class:`~pysnmp.hlapi.CommunityData` or :py:class:`~pysnmp.hlapi.UsmUserData` + Class instance representing SNMP credentials. + + transportTarget : :py:class:`~pysnmp.hlapi.asyncore.UdpTransportTarget` or :py:class:`~pysnmp.hlapi.asyncore.Udp6TransportTarget` + Class instance representing transport type along with SNMP peer address. + + \*varBinds : :py:class:`~pysnmp.smi.rfc1902.ObjectType` + One or more class instances representing MIB variables to place + into SNMP request. + + Other Parameters + ---------------- + \*\*options : + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `True`. + Default is `True`. + + Yields + ------ + errorIndication : str + True value indicates SNMP engine error. + errorStatus : str + True value indicates SNMP PDU error. + errorIndex : int + Non-zero value refers to `varBinds[errorIndex-1]` + varBinds : tuple + A sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` class + instances representing MIB variables returned in SNMP response. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Notes + ----- + The `setCmd` generator will be exhausted immidiately unless + a new sequence of `varBinds` are send back into running generator + (supported since Python 2.6). + + Examples + -------- + >>> from pysnmp.hlapi.v1arch import * + >>> + >>> g = setCmd(snmpDispatcher(), + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 161)), + >>> ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), 'Linux i386')) + >>> + >>> next(g) + (None, 0, 0, [ObjectType(ObjectIdentity(ObjectName('1.3.6.1.2.1.1.1.0')), + DisplayString('Linux i386'))]) + """ + + def cbFun(*args, **kwargs): + response[:] = args + + options['cbFun'] = cbFun + + errorIndication, errorStatus, errorIndex = None, 0, 0 + response = [] + + while True: + if varBinds: + cmdgen.setCmd(snmpDispatcher, authData, transportTarget, + *varBinds, **options) + + snmpDispatcher.transportDispatcher.runDispatcher() + + errorIndication, errorStatus, errorIndex, varBinds = response + + varBinds = (yield errorIndication, errorStatus, errorIndex, varBinds) + + if not varBinds: + break + + +def nextCmd(snmpDispatcher, authData, transportTarget, + *varBinds, **options): + """Create a generator to perform one or more SNMP GETNEXT queries. + + On each iteration, new SNMP GETNEXT request is send + (:RFC:`1905#section-4.2.2`). The iterator blocks waiting for response + to arrive or error to occur. + + Parameters + ---------- + snmpDispatcher : :py:class:`~pysnmp.hlapi.snmpDispatcher` + Class instance representing SNMP engine. + + authData : :py:class:`~pysnmp.hlapi.CommunityData` or :py:class:`~pysnmp.hlapi.UsmUserData` + Class instance representing SNMP credentials. + + transportTarget : :py:class:`~pysnmp.hlapi.asyncore.UdpTransportTarget` or :py:class:`~pysnmp.hlapi.asyncore.Udp6TransportTarget` + Class instance representing transport type along with SNMP peer address. + + \*varBinds : :py:class:`~pysnmp.smi.rfc1902.ObjectType` + One or more class instances representing MIB variables to place + into SNMP request. + + Other Parameters + ---------------- + \*\*options : + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `True`. + Default is `True`. + * `lexicographicMode` - walk SNMP agent's MIB till the end (if `True`), + otherwise (if `False`) stop iteration when all response MIB + variables leave the scope of initial MIB variables in + `varBinds`. Default is `True`. + * `ignoreNonIncreasingOid` - continue iteration even if response + MIB variables (OIDs) are not greater then request MIB variables. + Be aware that setting it to `True` may cause infinite loop between + SNMP management and agent applications. Default is `False`. + * `maxRows` - stop iteration once this generator instance processed + `maxRows` of SNMP conceptual table. Default is `0` (no limit). + * `maxCalls` - stop iteration once this generator instance processed + `maxCalls` responses. Default is 0 (no limit). + + Yields + ------ + errorIndication: str + True value indicates SNMP engine error. + errorStatus: str + True value indicates SNMP PDU error. + errorIndex: int + Non-zero value refers to `varBinds[errorIndex-1]` + varBindTable: tuple + A 2-dimensional array of :py:class:`~pysnmp.smi.rfc1902.ObjectType` class + instances representing a table of MIB variables returned in SNMP response. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Notes + ----- + The `nextCmd` generator will be exhausted on any of the following + conditions: + + * SNMP engine error occurs thus `errorIndication` is `True` + * SNMP PDU `errorStatus` is reported as `True` + * SNMP :py:class:`~pysnmp.proto.rfc1905.EndOfMibView` values + (also known as *SNMP exception values*) are reported for all + MIB variables in `varBinds` + * *lexicographicMode* option is `True` and SNMP agent reports + end-of-mib or *lexicographicMode* is `False` and all + response MIB variables leave the scope of `varBinds` + + At any moment a new sequence of `varBinds` could be send back into + running generator (supported since Python 2.6). + + Examples + -------- + >>> from pysnmp.hlapi.v1arch import * + >>> + >>> g = nextCmd(snmpDispatcher(), + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 161)), + >>> ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'))) + >>> next(g) + (None, 0, 0, [[ObjectType(ObjectIdentity(ObjectName('1.3.6.1.2.1.1.1.0')), DisplayString('SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'))]]) + >>> g.send([ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets'))]) + (None, 0, 0, [(ObjectName('1.3.6.1.2.1.2.2.1.10.1'), Counter32(284817787))]) + """ + + def cbFun(*args, **kwargs): + response[:] = args + (kwargs.get('nextVarBinds', ()),) + + options['cbFun'] = cbFun + + lexicographicMode = options.pop('lexicographicMode', True) + maxRows = options.pop('maxRows', 0) + maxCalls = options.pop('maxCalls', 0) + + initialVarBinds = vbProcessor.makeVarBinds(snmpDispatcher.cache, varBinds) + + totalRows = totalCalls = 0 + + errorIndication, errorStatus, errorIndex, varBindTable = None, 0, 0, () + response = [] + + while True: + if not varBinds: + yield (errorIndication, errorStatus, errorIndex, varBindTable) + return + + cmdgen.nextCmd(snmpDispatcher, authData, transportTarget, + *[(x[0], Null('')) for x in varBinds], **options) + + snmpDispatcher.transportDispatcher.runDispatcher() + + errorIndication, errorStatus, errorIndex, varBindTable, varBinds = response + + if errorIndication: + yield (errorIndication, errorStatus, errorIndex, varBindTable) + return + + elif errorStatus: + if errorStatus == 2: + # Hide SNMPv1 noSuchName error which leaks in here + # from SNMPv1 Agent through internal pysnmp proxy. + errorStatus = errorStatus.clone(0) + errorIndex = errorIndex.clone(0) + yield (errorIndication, errorStatus, errorIndex, varBindTable) + return + + else: + varBindRow = varBindTable and varBindTable[-1] + + if not lexicographicMode: + for idx, varBind in enumerate(varBindRow): + name, val = varBind + if not isinstance(val, Null): + if initialVarBinds[idx][0].isPrefixOf(name): + break + else: + return + + for varBindRow in varBindTable: + nextVarBinds = (yield errorIndication, errorStatus, errorIndex, varBindRow) + + if nextVarBinds: + initialVarBinds = varBinds = vbProcessor.makeVarBinds(snmpDispatcher.cache, nextVarBinds) + + totalRows += 1 + totalCalls += 1 + + if maxRows and totalRows >= maxRows: + return + + if maxCalls and totalCalls >= maxCalls: + return + + +def bulkCmd(snmpDispatcher, authData, transportTarget, + nonRepeaters, maxRepetitions, *varBinds, **options): + """Creates a generator to perform one or more SNMP GETBULK queries. + + On each iteration, new SNMP GETBULK request is send + (:RFC:`1905#section-4.2.3`). The iterator blocks waiting for response + to arrive or error to occur. + + Parameters + ---------- + snmpDispatcher : :py:class:`~pysnmp.hlapi.snmpDispatcher` + Class instance representing SNMP engine. + + authData : :py:class:`~pysnmp.hlapi.CommunityData` or :py:class:`~pysnmp.hlapi.UsmUserData` + Class instance representing SNMP credentials. + + transportTarget : :py:class:`~pysnmp.hlapi.asyncore.UdpTransportTarget` or :py:class:`~pysnmp.hlapi.asyncore.Udp6TransportTarget` + Class instance representing transport type along with SNMP peer address. + + nonRepeaters : int + One MIB variable is requested in response for the first + `nonRepeaters` MIB variables in request. + + maxRepetitions : int + `maxRepetitions` MIB variables are requested in response for each + of the remaining MIB variables in the request (e.g. excluding + `nonRepeaters`). Remote SNMP engine may choose lesser value than + requested. + + \*varBinds : :py:class:`~pysnmp.smi.rfc1902.ObjectType` + One or more class instances representing MIB variables to place + into SNMP request. + + Other Parameters + ---------------- + \*\*options : + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `True`. + Default is `True`. + * `lexicographicMode` - walk SNMP agent's MIB till the end (if `True`), + otherwise (if `False`) stop iteration when all response MIB + variables leave the scope of initial MIB variables in + `varBinds`. Default is `True`. + * `ignoreNonIncreasingOid` - continue iteration even if response + MIB variables (OIDs) are not greater then request MIB variables. + Be aware that setting it to `True` may cause infinite loop between + SNMP management and agent applications. Default is `False`. + * `maxRows` - stop iteration once this generator instance processed + `maxRows` of SNMP conceptual table. Default is `0` (no limit). + * `maxCalls` - stop iteration once this generator instance processed + `maxCalls` responses. Default is 0 (no limit). + + Yields + ------ + errorIndication : str + True value indicates SNMP engine error. + errorStatus : str + True value indicates SNMP PDU error. + errorIndex : int + Non-zero value refers to \*varBinds[errorIndex-1] + varBinds: tuple + A sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` class + instances representing MIB variables returned in SNMP response. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Notes + ----- + The `bulkCmd` generator will be exhausted on any of the following + conditions: + + * SNMP engine error occurs thus `errorIndication` is `True` + * SNMP PDU `errorStatus` is reported as `True` + * SNMP :py:class:`~pysnmp.proto.rfc1905.EndOfMibView` values + (also known as *SNMP exception values*) are reported for all + MIB variables in `varBinds` + * *lexicographicMode* option is `True` and SNMP agent reports + end-of-mib or *lexicographicMode* is `False` and all + response MIB variables leave the scope of `varBinds` + + At any moment a new sequence of `varBinds` could be send back into + running generator (supported since Python 2.6). + + Setting `maxRepetitions` value to 15..50 might significantly improve + system performance, as many MIB variables get packed into a single + response message at once. + + Examples + -------- + >>> from pysnmp.hlapi.v1arch import * + >>> + >>> g = bulkCmd(snmpDispatcher(), + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 161)), + >>> 0, 25, + >>> ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'))) + >>> next(g) + (None, 0, 0, [[ObjectType(ObjectIdentity(ObjectName('1.3.6.1.2.1.1.1.0')), DisplayString('SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'))]]) + >>> g.send([ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets'))]) + (None, 0, 0, [[(ObjectName('1.3.6.1.2.1.2.2.1.10.1'), Counter32(284817787))]]) + """ + + def cbFun(*args, **kwargs): + response[:] = args + (kwargs.get('nextVarBinds', ()),) + + options['cbFun'] = cbFun + + lexicographicMode = options.pop('lexicographicMode', True) + maxRows = options.pop('maxRows', 0) + maxCalls = options.pop('maxCalls', 0) + + initialVarBinds = vbProcessor.makeVarBinds(snmpDispatcher.cache, varBinds) + + nullVarBinds = [False] * len(initialVarBinds) + + totalRows = totalCalls = 0 + + errorIndication, errorStatus, errorIndex, varBindTable = None, 0, 0, () + response = [] + + stopFlag = False + + while not stopFlag: + if not varBinds: + yield (errorIndication, errorStatus, errorIndex, varBinds) + return + + if maxRows and totalRows < maxRows: + maxRepetitions = min(maxRepetitions, maxRows - totalRows) + + cmdgen.bulkCmd(snmpDispatcher, authData, transportTarget, + nonRepeaters, maxRepetitions, + *[(x[0], Null('')) for x in varBinds], **options) + + snmpDispatcher.transportDispatcher.runDispatcher() + + errorIndication, errorStatus, errorIndex, varBindTable, varBinds = response + + if errorIndication: + yield (errorIndication, errorStatus, errorIndex, ()) + return + + elif errorStatus: + if errorStatus == 2: + # Hide SNMPv1 noSuchName error which leaks in here + # from SNMPv1 Agent through internal pysnmp proxy. + errorStatus = errorStatus.clone(0) + errorIndex = errorIndex.clone(0) + yield (errorIndication, errorStatus, errorIndex, varBindTable and varBindTable[0] or []) + return + + else: + for rowIdx, varBindRow in enumerate(varBindTable): + stopFlag = True + if len(varBindRow) != len(initialVarBinds): + varBindTable = rowIdx and varBindTable[:rowIdx - 1] or [] + break + + for colIdx, varBind in enumerate(varBindRow): + name, val = varBind + if nullVarBinds[colIdx]: + varBindRow[colIdx] = name, endOfMibView + continue + + stopFlag = False + + if isinstance(val, Null): + nullVarBinds[colIdx] = True + + elif not lexicographicMode and not initialVarBinds[colIdx][0].isPrefixOf(name): + varBindRow[colIdx] = name, endOfMibView + nullVarBinds[colIdx] = True + + if stopFlag: + varBindTable = rowIdx and varBindTable[:rowIdx - 1] or [] + break + + totalRows += len(varBindTable) + totalCalls += 1 + + if maxRows and totalRows >= maxRows: + if totalRows > maxRows: + varBindTable = varBindTable[:-(totalRows - maxRows)] + stopFlag = True + + if maxCalls and totalCalls >= maxCalls: + stopFlag = True + + for varBindRow in varBindTable: + nextVarBinds = (yield errorIndication, errorStatus, errorIndex, varBindRow) + + if nextVarBinds: + initialVarBinds = varBinds = vbProcessor.makeVarBinds(snmpDispatcher.cache, nextVarBinds) diff --git a/pysnmp/hlapi/v1arch/asyncore/sync/ntforg.py b/pysnmp/hlapi/v1arch/asyncore/sync/ntforg.py new file mode 100644 index 00000000..25912ff4 --- /dev/null +++ b/pysnmp/hlapi/v1arch/asyncore/sync/ntforg.py @@ -0,0 +1,140 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from sys import version_info +from pysnmp.hlapi.v1arch.asyncore import ntforg +from pysnmp.hlapi.varbinds import * +from pysnmp.proto import errind +from pyasn1.type.univ import Null + +__all__ = ['sendNotification'] + +if version_info[:2] < (2, 6): + __all__.append('next') + + # noinspection PyShadowingBuiltins + def next(iter): + return iter.next() + + +def sendNotification(snmpDispatcher, authData, transportTarget, + notifyType, *varBinds, **options): + """Creates a generator to send one or more SNMP notifications. + + On each iteration, new SNMP TRAP or INFORM notification is send + (:RFC:`1905#section-4,2,6`). The iterator blocks waiting for + INFORM acknowledgement to arrive or error to occur. + + Parameters + ---------- + snmpDispatcher: :py:class:`~pysnmp.hlapi.v1arch.asyncore.SnmpDispatcher` + Class instance representing asyncore-based asynchronous event loop and + associated state information. + + authData: :py:class:`~pysnmp.hlapi.CommunityData` or :py:class:`~pysnmp.hlapi.UsmUserData` + Class instance representing SNMP credentials. + + transportTarget: :py:class:`~pysnmp.hlapi.asyncore.UdpTransportTarget` or + :py:class:`~pysnmp.hlapi.asyncore.Udp6TransportTarget` + Class instance representing transport type along with SNMP peer address. + + notifyType: str + Indicates type of notification to be sent. Recognized literal + values are *trap* or *inform*. + + \*varBinds: :class:`tuple` of OID-value pairs or :py:class:`~pysnmp.smi.rfc1902.ObjectType` or :py:class:`~pysnmp.smi.rfc1902.NotificationType` + One or more objects representing MIB variables to place + into SNMP notification. It could be tuples of OID-values + or :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + of :py:class:`~pysnmp.smi.rfc1902.NotificationType` objects. + + SNMP Notification PDU places rigid requirement on the ordering of + the variable-bindings. + + Mandatory variable-bindings: + + 0. SNMPv2-MIB::sysUpTime.0 = + 1. SNMPv2-SMI::snmpTrapOID.0 = {SNMPv2-MIB::coldStart, ...} + + Optional variable-bindings (applicable to SNMP v1 TRAP): + + 2. SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = + 3. SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = + 4. SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = + + Informational variable-bindings: + + * SNMPv2-SMI::NOTIFICATION-TYPE + * SNMPv2-SMI::OBJECT-TYPE + + Other Parameters + ---------------- + \*\*options : + Request options: + + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `False`. + + Yields + ------ + errorIndication: str + True value indicates local SNMP error. + errorStatus: str + True value indicates SNMP PDU error reported by remote. + errorIndex: int + Non-zero value refers to `varBinds[errorIndex-1]` + varBinds: tuple + A sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` class + instances representing MIB variables returned in SNMP response. + + Raises + ------ + PySnmpError + Or its derivative indicating that an error occurred while + performing SNMP operation. + + Notes + ----- + The `sendNotification` generator will be exhausted immediately unless + an instance of :py:class:`~pysnmp.smi.rfc1902.NotificationType` class + or a sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` `varBinds` + are send back into running generator (supported since Python 2.6). + + Examples + -------- + >>> from pysnmp.hlapi.v1arch import * + >>> + >>> g = sendNotification(SnmpDispatcher(), + >>> CommunityData('public'), + >>> UdpTransportTarget(('demo.snmplabs.com', 162)), + >>> 'trap', + >>> NotificationType(ObjectIdentity('IF-MIB', 'linkDown'))) + >>> next(g) + (None, 0, 0, []) + """ + + def cbFun(*args, **kwargs): + response[:] = args + + options['cbFun'] = cbFun + + errorIndication, errorStatus, errorIndex = None, 0, 0 + + response = [None, 0, 0, []] + + while True: + if varBinds: + ntforg.sendNotification(snmpDispatcher, authData, transportTarget, + notifyType, *varBinds, **options) + + snmpDispatcher.transportDispatcher.runDispatcher() + + errorIndication, errorStatus, errorIndex, varBinds = response + + varBinds = (yield errorIndication, errorStatus, errorIndex, varBinds) + + if not varBinds: + break diff --git a/pysnmp/hlapi/v1arch/asyncore/transport.py b/pysnmp/hlapi/v1arch/asyncore/transport.py new file mode 100644 index 00000000..be5e336d --- /dev/null +++ b/pysnmp/hlapi/v1arch/asyncore/transport.py @@ -0,0 +1,111 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +import socket +import sys + +from pysnmp import error +from pysnmp.carrier.asyncore.dgram import udp, udp6 +from pysnmp.hlapi.transport import AbstractTransportTarget + +__all__ = ['Udp6TransportTarget', 'UdpTransportTarget'] + + +class UdpTransportTarget(AbstractTransportTarget): + """Represent UDP/IPv4 transport endpoint. + + This object can be used for passing UDP/IPv4 configuration information + to the low-level SNMP applications. + + See :RFC:`1906#section-3` for more information on the UDP transport mapping. + + Parameters + ---------- + transportAddr: :py:class:`tuple` + Indicates remote address in Python :py:mod:`socket` module format + which is a tuple of FQDN, port where FQDN is a string representing + either hostname or IPv4 address in quad-dotted form, port is an + integer. + timeout: :py:class:`int` + Response timeout in seconds. + retries: :py:class:`int` + Maximum number of request retries, 0 retries means just a single + request. + + Examples + -------- + >>> from pysnmp.hlapi.v1arch.asyncore import UdpTransportTarget + >>> UdpTransportTarget(('demo.snmplabs.com', 161)) + UdpTransportTarget(('195.218.195.228', 161), timeout=1, retries=5) + >>> + + """ + transportDomain = udp.domainName + protoTransport = udp.UdpSocketTransport + + def _resolveAddr(self, transportAddr): + try: + return socket.getaddrinfo(transportAddr[0], + transportAddr[1], + socket.AF_INET, + socket.SOCK_DGRAM, + socket.IPPROTO_UDP)[0][4][:2] + except socket.gaierror: + raise error.PySnmpError('Bad IPv4/UDP transport address %s: %s' % ( + '@'.join([str(x) for x in transportAddr]), sys.exc_info()[1])) + + +class Udp6TransportTarget(AbstractTransportTarget): + """Represent UDP/IPv6 transport endpoint. + + This object can be used for passing UDP/IPv4 configuration information + to the low-level SNMP applications. + + See :RFC:`1906#section-3`, :RFC:`2851#section-4` for more information + on the UDP and IPv6 transport mapping. + + Parameters + ---------- + transportAddr : tuple + Indicates remote address in Python :py:mod:`socket` module format + which is a tuple of FQDN, port where FQDN is a string representing + either hostname or IPv6 address in one of three conventional forms + (:RFC:`1924#section-3`), port is an integer. + timeout : int + Response timeout in seconds. + retries : int + Maximum number of request retries, 0 retries means just a single + request. + + Examples + -------- + >>> from pysnmp.hlapi.v1arch.asyncore import Udp6TransportTarget + >>> Udp6TransportTarget(('google.com', 161)) + Udp6TransportTarget(('2a00:1450:4014:80a::100e', 161), timeout=1, retries=5) + >>> Udp6TransportTarget(('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', 161)) + Udp6TransportTarget(('fedc:ba98:7654:3210:fedc:ba98:7654:3210', 161), timeout=1, retries=5) + >>> Udp6TransportTarget(('1080:0:0:0:8:800:200C:417A', 161)) + Udp6TransportTarget(('1080::8:800:200c:417a', 161), timeout=1, retries=5) + >>> Udp6TransportTarget(('::0', 161)) + Udp6TransportTarget(('::', 161), timeout=1, retries=5) + >>> Udp6TransportTarget(('::', 161)) + Udp6TransportTarget(('::', 161), timeout=1, retries=5) + >>> + + """ + transportDomain = udp6.domainName + protoTransport = udp6.Udp6SocketTransport + + def _resolveAddr(self, transportAddr): + try: + return socket.getaddrinfo(transportAddr[0], + transportAddr[1], + socket.AF_INET6, + socket.SOCK_DGRAM, + socket.IPPROTO_UDP)[0][4][:2] + except socket.gaierror: + raise error.PySnmpError('Bad IPv6/UDP transport address %s: %s' % ( + '@'.join([str(x) for x in transportAddr]), sys.exc_info()[1])) diff --git a/pysnmp/hlapi/v1arch/auth.py b/pysnmp/hlapi/v1arch/auth.py new file mode 100644 index 00000000..761f9738 --- /dev/null +++ b/pysnmp/hlapi/v1arch/auth.py @@ -0,0 +1,45 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# + +__all__ = ['CommunityData'] + + +class CommunityData(object): + """Creates SNMP v1/v2c configuration entry. + + This object can be used by + :py:class:`~pysnmp.hlapi.v1arch.asyncore.AsyncCommandGenerator` or + :py:class:`~pysnmp.hlapi.v1arch.asyncore.AsyncNotificationOriginator` + and their derivatives for conveying SNMP v1/v2c configuration. + + Parameters + ---------- + communityName: py:class:`str` + SNMP v1/v2c community string. + mpModel: py:class:`int` + SNMP version - 0 for SNMPv1 and 1 for SNMPv2c. + + Examples + -------- + >>> from pysnmp.hlapi.v1arch import CommunityData + >>> CommunityData('public') + CommunityData(communityName=, mpModel=1) + """ + + def __init__(self, communityName, mpModel=1): + self.mpModel = mpModel + self.communityName = communityName + + def __hash__(self): + return hash((self.communityName, self.mpModel)) + + def __repr__(self): + return '%s(communityName=, mpModel=%r)' % ( + self.__class__.__name__, + self.communityName, + self.mpModel, + ) diff --git a/pysnmp/hlapi/v1arch/dispatch.py b/pysnmp/hlapi/v1arch/dispatch.py new file mode 100644 index 00000000..0c222281 --- /dev/null +++ b/pysnmp/hlapi/v1arch/dispatch.py @@ -0,0 +1,168 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from time import time + +from pysnmp.proto.api import verdec +from pysnmp.proto import api +from pysnmp.proto import error +from pysnmp import debug + +from pyasn1.codec.ber import encoder, decoder + +__all__ = [] + + +class AbstractSnmpDispatcher(object): + """Creates SNMP message dispatcher object. + + `SnmpDispatcher` object manages send and receives SNMP PDU + messages through underlying transport dispatcher and dispatches + them to the callers. + + `SnmpDispatcher` is the only stateful object, all `hlapi.v1arch` SNMP + operations require an instance of `SnmpDispatcher`. Users do not normally + request services directly from `SnmpDispather`, but pass it around to + other `hlapi.v1arch` interfaces. + + It is possible to run multiple instances of `SnmpDispatcher` in the + application. In a multithreaded environment, each thread that + works with SNMP must have its own `SnmpDispatcher` instance. + """ + + protoDispatcher = None + + def __init__(self, transportDispatcher=None): + if transportDispatcher: + self.transportDispatcher = transportDispatcher + else: + self.transportDispatcher = self.protoDispatcher() + + self._automaticDispatcher = transportDispatcher is not self.transportDispatcher + self._configuredTransports = set() + + self._pendingReqs = {} + + self.transportDispatcher.registerRecvCbFun(self._recvCb) + self.transportDispatcher.registerTimerCbFun(self._timerCb) + + self.cache = {} + + def __repr__(self): + return '%s(transportDispatcher=%s)' % (self.__class__.__name__, self.transportDispatcher) + + def close(self): + self.transportDispatcher.unregisterRecvCbFun() + self.transportDispatcher.unregisterTimerCbFun() + if self._automaticDispatcher: + self.transportDispatcher.close() + + for requestId, stateInfo in self._pendingReqs.items(): + cbFun = stateInfo['cbFun'] + cbCtx = stateInfo['cbCtx'] + + if cbFun: + cbFun(self, 'Request #%d terminated' % requestId, None, cbCtx) + + self._pendingReqs.clear() + + def sendPdu(self, authData, transportTarget, reqPdu, cbFun=None, cbCtx=None): + if (self._automaticDispatcher and + transportTarget.transportDomain not in self._configuredTransports): + self.transportDispatcher.registerTransport( + transportTarget.transportDomain, transportTarget.protoTransport().openClientMode() + ) + self._configuredTransports.add(transportTarget.transportDomain) + + pMod = api.protoModules[authData.mpModel] + + reqMsg = pMod.Message() + pMod.apiMessage.setDefaults(reqMsg) + pMod.apiMessage.setCommunity(reqMsg, authData.communityName) + pMod.apiMessage.setPDU(reqMsg, reqPdu) + + outgoingMsg = encoder.encode(reqMsg) + + requestId = pMod.apiPDU.getRequestID(reqPdu) + + self._pendingReqs[requestId] = dict( + outgoingMsg=outgoingMsg, + transportTarget=transportTarget, + cbFun=cbFun, cbCtx=cbCtx, + timestamp=time() + transportTarget.timeout, retries=0 + ) + + self.transportDispatcher.sendMessage( + outgoingMsg, transportTarget.transportDomain, transportTarget.transportAddr + ) + + if (reqPdu.__class__ is getattr(pMod, 'SNMPv2TrapPDU', None) or + reqPdu.__class__ is getattr(pMod, 'TrapPDU', None)): + return requestId + + self.transportDispatcher.jobStarted(id(self)) + + return requestId + + def _recvCb(self, snmpEngine, transportDomain, transportAddress, wholeMsg): + try: + mpModel = verdec.decodeMessageVersion(wholeMsg) + + except error.ProtocolError: + return null # n.b the whole buffer gets dropped + + debug.logger & debug.flagDsp and debug.logger('receiveMessage: msgVersion %s, msg decoded' % mpModel) + + pMod = api.protoModules[mpModel] + + while wholeMsg: + rspMsg, wholeMsg = decoder.decode(wholeMsg, asn1Spec=pMod.Message()) + rspPdu = pMod.apiMessage.getPDU(rspMsg) + + requestId = pMod.apiPDU.getRequestID(rspPdu) + + try: + stateInfo = self._pendingReqs.pop(requestId) + + except KeyError: + continue + + self.transportDispatcher.jobFinished(id(self)) + + cbFun = stateInfo['cbFun'] + cbCtx = stateInfo['cbCtx'] + + if cbFun: + cbFun(self, requestId, None, rspPdu, cbCtx) + + return wholeMsg + + def _timerCb(self, timeNow): + for requestId, stateInfo in self._pendingReqs.items(): + if stateInfo['timestamp'] < timeNow: + continue + + retries = stateInfo['retries'] + transportTarget = stateInfo['transportTarget'] + + if retries == transportTarget.retries: + cbFun = stateInfo['cbFun'] + cbCtx = stateInfo['cbCtx'] + + if cbFun: + del self._pendingReqs[requestId] + cbFun(self, requestId, 'Request #%d timed out' % requestId, None, cbCtx) + self.transportDispatcher.jobFinished(id(self)) + continue + + stateInfo['retries'] += 1 + stateInfo['timestamp'] = timeNow + transportTarget.timeout + + outgoingMsg = stateInfo['outgoingMsg'] + + self.transportDispatcher.sendMessage( + outgoingMsg, transportTarget.transportDomain, transportTarget.transportAddr + ) diff --git a/pysnmp/hlapi/v3arch/__init__.py b/pysnmp/hlapi/v3arch/__init__.py new file mode 100644 index 00000000..8f36181c --- /dev/null +++ b/pysnmp/hlapi/v3arch/__init__.py @@ -0,0 +1,15 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from pysnmp.proto.rfc1902 import * +from pysnmp.proto.rfc1905 import NoSuchInstance, NoSuchObject, EndOfMibView +from pysnmp.smi.rfc1902 import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.entity.engine import * + +# default is synchronous asyncore-based API +from pysnmp.hlapi.v3arch.asyncore.sync import * diff --git a/pysnmp/hlapi/asyncio/__init__.py b/pysnmp/hlapi/v3arch/asyncio/__init__.py similarity index 52% rename from pysnmp/hlapi/asyncio/__init__.py rename to pysnmp/hlapi/v3arch/asyncio/__init__.py index 24e71f7c..98f67187 100644 --- a/pysnmp/hlapi/asyncio/__init__.py +++ b/pysnmp/hlapi/v3arch/asyncio/__init__.py @@ -7,8 +7,8 @@ from pysnmp.proto.rfc1902 import * from pysnmp.smi.rfc1902 import * from pysnmp.entity.engine import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.asyncio.transport import * -from pysnmp.hlapi.asyncio.cmdgen import * -from pysnmp.hlapi.asyncio.ntforg import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.asyncio.transport import * +from pysnmp.hlapi.v3arch.asyncio.cmdgen import * +from pysnmp.hlapi.v3arch.asyncio.ntforg import * diff --git a/pysnmp/hlapi/asyncio/cmdgen.py b/pysnmp/hlapi/v3arch/asyncio/cmdgen.py similarity index 96% rename from pysnmp/hlapi/asyncio/cmdgen.py rename to pysnmp/hlapi/v3arch/asyncio/cmdgen.py index e449d477..bf97bcd4 100644 --- a/pysnmp/hlapi/asyncio/cmdgen.py +++ b/pysnmp/hlapi/v3arch/asyncio/cmdgen.py @@ -32,12 +32,13 @@ # THE POSSIBILITY OF SUCH DAMAGE. # from pysnmp.smi.rfc1902 import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.lcd import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.lcd import * from pysnmp.hlapi.varbinds import * -from pysnmp.hlapi.asyncio.transport import * +from pysnmp.hlapi.v3arch.asyncio.transport import * from pysnmp.entity.rfc3413 import cmdgen +from pysnmp.proto.api import v2c try: import asyncio @@ -49,7 +50,7 @@ __all__ = ['getCmd', 'nextCmd', 'setCmd', 'bulkCmd', 'isEndOfMib'] vbProcessor = CommandGeneratorVarBinds() lcd = CommandGeneratorLcdConfigurator() -isEndOfMib = lambda x: not cmdgen.getNextVarBinds(x)[1] +isEndOfMib = lambda varBinds: not v2c.apiPDU.getNextVarBinds(varBinds) @asyncio.coroutine @@ -135,7 +136,7 @@ def getCmd(snmpEngine, authData, transportTarget, contextData, if future.cancelled(): return try: - varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, + varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine.cache, varBinds, lookupMib) except Exception as e: future.set_exception(e) @@ -151,7 +152,7 @@ def getCmd(snmpEngine, authData, transportTarget, contextData, cmdgen.GetCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun, + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), future) ) return future @@ -240,7 +241,7 @@ def setCmd(snmpEngine, authData, transportTarget, contextData, if future.cancelled(): return try: - varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, + varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine.cache, varBinds, lookupMib) except Exception as e: future.set_exception(e) @@ -256,7 +257,7 @@ def setCmd(snmpEngine, authData, transportTarget, contextData, cmdgen.SetCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun, + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), future) ) return future @@ -349,7 +350,7 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData, if future.cancelled(): return try: - varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine, + varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine.cache, varBindTableRow, lookupMib) for varBindTableRow in varBindTable] @@ -367,7 +368,7 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData, cmdgen.NextCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun, + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), future) ) return future @@ -489,7 +490,7 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData, if future.cancelled(): return try: - varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine, + varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine.cache, varBindTableRow, lookupMib) for varBindTableRow in varBindTable] @@ -507,7 +508,7 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData, cmdgen.BulkCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, nonRepeaters, maxRepetitions, - vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun, + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), future) ) return future diff --git a/pysnmp/hlapi/asyncio/ntforg.py b/pysnmp/hlapi/v3arch/asyncio/ntforg.py similarity index 77% rename from pysnmp/hlapi/asyncio/ntforg.py rename to pysnmp/hlapi/v3arch/asyncio/ntforg.py index 0bd59b7e..d43bf979 100644 --- a/pysnmp/hlapi/asyncio/ntforg.py +++ b/pysnmp/hlapi/v3arch/asyncio/ntforg.py @@ -9,11 +9,11 @@ # Zachary Lorusso # from pysnmp.smi.rfc1902 import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.lcd import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.lcd import * from pysnmp.hlapi.varbinds import * -from pysnmp.hlapi.asyncio.transport import * +from pysnmp.hlapi.v3arch.asyncio.transport import * from pysnmp.entity.rfc3413 import ntforg try: @@ -29,7 +29,7 @@ lcd = NotificationOriginatorLcdConfigurator() @asyncio.coroutine def sendNotification(snmpEngine, authData, transportTarget, contextData, - notifyType, varBinds, **options): + notifyType, *varBinds, **options): """Creates a generator to send SNMP notification. When iterator gets advanced by :py:mod:`asyncio` main loop, @@ -55,13 +55,30 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, Indicates type of notification to be sent. Recognized literal values are *trap* or *inform*. - varBinds: tuple - Single :py:class:`~pysnmp.smi.rfc1902.NotificationType` class instance - representing a minimum sequence of MIB variables required for - particular notification type. - Alternatively, a sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` - objects could be passed instead. In the latter case it is up to - the user to ensure proper Notification PDU contents. + \*varBinds: :class:`tuple` of OID-value pairs or :py:class:`~pysnmp.smi.rfc1902.ObjectType` or :py:class:`~pysnmp.smi.rfc1902.NotificationType` + One or more objects representing MIB variables to place + into SNMP notification. It could be tuples of OID-values + or :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + of :py:class:`~pysnmp.smi.rfc1902.NotificationType` objects. + + SNMP Notification PDU places rigid requirement on the ordering of + the variable-bindings. + + Mandatory variable-bindings: + + 0. SNMPv2-MIB::sysUpTime.0 = + 1. SNMPv2-SMI::snmpTrapOID.0 = {SNMPv2-MIB::coldStart, ...} + + Optional variable-bindings (applicable to SNMP v1 TRAP): + + 2. SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = + 3. SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = + 4. SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = + + Informational variable-bindings: + + * SNMPv2-SMI::NOTIFICATION-TYPE + * SNMPv2-SMI::OBJECT-TYPE Other Parameters ---------------- @@ -125,7 +142,7 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, if future.cancelled(): return try: - varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, + varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine.cache, varBinds, lookupMib) except Exception as e: future.set_exception(e) @@ -145,7 +162,7 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, notifyName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), future) ) diff --git a/pysnmp/hlapi/asyncio/transport.py b/pysnmp/hlapi/v3arch/asyncio/transport.py similarity index 99% rename from pysnmp/hlapi/asyncio/transport.py rename to pysnmp/hlapi/v3arch/asyncio/transport.py index 4e7b9110..86423dfc 100644 --- a/pysnmp/hlapi/asyncio/transport.py +++ b/pysnmp/hlapi/v3arch/asyncio/transport.py @@ -6,9 +6,10 @@ # import socket import sys + from pysnmp.carrier.asyncio.dgram import udp, udp6 -from pysnmp.hlapi.transport import AbstractTransportTarget from pysnmp.error import PySnmpError +from pysnmp.hlapi.transport import AbstractTransportTarget __all__ = ['Udp6TransportTarget', 'UdpTransportTarget'] diff --git a/pysnmp/hlapi/asyncore/__init__.py b/pysnmp/hlapi/v3arch/asyncore/__init__.py similarity index 52% rename from pysnmp/hlapi/asyncore/__init__.py rename to pysnmp/hlapi/v3arch/asyncore/__init__.py index 303b4b84..9cef379f 100644 --- a/pysnmp/hlapi/asyncore/__init__.py +++ b/pysnmp/hlapi/v3arch/asyncore/__init__.py @@ -6,9 +6,9 @@ # from pysnmp.proto.rfc1902 import * from pysnmp.smi.rfc1902 import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.asyncore.transport import * -from pysnmp.hlapi.asyncore.cmdgen import * -from pysnmp.hlapi.asyncore.ntforg import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.asyncore.transport import * +from pysnmp.hlapi.v3arch.asyncore.cmdgen import * +from pysnmp.hlapi.v3arch.asyncore.ntforg import * from pysnmp.entity.engine import * diff --git a/pysnmp/hlapi/asyncore/cmdgen.py b/pysnmp/hlapi/v3arch/asyncore/cmdgen.py similarity index 93% rename from pysnmp/hlapi/asyncore/cmdgen.py rename to pysnmp/hlapi/v3arch/asyncore/cmdgen.py index 4cedfa82..fac237e2 100644 --- a/pysnmp/hlapi/asyncore/cmdgen.py +++ b/pysnmp/hlapi/v3arch/asyncore/cmdgen.py @@ -6,18 +6,19 @@ # from pysnmp.entity.rfc3413 import cmdgen from pysnmp.smi.rfc1902 import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.lcd import * from pysnmp.hlapi.varbinds import * -from pysnmp.hlapi.asyncore.transport import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.lcd import * +from pysnmp.hlapi.v3arch.asyncore.transport import * +from pysnmp.proto.api import v2c __all__ = ['getCmd', 'nextCmd', 'setCmd', 'bulkCmd', 'isEndOfMib'] vbProcessor = CommandGeneratorVarBinds() lcd = CommandGeneratorLcdConfigurator() -isEndOfMib = lambda x: not cmdgen.getNextVarBinds(x)[1] +isEndOfMib = lambda varBinds: not v2c.apiPDU.getNextVarBinds(varBinds) def getCmd(snmpEngine, authData, transportTarget, contextData, @@ -51,15 +52,14 @@ def getCmd(snmpEngine, authData, transportTarget, contextData, Other Parameters ---------------- \*\*options : - Request options: - * `lookupMib` - load MIB and resolve response MIB variables at - the cost of slightly reduced performance. Default is `True`. - * `cbFun` (callable) - user-supplied callable that is invoked - to pass SNMP response data or error to user at a later point - of time. Default is `None`. - * `cbCtx` (object) - user-supplied object passing additional - parameters to/from `cbFun`. Default is `None`. + * `lookupMib` (bool) - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `True`. + * `cbFun` (callable) - user-supplied callable that is invoked + to pass SNMP response data or error to user at a later point + of time. Default is `None` + * `cbCtx` (object) - user-supplied object passing additional + parameters to/from `cbFun`. Default is `None`. Notes ----- @@ -118,7 +118,7 @@ def getCmd(snmpEngine, authData, transportTarget, contextData, return cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, vbProcessor.unmakeVarBinds( - snmpEngine, varBinds, lookupMib + snmpEngine.cache, varBinds, lookupMib ), cbCtx) addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget) @@ -126,7 +126,7 @@ def getCmd(snmpEngine, authData, transportTarget, contextData, return cmdgen.GetCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun, + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), options.get('cbFun'), options.get('cbCtx')) ) @@ -229,14 +229,14 @@ def setCmd(snmpEngine, authData, transportTarget, contextData, return cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, vbProcessor.unmakeVarBinds( - snmpEngine, varBinds, lookupMib + snmpEngine.cache, varBinds, lookupMib ), cbCtx) addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget) return cmdgen.SetCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, - contextData.contextName, vbProcessor.makeVarBinds(snmpEngine, varBinds), + contextData.contextName, vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), options.get('cbFun'), options.get('cbCtx')) ) @@ -339,7 +339,7 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData, lookupMib, cbFun, cbCtx = cbCtx return cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, - [vbProcessor.unmakeVarBinds(snmpEngine, varBindTableRow, lookupMib) for varBindTableRow in + [vbProcessor.unmakeVarBinds(snmpEngine.cache, varBindTableRow, lookupMib) for varBindTableRow in varBindTable], cbCtx) @@ -347,7 +347,7 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData, return cmdgen.NextCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), options.get('cbFun'), options.get('cbCtx')) ) @@ -478,16 +478,17 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData, errorIndication, errorStatus, errorIndex, varBindTable, cbCtx): lookupMib, cbFun, cbCtx = cbCtx - return cbFun(snmpEngine, sendRequestHandle, errorIndication, + return cbFun(snmpEngine.cache, sendRequestHandle, errorIndication, errorStatus, errorIndex, - [vbProcessor.unmakeVarBinds(snmpEngine, varBindTableRow, lookupMib) for varBindTableRow in + [vbProcessor.unmakeVarBinds(snmpEngine.cache, varBindTableRow, lookupMib) for varBindTableRow in varBindTable], cbCtx) addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget) + return cmdgen.BulkCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, nonRepeaters, maxRepetitions, - vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun, + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), options.get('cbFun'), options.get('cbCtx')) ) diff --git a/pysnmp/hlapi/asyncore/ntforg.py b/pysnmp/hlapi/v3arch/asyncore/ntforg.py similarity index 59% rename from pysnmp/hlapi/asyncore/ntforg.py rename to pysnmp/hlapi/v3arch/asyncore/ntforg.py index ecd418c1..09cb6dfc 100644 --- a/pysnmp/hlapi/asyncore/ntforg.py +++ b/pysnmp/hlapi/v3arch/asyncore/ntforg.py @@ -6,11 +6,11 @@ # from pysnmp.smi.rfc1902 import * from pysnmp.entity.rfc3413 import ntforg -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.lcd import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.lcd import * from pysnmp.hlapi.varbinds import * -from pysnmp.hlapi.asyncore.transport import * +from pysnmp.hlapi.v3arch.asyncore.transport import * __all__ = ['sendNotification'] @@ -19,8 +19,7 @@ lcd = NotificationOriginatorLcdConfigurator() def sendNotification(snmpEngine, authData, transportTarget, contextData, - notifyType, varBinds, cbFun=None, cbCtx=None, - lookupMib=False): + notifyType, *varBinds, **options): """Send SNMP notification. Based on passed parameters, prepares SNMP TRAP or INFORM @@ -47,26 +46,58 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, Indicates type of notification to be sent. Recognized literal values are *trap* or *inform*. - varBinds : tuple - Single :py:class:`~pysnmp.smi.rfc1902.NotificationType` class - instance representing a minimum sequence of MIB variables - required for particular notification type. Alternatively, - a sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` - objects could be passed instead. In the latter case it is up to - the user to ensure proper Notification PDU contents. + \*varBinds: :class:`tuple` of OID-value pairs or :py:class:`~pysnmp.smi.rfc1902.ObjectType` or :py:class:`~pysnmp.smi.rfc1902.NotificationType` + One or more objects representing MIB variables to place + into SNMP notification. It could be tuples of OID-values + or :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + of :py:class:`~pysnmp.smi.rfc1902.NotificationType` objects. + + SNMP Notification PDU includes some housekeeping items that + are required for SNMP to function. + + Agent information: + + * SNMPv2-MIB::sysUpTime.0 = + * SNMPv2-SMI::snmpTrapOID.0 = {SNMPv2-MIB::coldStart, ...} + + Applicable to SNMP v1 TRAP: + + * SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = + * SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = + * SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = + + .. note:: + + Unless user passes some of these variable-bindings, `.sendNotification()` + call will fill in the missing items. + + User variable-bindings: + + * SNMPv2-SMI::NOTIFICATION-TYPE + * SNMPv2-SMI::OBJECT-TYPE + + .. note:: + + The :py:class:`~pysnmp.smi.rfc1902.NotificationType` object ensures + properly formed SNMP notification (to comply MIB definition). If you + build notification PDU out of :py:class:`~pysnmp.smi.rfc1902.ObjectType` + objects or simple tuples of OID-value objects, it is your responsibility + to provide well-formed notificaton payload. Other Parameters ---------------- - cbFun : callable - user-supplied callable that is invoked to pass SNMP response - to *INFORM* notification or error to user at a later point of - time. The `cbFun` callable is never invoked for *TRAP* notifications. - cbCtx : object - user-supplied object passing additional parameters to/from - `cbFun`. - lookupMib : bool - `lookupMib` - load MIB and resolve response MIB variables at - the cost of slightly reduced performance. Default is `True`. + \*\*options: + + * lookupMib: bool + `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `True`. + * cbFun: callable + user-supplied callable that is invoked to pass SNMP response + to *INFORM* notification or error to user at a later point of + time. The `cbFun` callable is never invoked for *TRAP* notifications. + * cbCtx: object + user-supplied object passing additional parameters to/from + `cbFun` Notes ----- @@ -126,7 +157,7 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, vbProcessor.unmakeVarBinds( - snmpEngine, varBinds, lookupMib + snmpEngine.cache, varBinds, lookupMib ), cbCtx ) @@ -136,6 +167,7 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, return ntforg.NotificationOriginator().sendVarBinds( snmpEngine, notifyName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), - __cbFun, (lookupMib, cbFun, cbCtx) + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, + (options.get('lookupMib', True), + options.get('cbFun'), options.get('cbCtx')) ) diff --git a/pysnmp/hlapi/v3arch/asyncore/sync/__init__.py b/pysnmp/hlapi/v3arch/asyncore/sync/__init__.py new file mode 100644 index 00000000..be6f9ec1 --- /dev/null +++ b/pysnmp/hlapi/v3arch/asyncore/sync/__init__.py @@ -0,0 +1,19 @@ +# +# This file is part of pysnmp software. +# +# Copyright (c) 2005-2018, Ilya Etingof +# License: http://snmplabs.com/pysnmp/license.html +# +from pysnmp.proto.rfc1902 import * +from pysnmp.smi.rfc1902 import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.asyncore.transport import * +from pysnmp.entity.engine import * + +try: + from pysnmp.hlapi.v3arch.asyncore.sync.cmdgen import * + from pysnmp.hlapi.v3arch.asyncore.sync.ntforg import * +except SyntaxError: + from pysnmp.hlapi.v3arch.asyncore.sync.compat.cmdgen import * + from pysnmp.hlapi.v3arch.asyncore.sync.compat.ntforg import * diff --git a/pysnmp/hlapi/asyncore/sync/cmdgen.py b/pysnmp/hlapi/v3arch/asyncore/sync/cmdgen.py similarity index 99% rename from pysnmp/hlapi/asyncore/sync/cmdgen.py rename to pysnmp/hlapi/v3arch/asyncore/sync/cmdgen.py index 3868ac66..00848e52 100644 --- a/pysnmp/hlapi/asyncore/sync/cmdgen.py +++ b/pysnmp/hlapi/v3arch/asyncore/sync/cmdgen.py @@ -5,7 +5,7 @@ # License: http://snmplabs.com/pysnmp/license.html # from sys import version_info -from pysnmp.hlapi.asyncore import cmdgen +from pysnmp.hlapi.v3arch.asyncore import cmdgen from pysnmp.hlapi.varbinds import * from pysnmp.proto.rfc1905 import endOfMibView from pysnmp.proto import errind @@ -346,7 +346,7 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData, vbProcessor = CommandGeneratorVarBinds() - initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine, varBinds)] + initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine.cache, varBinds)] totalRows = totalCalls = 0 @@ -408,7 +408,7 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData, if initialVarBinds: varBinds = initialVarBinds - initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine, varBinds)] + initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine.cache, varBinds)] if maxRows and totalRows >= maxRows: return @@ -546,7 +546,7 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData, vbProcessor = CommandGeneratorVarBinds() - initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine, varBinds)] + initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine.cache, varBinds)] nullVarBinds = [False] * len(initialVars) totalRows = totalCalls = 0 @@ -632,4 +632,3 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData, varBinds = initialVarBinds initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine, varBinds)] nullVarBinds = [False] * len(initialVars) - diff --git a/pysnmp/hlapi/asyncore/sync/compat/__init__.py b/pysnmp/hlapi/v3arch/asyncore/sync/compat/__init__.py similarity index 100% rename from pysnmp/hlapi/asyncore/sync/compat/__init__.py rename to pysnmp/hlapi/v3arch/asyncore/sync/compat/__init__.py diff --git a/pysnmp/hlapi/asyncore/sync/compat/cmdgen.py b/pysnmp/hlapi/v3arch/asyncore/sync/compat/cmdgen.py similarity index 98% rename from pysnmp/hlapi/asyncore/sync/compat/cmdgen.py rename to pysnmp/hlapi/v3arch/asyncore/sync/compat/cmdgen.py index 066d1d9f..ff760ee5 100644 --- a/pysnmp/hlapi/asyncore/sync/compat/cmdgen.py +++ b/pysnmp/hlapi/v3arch/asyncore/sync/compat/cmdgen.py @@ -6,7 +6,7 @@ # # This is a Python 2.6- version of the same file at level up # -from pysnmp.hlapi.asyncore import cmdgen +from pysnmp.hlapi.v3arch.asyncore import cmdgen from pysnmp.hlapi.varbinds import * from pysnmp.proto.rfc1905 import endOfMibView from pysnmp.proto import errind @@ -100,7 +100,7 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData, vbProcessor = CommandGeneratorVarBinds() - initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine, varBinds)] + initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine.cache, varBinds)] totalRows = totalCalls = 0 @@ -172,7 +172,7 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData, vbProcessor = CommandGeneratorVarBinds() - initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine, varBinds)] + initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine.cache, varBinds)] nullVarBinds = [False] * len(initialVars) totalRows = totalCalls = 0 diff --git a/pysnmp/hlapi/asyncore/sync/compat/ntforg.py b/pysnmp/hlapi/v3arch/asyncore/sync/compat/ntforg.py similarity index 96% rename from pysnmp/hlapi/asyncore/sync/compat/ntforg.py rename to pysnmp/hlapi/v3arch/asyncore/sync/compat/ntforg.py index 80221713..173dbc95 100644 --- a/pysnmp/hlapi/asyncore/sync/compat/ntforg.py +++ b/pysnmp/hlapi/v3arch/asyncore/sync/compat/ntforg.py @@ -6,7 +6,7 @@ # # This is a Python 2.6- version of the same file at level up # -from pysnmp.hlapi.asyncore import ntforg +from pysnmp.hlapi.v3arch.asyncore import ntforg __all__ = ['sendNotification', 'next'] diff --git a/pysnmp/hlapi/asyncore/sync/ntforg.py b/pysnmp/hlapi/v3arch/asyncore/sync/ntforg.py similarity index 64% rename from pysnmp/hlapi/asyncore/sync/ntforg.py rename to pysnmp/hlapi/v3arch/asyncore/sync/ntforg.py index 6f732d75..8e80a740 100644 --- a/pysnmp/hlapi/asyncore/sync/ntforg.py +++ b/pysnmp/hlapi/v3arch/asyncore/sync/ntforg.py @@ -5,7 +5,7 @@ # License: http://snmplabs.com/pysnmp/license.html # from sys import version_info -from pysnmp.hlapi.asyncore import ntforg +from pysnmp.hlapi.v3arch.asyncore import ntforg __all__ = ['sendNotification'] @@ -18,12 +18,12 @@ if version_info[:2] < (2, 6): def sendNotification(snmpEngine, authData, transportTarget, contextData, - notifyType, varBinds, **options): + notifyType, *varBinds, **options): """Creates a generator to send one or more SNMP notifications. On each iteration, new SNMP TRAP or INFORM notification is send (:RFC:`1905#section-4,2,6`). The iterator blocks waiting for - INFORM acknowlegement to arrive or error to occur. + INFORM acknowledgement to arrive or error to occur. Parameters ---------- @@ -43,21 +43,49 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, Indicates type of notification to be sent. Recognized literal values are *trap* or *inform*. - varBinds: tuple - Single :py:class:`~pysnmp.smi.rfc1902.NotificationType` class instance - representing a minimum sequence of MIB variables required for - particular notification type. - Alternatively, a sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` - objects could be passed instead. In the latter case it is up to - the user to ensure proper Notification PDU contents. + \*varBinds: :class:`tuple` of OID-value pairs or :py:class:`~pysnmp.smi.rfc1902.ObjectType` or :py:class:`~pysnmp.smi.rfc1902.NotificationType` + One or more objects representing MIB variables to place + into SNMP notification. It could be tuples of OID-values + or :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + of :py:class:`~pysnmp.smi.rfc1902.NotificationType` objects. + + SNMP Notification PDU includes some housekeeping items that + are required for SNMP to function. + + Agent information: + + * SNMPv2-MIB::sysUpTime.0 = + * SNMPv2-SMI::snmpTrapOID.0 = {SNMPv2-MIB::coldStart, ...} + + Applicable to SNMP v1 TRAP: + + * SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = + * SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = + * SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = + + .. note:: + + Unless user passes some of these variable-bindings, `.sendNotification()` + call will fill in the missing items. + + User variable-bindings: + + * SNMPv2-SMI::NOTIFICATION-TYPE + * SNMPv2-SMI::OBJECT-TYPE + + .. note:: + + The :py:class:`~pysnmp.smi.rfc1902.NotificationType` object ensures + properly formed SNMP notification (to comply MIB definition). If you + build notification PDU out of :py:class:`~pysnmp.smi.rfc1902.ObjectType` + objects or simple tuples of OID-value objects, it is your responsibility + to provide well-formed notificaton payload. Other Parameters ---------------- - \*\*options : - Request options: - - * `lookupMib` - load MIB and resolve response MIB variables at - the cost of slightly reduced performance. Default is `True`. + \*\*options: + * `lookupMib` - load MIB and resolve response MIB variables at + the cost of slightly reduced performance. Default is `True`. Yields ------ @@ -79,7 +107,7 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, Notes ----- - The `sendNotification` generator will be exhausted immidiately unless + The `sendNotification` generator will be exhausted immediately unless an instance of :py:class:`~pysnmp.smi.rfc1902.NotificationType` class or a sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` `varBinds` are send back into running generator (supported since Python 2.6). @@ -113,8 +141,8 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, while True: if varBinds: ntforg.sendNotification(snmpEngine, authData, transportTarget, - contextData, notifyType, varBinds, - cbFun, cbCtx, + contextData, notifyType, *varBinds, + cbFun=cbFun, cbCtx=cbCtx, lookupMib=options.get('lookupMib', True)) snmpEngine.transportDispatcher.runDispatcher() diff --git a/pysnmp/hlapi/asyncore/transport.py b/pysnmp/hlapi/v3arch/asyncore/transport.py similarity index 97% rename from pysnmp/hlapi/asyncore/transport.py rename to pysnmp/hlapi/v3arch/asyncore/transport.py index 2c103632..6019bd02 100644 --- a/pysnmp/hlapi/asyncore/transport.py +++ b/pysnmp/hlapi/v3arch/asyncore/transport.py @@ -6,9 +6,10 @@ # import socket import sys + +from pysnmp import error from pysnmp.carrier.asyncore.dgram import udp, udp6 from pysnmp.hlapi.transport import AbstractTransportTarget -from pysnmp import error __all__ = ['Udp6TransportTarget', 'UdpTransportTarget'] @@ -42,7 +43,7 @@ class UdpTransportTarget(AbstractTransportTarget): Examples -------- - >>> from pysnmp.hlapi.asyncore import UdpTransportTarget + >>> from pysnmp.hlapi.v3arch.asyncore import UdpTransportTarget >>> UdpTransportTarget(('demo.snmplabs.com', 161)) UdpTransportTarget(('195.218.195.228', 161), timeout=1, retries=5, tagList='') >>> @@ -92,7 +93,7 @@ class Udp6TransportTarget(AbstractTransportTarget): Examples -------- - >>> from pysnmp.hlapi.asyncore import Udp6TransportTarget + >>> from pysnmp.hlapi.v3arch.asyncore import Udp6TransportTarget >>> Udp6TransportTarget(('google.com', 161)) Udp6TransportTarget(('2a00:1450:4014:80a::100e', 161), timeout=1, retries=5, tagList='') >>> Udp6TransportTarget(('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', 161)) diff --git a/pysnmp/hlapi/auth.py b/pysnmp/hlapi/v3arch/auth.py similarity index 100% rename from pysnmp/hlapi/auth.py rename to pysnmp/hlapi/v3arch/auth.py diff --git a/pysnmp/hlapi/context.py b/pysnmp/hlapi/v3arch/context.py similarity index 100% rename from pysnmp/hlapi/context.py rename to pysnmp/hlapi/v3arch/context.py diff --git a/pysnmp/hlapi/lcd.py b/pysnmp/hlapi/v3arch/lcd.py similarity index 99% rename from pysnmp/hlapi/lcd.py rename to pysnmp/hlapi/v3arch/lcd.py index 94c10abf..3c11635e 100644 --- a/pysnmp/hlapi/lcd.py +++ b/pysnmp/hlapi/v3arch/lcd.py @@ -6,7 +6,7 @@ # from pysnmp.entity import config from pysnmp import nextid, error -from pysnmp.hlapi.auth import * +from pysnmp.hlapi.v3arch.auth import * __all__ = ['CommandGeneratorLcdConfigurator', 'NotificationOriginatorLcdConfigurator'] diff --git a/pysnmp/hlapi/v3arch/twisted/__init__.py b/pysnmp/hlapi/v3arch/twisted/__init__.py new file mode 100644 index 00000000..f141bf55 --- /dev/null +++ b/pysnmp/hlapi/v3arch/twisted/__init__.py @@ -0,0 +1,8 @@ +from pysnmp.proto.rfc1902 import * +from pysnmp.smi.rfc1902 import * +from pysnmp.entity.engine import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.twisted.transport import * +from pysnmp.hlapi.v3arch.twisted.cmdgen import * +from pysnmp.hlapi.v3arch.twisted.ntforg import * diff --git a/pysnmp/hlapi/twisted/cmdgen.py b/pysnmp/hlapi/v3arch/twisted/cmdgen.py similarity index 96% rename from pysnmp/hlapi/twisted/cmdgen.py rename to pysnmp/hlapi/v3arch/twisted/cmdgen.py index 94490527..745ce9d2 100644 --- a/pysnmp/hlapi/twisted/cmdgen.py +++ b/pysnmp/hlapi/v3arch/twisted/cmdgen.py @@ -5,13 +5,14 @@ # License: http://snmplabs.com/pysnmp/license.html # from pysnmp.smi.rfc1902 import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.lcd import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.lcd import * from pysnmp.hlapi.varbinds import * -from pysnmp.hlapi.twisted.transport import * +from pysnmp.hlapi.v3arch.twisted.transport import * from pysnmp.entity.rfc3413 import cmdgen from pysnmp.proto import errind +from pysnmp.proto.api import v2c from twisted.internet.defer import Deferred from twisted.python.failure import Failure @@ -20,7 +21,8 @@ __all__ = ['getCmd', 'nextCmd', 'setCmd', 'bulkCmd', 'isEndOfMib'] vbProcessor = CommandGeneratorVarBinds() lcd = CommandGeneratorLcdConfigurator() -isEndOfMib = lambda x: not cmdgen.getNextVarBinds(x)[1] +isEndOfMib = lambda varBinds: not v2c.apiPDU.getNextVarBinds(varBinds) + def getCmd(snmpEngine, authData, transportTarget, contextData, *varBinds, **options): @@ -118,7 +120,7 @@ def getCmd(snmpEngine, authData, transportTarget, contextData, deferred.errback(Failure(errorIndication)) else: try: - varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookupMib) + varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine.cache, varBinds, lookupMib) except Exception as e: deferred.errback(Failure(e)) @@ -133,7 +135,7 @@ def getCmd(snmpEngine, authData, transportTarget, contextData, cmdgen.GetCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun, + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), deferred) ) return deferred @@ -234,7 +236,7 @@ def setCmd(snmpEngine, authData, transportTarget, contextData, deferred.errback(Failure(errorIndication)) else: try: - varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookupMib) + varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine.cache, varBinds, lookupMib) except Exception as e: deferred.errback(Failure(e)) @@ -249,7 +251,7 @@ def setCmd(snmpEngine, authData, transportTarget, contextData, cmdgen.SetCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun, + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), deferred) ) return deferred @@ -361,7 +363,7 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData, deferred.errback(Failure(errorIndication)) else: try: - varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine, + varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine.cache, varBindTableRow, lookupMib) for varBindTableRow in varBindTable] @@ -379,7 +381,7 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData, cmdgen.NextCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun, + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), deferred) ) return deferred @@ -519,7 +521,7 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData, deferred.errback(Failure(errorIndication)) else: try: - varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine, + varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine.cache, varBindTableRow, lookupMib) for varBindTableRow in varBindTable] @@ -537,7 +539,7 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData, cmdgen.BulkCommandGenerator().sendVarBinds( snmpEngine, addrName, contextData.contextEngineId, contextData.contextName, nonRepeaters, maxRepetitions, - vbProcessor.makeVarBinds(snmpEngine, varBinds), + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), deferred) ) diff --git a/pysnmp/hlapi/twisted/ntforg.py b/pysnmp/hlapi/v3arch/twisted/ntforg.py similarity index 66% rename from pysnmp/hlapi/twisted/ntforg.py rename to pysnmp/hlapi/v3arch/twisted/ntforg.py index fbbdc0f1..0f57068d 100644 --- a/pysnmp/hlapi/twisted/ntforg.py +++ b/pysnmp/hlapi/v3arch/twisted/ntforg.py @@ -5,11 +5,11 @@ # License: http://snmplabs.com/pysnmp/license.html # from pysnmp.smi.rfc1902 import * -from pysnmp.hlapi.auth import * -from pysnmp.hlapi.context import * -from pysnmp.hlapi.lcd import * +from pysnmp.hlapi.v3arch.auth import * +from pysnmp.hlapi.v3arch.context import * +from pysnmp.hlapi.v3arch.lcd import * from pysnmp.hlapi.varbinds import * -from pysnmp.hlapi.twisted.transport import * +from pysnmp.hlapi.v3arch.twisted.transport import * from pysnmp.entity.rfc3413 import ntforg from twisted.internet import reactor from twisted.internet.defer import Deferred @@ -21,7 +21,7 @@ vbProcessor = NotificationOriginatorVarBinds() lcd = NotificationOriginatorLcdConfigurator() def sendNotification(snmpEngine, authData, transportTarget, contextData, - notifyType, varBinds, **options): + notifyType, *varBinds, **options): """Sends SNMP notification. Based on passed parameters, prepares SNMP TRAP or INFORM message @@ -30,29 +30,59 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, Parameters ---------- - snmpEngine : :py:class:`~pysnmp.hlapi.SnmpEngine` + snmpEngine: :py:class:`~pysnmp.hlapi.SnmpEngine` Class instance representing SNMP engine. - authData : :py:class:`~pysnmp.hlapi.CommunityData` or :py:class:`~pysnmp.hlapi.UsmUserData` + authData: :py:class:`~pysnmp.hlapi.CommunityData` or :py:class:`~pysnmp.hlapi.UsmUserData` Class instance representing SNMP credentials. transportTarget : :py:class:`~pysnmp.hlapi.twisted.UdpTransportTarget` or :py:class:`~pysnmp.hlapi.twisted.Udp6TransportTarget` Class instance representing transport type along with SNMP peer address. - contextData : :py:class:`~pysnmp.hlapi.ContextData` + contextData: :py:class:`~pysnmp.hlapi.ContextData` Class instance representing SNMP ContextEngineId and ContextName values. - notifyType : str + notifyType: str Indicates type of notification to be sent. Recognized literal values are *trap* or *inform*. - varBinds: tuple - Single :py:class:`~pysnmp.smi.rfc1902.NotificationType` class instance - representing a minimum sequence of MIB variables required for - particular notification type. - Alternatively, a sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` - objects could be passed instead. In the latter case it is up to - the user to ensure proper Notification PDU contents. + \*varBinds: :class:`tuple` of OID-value pairs or :py:class:`~pysnmp.smi.rfc1902.ObjectType` or :py:class:`~pysnmp.smi.rfc1902.NotificationType` + One or more objects representing MIB variables to place + into SNMP notification. It could be tuples of OID-values + or :py:class:`~pysnmp.smi.rfc1902.ObjectType` class instances + of :py:class:`~pysnmp.smi.rfc1902.NotificationType` objects. + + SNMP Notification PDU includes some housekeeping items that + are required for SNMP to function. + + Agent information: + + * SNMPv2-MIB::sysUpTime.0 = + * SNMPv2-SMI::snmpTrapOID.0 = {SNMPv2-MIB::coldStart, ...} + + Applicable to SNMP v1 TRAP: + + * SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = + * SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = + * SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = + + .. note:: + + Unless user passes some of these variable-bindings, `.sendNotification()` + call will fill in the missing items. + + User variable-bindings: + + * SNMPv2-SMI::NOTIFICATION-TYPE + * SNMPv2-SMI::OBJECT-TYPE + + .. note:: + + The :py:class:`~pysnmp.smi.rfc1902.NotificationType` object ensures + properly formed SNMP notification (to comply MIB definition). If you + build notification PDU out of :py:class:`~pysnmp.smi.rfc1902.ObjectType` + objects or simple tuples of OID-value objects, it is your responsibility + to provide well-formed notificaton payload. Other Parameters ---------------- @@ -126,7 +156,9 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, deferred.errback(Failure(errorIndication)) else: try: - varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookupMib) + varBindsUnmade = vbProcessor.unmakeVarBinds( + snmpEngine.cache, varBinds, lookupMib + ) except Exception as e: deferred.errback(Failure(e)) @@ -148,7 +180,7 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData, notifyName, contextData.contextEngineId, contextData.contextName, - vbProcessor.makeVarBinds(snmpEngine, varBinds), + vbProcessor.makeVarBinds(snmpEngine.cache, varBinds), __cbFun, (options.get('lookupMib', True), deferred) ) diff --git a/pysnmp/hlapi/twisted/transport.py b/pysnmp/hlapi/v3arch/twisted/transport.py similarity index 98% rename from pysnmp/hlapi/twisted/transport.py rename to pysnmp/hlapi/v3arch/twisted/transport.py index aeea22da..0db45a70 100644 --- a/pysnmp/hlapi/twisted/transport.py +++ b/pysnmp/hlapi/v3arch/twisted/transport.py @@ -4,10 +4,12 @@ # Copyright (c) 2005-2018, Ilya Etingof # License: http://snmplabs.com/pysnmp/license.html # -import socket, sys +import socket +import sys + from pysnmp.carrier.twisted.dgram import udp -from pysnmp.hlapi.transport import AbstractTransportTarget from pysnmp.error import PySnmpError +from pysnmp.hlapi.transport import AbstractTransportTarget __all__ = ['UdpTransportTarget'] diff --git a/pysnmp/hlapi/varbinds.py b/pysnmp/hlapi/varbinds.py index ac9151a8..6c0c2905 100644 --- a/pysnmp/hlapi/varbinds.py +++ b/pysnmp/hlapi/varbinds.py @@ -4,68 +4,86 @@ # Copyright (c) 2005-2018, Ilya Etingof # License: http://snmplabs.com/pysnmp/license.html # -from pysnmp.smi import view from pysnmp.smi.rfc1902 import * +from pysnmp.smi import builder +from pysnmp.smi import view __all__ = ['CommandGeneratorVarBinds', 'NotificationOriginatorVarBinds'] -class AbstractVarBinds(object): +class MibViewControllerManager(object): @staticmethod - def getMibViewController(snmpEngine): - mibViewController = snmpEngine.getUserContext('mibViewController') - if not mibViewController: - mibViewController = view.MibViewController( - snmpEngine.getMibBuilder() - ) - snmpEngine.setUserContext(mibViewController=mibViewController) + def getMibViewController(userCache): + try: + mibViewController = userCache['mibViewController'] + + except KeyError: + mibViewController = view.MibViewController(builder.MibBuilder()) + userCache['mibViewController'] = mibViewController + return mibViewController -class CommandGeneratorVarBinds(AbstractVarBinds): - def makeVarBinds(self, snmpEngine, varBinds): - mibViewController = self.getMibViewController(snmpEngine) - __varBinds = [] +class CommandGeneratorVarBinds(MibViewControllerManager): + def makeVarBinds(self, userCache, varBinds): + mibViewController = self.getMibViewController(userCache) + + resolvedVarBinds = [] + for varBind in varBinds: if isinstance(varBind, ObjectType): pass + elif isinstance(varBind[0], ObjectIdentity): varBind = ObjectType(*varBind) + elif isinstance(varBind[0][0], tuple): # legacy varBind = ObjectType(ObjectIdentity(varBind[0][0][0], varBind[0][0][1], *varBind[0][1:]), varBind[1]) + else: varBind = ObjectType(ObjectIdentity(varBind[0]), varBind[1]) - __varBinds.append(varBind.resolveWithMib(mibViewController)) + resolvedVarBinds.append(varBind.resolveWithMib(mibViewController)) - return __varBinds + return resolvedVarBinds - def unmakeVarBinds(self, snmpEngine, varBinds, lookupMib=True): + def unmakeVarBinds(self, userCache, varBinds, lookupMib=True): if lookupMib: - mibViewController = self.getMibViewController(snmpEngine) + mibViewController = self.getMibViewController(userCache) varBinds = [ObjectType(ObjectIdentity(x[0]), x[1]).resolveWithMib(mibViewController) for x in varBinds] return varBinds -class NotificationOriginatorVarBinds(AbstractVarBinds): - def makeVarBinds(self, snmpEngine, varBinds): - mibViewController = self.getMibViewController(snmpEngine) +class NotificationOriginatorVarBinds(MibViewControllerManager): + def makeVarBinds(self, userCache, varBinds): + mibViewController = self.getMibViewController(userCache) + if isinstance(varBinds, NotificationType): - varBinds.resolveWithMib(mibViewController) - __varBinds = [] + return varBinds.resolveWithMib(mibViewController) + + resolvedVarBinds = [] + for varBind in varBinds: + if isinstance(varBind, NotificationType): + resolvedVarBinds.extend(varBind.resolveWithMib(mibViewController)) + continue + if isinstance(varBind, ObjectType): pass + elif isinstance(varBind[0], ObjectIdentity): varBind = ObjectType(*varBind) + else: varBind = ObjectType(ObjectIdentity(varBind[0]), varBind[1]) - __varBinds.append(varBind.resolveWithMib(mibViewController)) - return __varBinds - def unmakeVarBinds(self, snmpEngine, varBinds, lookupMib=False): + resolvedVarBinds.append(varBind.resolveWithMib(mibViewController)) + + return resolvedVarBinds + + def unmakeVarBinds(self, userCache, varBinds, lookupMib=False): if lookupMib: - mibViewController = self.getMibViewController(snmpEngine) + mibViewController = self.getMibViewController(userCache) varBinds = [ObjectType(ObjectIdentity(x[0]), x[1]).resolveWithMib(mibViewController) for x in varBinds] return varBinds diff --git a/pysnmp/proto/api/v1.py b/pysnmp/proto/api/v1.py index 709a0b68..e6a138df 100644 --- a/pysnmp/proto/api/v1.py +++ b/pysnmp/proto/api/v1.py @@ -139,12 +139,20 @@ class PDUAPI(object): def getVarBindTable(self, reqPDU, rspPDU): if apiPDU.getErrorStatus(rspPDU) == 2: - varBindRow = [] - for varBind in apiPDU.getVarBinds(reqPDU): - varBindRow.append((varBind[0], null)) - return [varBindRow] + varBindRow = [(vb[0], null) for vb in apiPDU.getVarBinds(reqPDU)] else: - return [apiPDU.getVarBinds(rspPDU)] + varBindRow = apiPDU.getVarBinds(rspPDU) + return [varBindRow] + + def getNextVarBinds(self, varBinds, errorIndex=None): + errorIndication = None + + if errorIndex: + return errorIndication, [] + + rspVarBinds = [(vb[0], null) for vb in varBinds] + + return errorIndication, rspVarBinds apiPDU = PDUAPI() diff --git a/pysnmp/proto/api/v2c.py b/pysnmp/proto/api/v2c.py index eec78e79..cf381ced 100644 --- a/pysnmp/proto/api/v2c.py +++ b/pysnmp/proto/api/v2c.py @@ -60,6 +60,25 @@ class PDUAPI(v1.PDUAPI): def getVarBindTable(self, reqPDU, rspPDU): return [apiPDU.getVarBinds(rspPDU)] + def getNextVarBinds(self, varBinds, errorIndex=None): + errorIndication = None + + rspVarBinds = [] + + if errorIndex: + return errorIndication, rspVarBinds + + for idx, varBind in enumerate(varBinds): + if varBind[1].tagSet in ( + rfc1905.NoSuchObject.tagSet, + rfc1905.NoSuchInstance.tagSet, + rfc1905.EndOfMibView.tagSet): + continue + + rspVarBinds.append((varBind[0], null)) + + return errorIndication, rspVarBinds + def setEndOfMibError(self, pdu, errorIndex): varBindList = self.getVarBindList(pdu) varBindList[errorIndex - 1].setComponentByPosition( @@ -115,10 +134,15 @@ class BulkPDUAPI(PDUAPI): reqVarBinds = self.getVarBinds(reqPDU) N = min(int(nonRepeaters), len(reqVarBinds)) - R = max(len(reqVarBinds) - N, 0) rspVarBinds = self.getVarBinds(rspPDU) + # shortcut for the most trivial case + if N == 0 and len(reqVarBinds) == 1: + return [[vb] for vb in rspVarBinds] + + R = max(len(reqVarBinds) - N, 0) + varBindTable = [] if R: diff --git a/runtests.sh b/runtests.sh index 9143a769..fcb23f17 100755 --- a/runtests.sh +++ b/runtests.sh @@ -4,10 +4,14 @@ set -e PYTHON=${1:-python} -for x in examples/hlapi/asyncore/sync/manager/cmdgen/*.py \ - examples/hlapi/asyncore/sync/agent/ntforg/*.py \ - examples/hlapi/asyncore/manager/cmdgen/*.py \ - examples/hlapi/asyncore/agent/ntforg/*.py \ +for x in examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/*.py \ + examples/hlapi/v3arch/asyncore/sync/agent/ntforg/*.py \ + examples/hlapi/v3arch/asyncore/manager/cmdgen/*.py \ + examples/hlapi/v3arch/asyncore/agent/ntforg/*.py \ + examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/*.py \ + examples/hlapi/v1arch/asyncore/sync/agent/ntforg/*.py \ + examples/hlapi/v1arch/asyncore/manager/cmdgen/*.py \ + examples/hlapi/v1arch/asyncore/agent/ntforg/*.py \ examples/v3arch/asyncore/manager/cmdgen/*.py \ examples/v3arch/asyncore/agent/ntforg/*.py \ examples/v1arch/asyncore/manager/cmdgen/*.py \ diff --git a/setup.py b/setup.py index 412e667a..7b9df3fb 100644 --- a/setup.py +++ b/setup.py @@ -152,11 +152,14 @@ params.update({ 'pysnmp.entity', 'pysnmp.entity.rfc3413', 'pysnmp.hlapi', - 'pysnmp.hlapi.asyncio', - 'pysnmp.hlapi.asyncore', - 'pysnmp.hlapi.asyncore.sync', - 'pysnmp.hlapi.asyncore.sync.compat', - 'pysnmp.hlapi.twisted', + 'pysnmp.hlapi.v1arch', + 'pysnmp.hlapi.v1arch.asyncore', + 'pysnmp.hlapi.v3arch', + 'pysnmp.hlapi.v3arch.asyncio', + 'pysnmp.hlapi.v3arch.asyncore', + 'pysnmp.hlapi.v3arch.asyncore.sync', + 'pysnmp.hlapi.v3arch.asyncore.sync.compat', + 'pysnmp.hlapi.v3arch.twisted', 'pysnmp.proto', 'pysnmp.proto.mpmod', 'pysnmp.proto.secmod',