summaryrefslogtreecommitdiff
path: root/examples/v3arch/asyncore/oneliner/agent/ntforg
diff options
context:
space:
mode:
Diffstat (limited to 'examples/v3arch/asyncore/oneliner/agent/ntforg')
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-async-multiple-snmp-engines.py88
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-async-multiple-transports-and-protocols.py60
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py87
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py94
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py87
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3.py87
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/trap-async-multiple-transports-and-protocols.py51
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-custom-values.py82
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-default-values.py76
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py60
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py78
11 files changed, 557 insertions, 293 deletions
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-async-multiple-snmp-engines.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-async-multiple-snmp-engines.py
new file mode 100644
index 0000000..aa96c1e
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-async-multiple-snmp-engines.py
@@ -0,0 +1,88 @@
+"""
+Multiple SNMP Engines
++++++++++++++++++++++
+
+Send SNMP notifications in behalf of multiple independend SNMP engines
+using the following options:
+
+* with a single transport dispatcher and two independent SNMP engines
+* SNMPv2c and SNMPv3
+* with community name 'public' or USM username usr-md5-des
+* over IPv4/UDP
+* send IMFORM notification
+* to multiple Managers
+* with TRAP ID 'coldStart' specified as a MIB symbol
+* include managed object information specified as var-bind objects pair
+
+Within this script we have a single asynchronous TransportDispatcher
+and a single UDP-based transport serving two independent SNMP engines.
+We use a single instance of AsyncNotificationOriginator with each of
+SNMP Engines to communicate INFORM notification to remote systems.
+
+When we receive a [response] message from remote system we use
+a custom message router to choose what of the two SNMP engines
+data packet should be handed over. The selection criteria we
+employ here is based on peer's UDP port number. Other selection
+criterias are also possible.
+
+"""#
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
+from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher
+
+# List of targets in the following format:
+# ( ( authData, transportTarget ), ... )
+targets = (
+ # 1-st target (SNMPv2c over IPv4/UDP)
+ ( CommunityData('public'),
+ UdpTransportTarget(('localhost', 1162)),
+ ContextData() ),
+ # 2-nd target (SNMPv3 over IPv4/UDP)
+ ( UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData() ),
+)
+
+def cbFun(snmpEngine, sendRequestHandle, errorIndication,
+ errorStatus, errorIndex, varBinds, cbCtx):
+ snmpEngine = cbCtx
+ if errorIndication:
+ print('Notification %s for %s not sent: %s' % (sendRequestHandle, snmpEngine.snmpEngineID.prettyPrint(), errorIndication))
+ elif errorStatus:
+ print('Notification Receiver returned error for request %s, SNMP Engine %s: %s @%s' % (sendRequestHandle, snmpEngine.snmpEngineID.prettyPrint(), errorStatus, errorIndex))
+ else:
+ print('Notification %s for SNMP Engine %s delivered:' % (sendRequestHandle, snmpEngine.snmpEngineID.prettyPrint()))
+ for name, val in varBinds:
+ print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+# Instantiate the single transport dispatcher object
+transportDispatcher = AsyncoreDispatcher()
+
+# Setup a custom data routing function to select snmpEngine by transportDomain
+transportDispatcher.registerRoutingCbFun(
+ lambda td,ta,d: ta[1] % 3 and 'A' or 'B'
+)
+
+snmpEngineA = engine.SnmpEngine()
+snmpEngineA.registerTransportDispatcher(transportDispatcher, 'A')
+
+snmpEngineB = engine.SnmpEngine()
+snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B')
+
+ntfOrg = AsyncNotificationOriginator()
+
+for authData, transportTarget, contextData in targets:
+ snmpEngine = transportTarget.getTransportInfo()[1][1] % 3 and \
+ snmpEngineA or snmpEngineB
+ sendPduHandle = ntfOrg.sendNotification(
+ snmpEngine,
+ authData,
+ transportTarget,
+ contextData,
+ 'inform', # NotifyType
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ),
+ cbInfo=(cbFun, snmpEngine)
+ )
+
+transportDispatcher.runDispatcher()
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-async-multiple-transports-and-protocols.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-async-multiple-transports-and-protocols.py
new file mode 100644
index 0000000..cfa2acd
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-async-multiple-transports-and-protocols.py
@@ -0,0 +1,60 @@
+"""
+Multiple concurrent notifications
++++++++++++++++++++++++++++++++++
+
+Send multiple SNMP notifications at once using the following options:
+
+* SNMPv2c and SNMPv3
+* with community name 'public' or USM username usr-md5-des
+* over IPv4/UDP
+* send INFORM notification
+* to multiple Managers
+* with TRAP ID 'coldStart' specified as a MIB symbol
+* include managed object information specified as var-bind objects pair
+
+"""#
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
+
+# List of targets in the followin format:
+# ( ( authData, transportTarget ), ... )
+targets = (
+ # 1-st target (SNMPv2c over IPv4/UDP)
+ ( CommunityData('public'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData() ),
+ # 2-nd target (SNMPv3 over IPv4/UDP)
+ ( UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData() ),
+)
+
+def cbFun(snmpEngine, sendRequestHandle, errorIndication,
+ errorStatus, errorIndex, varBinds, cbctx):
+ if errorIndication:
+ print('Notification %s not sent: %s' % (sendRequestHandle, errorIndication))
+ elif errorStatus:
+ print('Notification Receiver returned error for %s: %s @%s' %
+ (sendRequestHandle, errorStatus, errorIndex))
+ else:
+ print('Notification %s delivered:' % sendRequestHandle)
+ for name, val in varBinds:
+ print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+
+snmpEngine = engine.SnmpEngine()
+
+ntfOrg = AsyncNotificationOriginator()
+
+for authData, transportTarget, contextData in targets:
+ sendPduHandle = ntfOrg.sendNotification(
+ snmpEngine,
+ authData,
+ transportTarget,
+ contextData,
+ 'inform', # NotifyType
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ),
+ cbInfo=(cbFun, None)
+ )
+
+snmpEngine.transportDispatcher.runDispatcher()
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py
index 6eebaa9..4d99a12 100644
--- a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py
@@ -1,42 +1,49 @@
-#
-# Notification Originator
-#
-# Send SNMP notification using the following options:
-#
-# * SNMPv2c
-# * with community name 'public'
-# * over IPv4/UDP
-# * send INFORM notification
-# * with TRAP ID 'coldStart' specified as a MIB symbol
-# * include managed object information specified as a MIB symbol
-# * perform response OIDs and values resolution at MIB
-#
+"""
+Sending additional var-binds
+++++++++++++++++++++++++++++
+
+Send SNMP notification using the following options:
+
+* SNMPv2c
+* with community name 'public'
+* over IPv4/UDP
+* send INFORM notification
+* with TRAP ID 'coldStart' specified as a MIB symbol
+* include managed object information specified as a MIB symbol
+
+Functionally similar to:
+
+| $ snmpinform -v2c -c public
+| demo.snmplabs.com \
+| 12345 \
+| 1.3.6.1.6.3.1.1.5.1 \
+| 1.3.6.1.2.1.1.1.0 s 'my system'
+
+"""#
from pysnmp.entity.rfc3413.oneliner.ntforg import *
-for errorIndication, \
- errorStatus, errorIndex, \
- varBinds in \
- sendNotification(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('localhost', 162)),
- ContextData(),
- 'inform',
- NotificationType(
- ObjectIdentity('SNMPv2-MIB', 'coldStart')
- ).addVarBinds(
- ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'my system') )
- ),
- lookupNames=True, lookupValues=True):
- # Check for errors and print out results
- if errorIndication:
- print(errorIndication)
- else:
- if 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 ]))
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ sendNotification(SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'inform',
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds(
+ ObjectType(ObjectIdentity('SNMPv2-MIB','sysName',0),
+ '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/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py
index 071c336..0c75c21 100644
--- a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py
@@ -1,46 +1,50 @@
-#
-# Notification Originator
-#
-# Send SNMP notification using the following options:
-#
-# * SNMPv3
-# * with user 'usr-md5-none', MD5 auth, no priv
-# * send INFORM notification
-# * in behalf of contextEngineId 0x8000000004030201, contextName ''
-# * over IPv4/UDP
-# * with TRAP ID 'warmStart' specified as a string OID
-#
-# Sending SNMPv3 Notification in behalf of non-default ContextEngineId
-# requires having a collection of Managed Objects registered under
-# the ContextEngineId being used.
-#
+"""
+INFORM with custom ContextEngineId
+++++++++++++++++++++++++++++++++++
+
+Send SNMP notification using the following options:
+
+* SNMPv3
+* with user 'usr-md5-none', MD5 auth, no priv
+* send INFORM notification
+* in behalf of contextEngineId 0x8000000004030201, contextName ''
+* over IPv4/UDP
+* with TRAP ID 'warmStart' specified as a string OID
+
+Sending SNMPv3 Notification in behalf of non-default ContextEngineId
+requires having a collection of Managed Objects registered under
+the ContextEngineId being used.
+
+Functionally similar to:
+
+| $ snmpinform -v3 -l authNoPriv -u usr-md5-none -A authkey1 \
+| -E 0x8000000004030201
+| demo.snmplabs.com \
+| 12345 \
+| 1.3.6.1.6.3.1.1.5.2
+
+"""#
from pysnmp.entity.rfc3413.oneliner.ntforg import *
-from pysnmp.proto import rfc1902
-
-for errorIndication, \
- errorStatus, errorIndex, \
- varBinds in \
- sendNotification(SnmpEngine(),
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(('localhost', 162)),
- ContextData(
- rfc1902.OctetString(hexValue='8000000004030201')
- ),
- 'inform',
- NotificationType(
- ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
- ),
- lookupNames=True, lookupValues=True):
- # Check for errors and print out results
- if errorIndication:
- print(errorIndication)
- else:
- if 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 ]))
+
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ sendNotification(SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(
+ rfc1902.OctetString(hexValue='8000000004030201')
+ ),
+ 'inform',
+ NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2')))
+)
+
+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/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py
index ed87fdc..1b3e1f8 100644
--- a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py
@@ -1,43 +1,48 @@
-#
-# Notification Originator
-#
-# Send SNMP notification using the following options:
-#
-# * SNMPv3
-# * with user 'usr-md5-none', MD5 auth, no priv
-# * send INFORM notification
-# * in behalf of contextEngineId = SnmpEngineId, contextName 'my-context'
-# * over IPv4/UDP
-# * with TRAP ID 'warmStart' specified as a string OID
-#
-# Sending SNMPv3 Notification in behalf of non-default ContextName
-# requires having a collection of Managed Objects registered under
-# the ContextName being used.
-#
+"""
+INFORM with custom ContextName
+++++++++++++++++++++++++++++++
+
+Send SNMP notification using the following options:
+
+* SNMPv3
+* with user 'usr-md5-none', MD5 auth, no priv
+* send INFORM notification
+* in behalf of contextEngineId = SnmpEngineId, contextName 'my-context'
+* over IPv4/UDP
+* with TRAP ID 'warmStart' specified as a string OID
+
+Sending SNMPv3 Notification in behalf of non-default ContextName
+requires having a collection of Managed Objects registered under
+the ContextName being used.
+
+Functionally similar to:
+
+| $ snmpinform -v3 -l authNoPriv -u usr-md5-none -A authkey1 \
+| -n my-context \
+| demo.snmplabs.com \
+| 12345 \
+| 1.3.6.1.6.3.1.1.5.2
+
+"""#
from pysnmp.entity.rfc3413.oneliner.ntforg import *
-for errorIndication, \
- errorStatus, errorIndex, \
- varBinds in \
- sendNotification(SnmpEngine(),
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(('localhost', 162)),
- ContextData(contextName='my-context'),
- 'inform',
- NotificationType(
- ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
- ),
- lookupNames=True, lookupValues=True):
- # Check for errors and print out results
- if errorIndication:
- print(errorIndication)
- else:
- if 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 ]))
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ sendNotification(SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(contextName='my-context'),
+ 'inform',
+ NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2')))
+)
+
+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/v3arch/asyncore/oneliner/agent/ntforg/inform-v3.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3.py
index 2996eb5..161427a 100644
--- a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3.py
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3.py
@@ -1,44 +1,49 @@
-##
-# Notification Originator
-#
-# Send SNMP notification using the following options:
-#
-# * SNMPv3
-# * with user 'usr-md5-des', auth: MD5, priv DES
-# * 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'
-#
+"""
+INFORM, auth: MD5 privacy: DES
+++++++++++++++++++++++++++++++
+
+Send SNMP INFORM notification using the following options:
+
+* SNMPv3
+* with user 'usr-md5-des', auth: MD5, priv DES
+* 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 -v3 -l authPriv -u usr-sha-aes -A authkey1 -X privkey1 \
+| 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.entity.rfc3413.oneliner.ntforg import *
-from pysnmp.proto import rfc1902
-for errorIndication, \
- errorStatus, errorIndex, \
- varBinds in \
- sendNotification(SnmpEngine(),
- UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- UdpTransportTarget(('localhost', 162)),
- ContextData(),
- 'inform',
- NotificationType(
- ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
- ).addVarBinds(
- ( ObjectType(ObjectIdentity('1.3.6.1.2.1.1.5.0'),
- rfc1902.OctetString('system name')) )
- ),
- lookupNames=True, lookupValues=True):
- # Check for errors and print out results
- if errorIndication:
- print(errorIndication)
- else:
- if 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 ]))
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ sendNotification(SnmpEngine(),
+ UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'inform',
+ NotificationType(
+ 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')
+ ))
+)
+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/v3arch/asyncore/oneliner/agent/ntforg/trap-async-multiple-transports-and-protocols.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-async-multiple-transports-and-protocols.py
new file mode 100644
index 0000000..60c557a
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-async-multiple-transports-and-protocols.py
@@ -0,0 +1,51 @@
+"""
+Multiple concurrent queries
++++++++++++++++++++++++++++
+
+Send a bunch of different SNMP Notifications to different peers all at once,
+wait for responses asynchronously:
+
+* SNMPv1 and SNMPv2c
+* with community name 'public'
+* over IPv4/UDP
+* send TRAP notification
+* to multiple Managers
+* with TRAP ID 'coldStart' specified as a MIB symbol
+* include managed object information specified as var-bind objects pair
+
+"""#
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
+
+# List of targets in the followin format:
+# ( ( authData, transportTarget ), ... )
+targets = (
+ # 1-st target (SNMPv1 over IPv4/UDP)
+ ( CommunityData('public', mpModel=0),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData() ),
+ # 2-nd target (SNMPv2c over IPv4/UDP)
+ ( CommunityData('public'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData() ),
+)
+
+snmpEngine = SnmpEngine()
+
+ntfOrg = AsyncNotificationOriginator()
+
+for authData, transportTarget, contextData in targets:
+ ntfOrg.sendNotification(
+ snmpEngine,
+ authData,
+ transportTarget,
+ contextData,
+ 'trap', # NotifyType
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds(
+ ( ObjectName('1.3.6.1.2.1.1.1.0'),
+ OctetString('my name') )
+ )
+ )
+
+snmpEngine.transportDispatcher.runDispatcher()
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-custom-values.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-custom-values.py
index 1d2b825..85e130b 100644
--- a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-custom-values.py
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-custom-values.py
@@ -1,36 +1,50 @@
-#
-# Notification Originator
-#
-# Send SNMP notification using the following options:
-#
-# * SNMPv1
-# * with community name 'public'
-# * over IPv4/UDP
-# * send TRAP notification
-# * with Generic Trap #6 (enterpriseSpecific) and Specific Trap 432
-# * overriding Uptime value with 12345
-# * overriding Agent Address with '127.0.0.1'
-# * overriding Enterprise OID with 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'
-#
+"""
+Custom SNMPv1 TRAP
+++++++++++++++++++
+
+Send SNMPv1 TRAP through unified SNMPv3 message processing framework.
+
+Original v1 TRAP fields are mapped into dedicated variable-bindings,
+(see `RFC2576 <https://www.ietf.org/rfc/rfc2576.txt>`_) for details.
+
+* SNMPv1
+* with community name 'public'
+* over IPv4/UDP
+* send TRAP notification
+* with Generic Trap #6 (enterpriseSpecific) and Specific Trap 432
+* overriding Uptime value with 12345
+* overriding Agent Address with '127.0.0.1'
+* overriding Enterprise OID with 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 \
+| 127.0.0.1 \
+| 6 \
+| 432 \
+| 12345 \
+| '1.3.6.1.2.1.1.1.0' s 'my system'
+
+"""#
from pysnmp.entity.rfc3413.oneliner.ntforg import *
-from pysnmp.proto import rfc1902
-for errorIndication, \
- errorStatus, errorIndex, \
- varBinds in \
- sendNotification(SnmpEngine(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('localhost', 162)),
- ContextData(),
- 'trap',
- NotificationType(
- ObjectIdentity('1.3.6.1.4.1.20408.4.1.1.2.0.432'),
- ).addVarBinds(
- ('1.3.6.1.2.1.1.3.0', 12345),
- ('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', rfc1902.OctetString('my system'))
- )):
- if errorIndication:
- print(errorIndication)
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ sendNotification(SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(
+ ObjectIdentity('1.3.6.1.4.1.20408.4.1.1.2.0.432'),
+ ).addVarBinds(
+ ('1.3.6.1.2.1.1.3.0', 12345),
+ ('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', rfc1902.OctetString('my system'))
+ )
+ )
+)
+if errorIndication:
+ print(errorIndication)
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-default-values.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-default-values.py
index a704146..5ad5ef7 100644
--- a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-default-values.py
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-default-values.py
@@ -1,34 +1,46 @@
-#
-# Notification Originator
-#
-# Send SNMP notification using the following options:
-#
-# * SNMPv1
-# * with community name 'public'
-# * over IPv4/UDP
-# * send TRAP notification
-# * with Generic Trap #1 (warmStart) and Specific Trap 0
-# * with default Uptime
-# * with default Agent Address
-# * 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'
-#
+"""
+SNMPv1 TRAP with defaults
++++++++++++++++++++++++++
+
+Send SNMPv1 TRAP through unified SNMPv3 message processing framework
+using the following options:
+
+* SNMPv1
+* with community name 'public'
+* over IPv4/UDP
+* send TRAP notification
+* with Generic Trap #1 (warmStart) and Specific Trap 0
+* with default Uptime
+* with default Agent Address
+* 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.entity.rfc3413.oneliner.ntforg import *
-from pysnmp.proto import rfc1902
-for errorIndication, \
- errorStatus, errorIndex, \
- varBinds in \
- sendNotification(SnmpEngine(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('localhost', 162)),
- ContextData(),
- 'trap',
- NotificationType(
- ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
- ).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', rfc1902.OctetString('my system'))
- )):
- if errorIndication:
- print(errorIndication)
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ sendNotification(SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(
+ ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
+ ).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', rfc1902.OctetString('my system'))
+ )
+ )
+)
+if errorIndication:
+ print(errorIndication)
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py
index b243f43..a328a2c 100644
--- a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py
@@ -1,27 +1,37 @@
-#
-# Notification Originator
-#
-# Send SNMP notification using the following options:
-#
-# * SNMPv2c
-# * with community name 'public'
-# * over IPv4/UDP
-# * send TRAP notification
-# * with TRAP ID 'coldStart' specified as a MIB symbol
-# * include managed object information specified as a MIB symbol
-#
+"""
+SNMPv2c TRAP via NOTIFICATION-TYPE
+++++++++++++++++++++++++++++++++++
+
+Initialize TRAP message contents from variables specified
+in *NOTIFICATION-TYPE* SMI macro.
+
+* SNMPv2c
+* with community name 'public'
+* over IPv4/UDP
+* send TRAP notification
+* with TRAP ID 'coldStart' specified as a MIB symbol
+* include managed object information specified as a MIB symbol
+
+Functionally similar to:
+
+| $ snmptrap -v2c -c public demo.snmplabs.com \
+| 12345
+| 1.3.6.1.4.1.20408.4.1.1.2 \
+
+"""#
from pysnmp.entity.rfc3413.oneliner.ntforg import *
-for errorIndication, \
- errorStatus, errorIndex, \
- varBinds in \
- sendNotification(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('localhost', 162)),
- ContextData(),
- 'trap',
- NotificationType(
- ObjectIdentity('SNMPv2-MIB', 'coldStart')
- )):
- if errorIndication:
- print(errorIndication)
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ sendNotification(SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ )
+ )
+)
+
+if errorIndication:
+ print(errorIndication)
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py
index bbc9194..f03948f 100644
--- a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py
@@ -1,37 +1,45 @@
-#
-# Notification Originator
-#
-# Send SNMP notification using the following options:
-#
-# * SNMPv3
-# * with local snmpEngineId = 0x8000000001020304 (must configure at Receiver)
-# * with user 'usr-sha-aes128', auth: SHA, priv: AES128
-# * over IPv4/UDP
-# * send TRAP notification
-# * with TRAP ID 'authenticationFailure' specified as a MIB symbol
-# * do not include any additional managed object information
-#
-# SNMPv3 TRAPs requires pre-sharing the Notification Originator's
-# value of SnmpEngineId with Notification Receiver. To facilitate that
-# we will use static (e.g. not autogenerated) version of snmpEngineId.
-#
+"""
+SNMPv3 TRAP: auth SHA, privacy: AES128
+++++++++++++++++++++++++++++++++++++++
+
+Send SNMP notification using the following options:
+
+* SNMPv3
+* with local snmpEngineId = 0x8000000001020304 (must configure at Receiver)
+* with user 'usr-sha-aes128', auth: SHA, priv: AES128
+* over IPv4/UDP
+* send TRAP notification
+* with TRAP ID 'authenticationFailure' specified as a MIB symbol
+* do not include any additional managed object information
+
+SNMPv3 TRAPs requires pre-sharing the Notification Originator's
+value of SnmpEngineId with Notification Receiver. To facilitate that
+we will use static (e.g. not autogenerated) version of snmpEngineId.
+
+Functionally similar to:
+
+| $ snmptrap -v3 -l authPriv -u usr-sha-aes -A authkey1 -X privkey1 \
+| -a SHA -x AES \
+| 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.entity.rfc3413.oneliner.ntforg import *
-from pysnmp.proto.rfc1902 import OctetString
-for errorIndication, \
- errorStatus, errorIndex, \
- varBinds in \
- sendNotification(SnmpEngine(
- OctetString(hexValue='8000000001020304')
- ),
- UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
- authProtocol=usmHMACSHAAuthProtocol,
- privProtocol=usmAesCfb128Protocol),
- UdpTransportTarget(('localhost', 162)),
- ContextData(),
- 'trap',
- NotificationType(
- ObjectIdentity('SNMPv2-MIB', 'authenticationFailure')
- )):
- if errorIndication:
- print(errorIndication)
+errorIndication, errorStatus, errorIndex, varBinds = next(
+ sendNotification(SnmpEngine(OctetString(hexValue='8000000001020304')),
+ UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
+ authProtocol=usmHMACSHAAuthProtocol,
+ privProtocol=usmAesCfb128Protocol),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'authenticationFailure')
+ )
+ )
+)
+if errorIndication:
+ print(errorIndication)