summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py21
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py23
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py21
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py20
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py4
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py12
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py8
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py9
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py16
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py9
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py7
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py3
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py7
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py4
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py5
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py34
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py5
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py5
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py2
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py4
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py2
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py2
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py4
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py2
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py2
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py2
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py10
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py20
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py2
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py4
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py26
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py27
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py27
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py22
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py25
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py24
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v1-trap.py25
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v2c-inform.py28
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v2c-trap-via-notification-type.py83
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v2c-trap.py27
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v3-trap.py25
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py88
42 files changed, 381 insertions, 315 deletions
diff --git a/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py b/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py
index a19bc117..fc4a3582 100644
--- a/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py
+++ b/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py
@@ -12,19 +12,19 @@
# * include managed object information specified as var-bind objects pair
#
from pysnmp.entity.rfc3413.oneliner import ntforg
-from pysnmp.entity.rfc3413 import context
from pysnmp.entity import engine
-from pysnmp.proto import rfc1902
# List of targets in the followin format:
# ( ( authData, transportTarget ), ... )
targets = (
# 1-st target (SNMPv2c over IPv4/UDP)
( ntforg.CommunityData('public'),
- ntforg.UdpTransportTarget(('localhost', 162)) ),
+ ntforg.UdpTransportTarget(('localhost', 162)),
+ ntforg.ContextData() ),
# 2-nd target (SNMPv3 over IPv4/UDP)
( ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- ntforg.UdpTransportTarget(('localhost', 162)) )
+ ntforg.UdpTransportTarget(('localhost', 162)),
+ ntforg.ContextData() ),
)
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
@@ -43,17 +43,16 @@ snmpEngine = engine.SnmpEngine()
ntfOrg = ntforg.AsyncNotificationOriginator()
-for authData, transportTarget in targets:
+for authData, transportTarget, contextData in targets:
sendPduHandle = ntfOrg.sendNotification(
snmpEngine,
authData,
transportTarget,
- context.SnmpContext(snmpEngine),
- ntforg.null,
- 'inform',
- ntforg.MibVariable('SNMPv2-MIB', 'coldStart'),
- ( ( rfc1902.ObjectName('1.3.6.1.2.1.1.1.0'),
- rfc1902.OctetString('my name') ), ),
+ contextData,
+ 'inform', # NotifyType
+ ntforg.NotificationType(
+ ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ),
cbInfo=(cbFun, None)
)
diff --git a/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py b/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py
index a075fdaa..c9e955e9 100644
--- a/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py
+++ b/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py
@@ -12,7 +12,6 @@
# * include managed object information specified as var-bind objects pair
#
from pysnmp.entity.rfc3413.oneliner import ntforg
-from pysnmp.entity.rfc3413 import context
from pysnmp.entity import engine
from pysnmp.proto import rfc1902
@@ -21,27 +20,31 @@ from pysnmp.proto import rfc1902
targets = (
# 1-st target (SNMPv1 over IPv4/UDP)
( ntforg.CommunityData('public', mpModel=0),
- ntforg.UdpTransportTarget(('localhost', 162)) ),
+ ntforg.UdpTransportTarget(('localhost', 162)),
+ ntforg.ContextData() ),
# 2-nd target (SNMPv2c over IPv4/UDP)
( ntforg.CommunityData('public'),
- ntforg.UdpTransportTarget(('localhost', 162)) )
+ ntforg.UdpTransportTarget(('localhost', 162)),
+ ntforg.ContextData() ),
)
snmpEngine = engine.SnmpEngine()
ntfOrg = ntforg.AsyncNotificationOriginator()
-for authData, transportTarget in targets:
+for authData, transportTarget, contextData in targets:
ntfOrg.sendNotification(
snmpEngine,
authData,
transportTarget,
- context.SnmpContext(snmpEngine),
- ntforg.null,
- 'trap',
- ntforg.MibVariable('SNMPv2-MIB', 'coldStart'),
- ( ( rfc1902.ObjectName('1.3.6.1.2.1.1.1.0'),
- rfc1902.OctetString('my name') ), )
+ contextData,
+ 'trap', # NotifyType
+ ntforg.NotificationType(
+ ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds(
+ ( rfc1902.ObjectName('1.3.6.1.2.1.1.1.0'),
+ rfc1902.OctetString('my name') )
+ )
)
snmpEngine.transportDispatcher.runDispatcher()
diff --git a/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py b/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py
index 088b72b9..2dfbc55a 100644
--- a/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py
+++ b/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py
@@ -26,19 +26,19 @@
#
from pysnmp.entity.rfc3413.oneliner import ntforg
from pysnmp.entity import engine
-from pysnmp.entity.rfc3413 import context
from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher
-from pysnmp.proto import rfc1902
# List of targets in the following format:
# ( ( authData, transportTarget ), ... )
targets = (
# 1-st target (SNMPv2c over IPv4/UDP)
( ntforg.CommunityData('public'),
- ntforg.UdpTransportTarget(('localhost', 1162)) ),
+ ntforg.UdpTransportTarget(('localhost', 1162)),
+ ntforg.ContextData() ),
# 2-nd target (SNMPv3 over IPv4/UDP)
( ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- ntforg.UdpTransportTarget(('localhost', 162)) )
+ ntforg.UdpTransportTarget(('localhost', 162)),
+ ntforg.ContextData() ),
)
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
@@ -69,19 +69,18 @@ snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B')
ntfOrg = ntforg.AsyncNotificationOriginator()
-for authData, transportTarget in targets:
+for authData, transportTarget, contextData in targets:
snmpEngine = transportTarget.getTransportInfo()[1][1] % 3 and \
snmpEngineA or snmpEngineB
sendPduHandle = ntfOrg.sendNotification(
snmpEngine,
authData,
transportTarget,
- context.SnmpContext(snmpEngine),
- ntforg.null,
- 'inform',
- ntforg.MibVariable('SNMPv2-MIB', 'coldStart'),
- ( ( rfc1902.ObjectName('1.3.6.1.2.1.1.1.0'),
- rfc1902.OctetString('my name') ), ),
+ contextData,
+ 'inform', # NotifyType
+ ntforg.NotificationType(
+ ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ),
cbInfo=(cbFun, snmpEngine)
)
diff --git a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py b/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py
index d70617d2..d169377e 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py
@@ -22,29 +22,29 @@ targets = (
# 1-st target (SNMPv1 over IPv4/UDP)
( cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 2-nd target (SNMPv2c over IPv4/UDP)
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 3-nd target (SNMPv2c over IPv4/UDP) - same community and
# different transport address.
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysContact', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysContact', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysName', 0) ) ),
# 4-nd target (SNMPv3 over IPv4/UDP)
( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 5-th target (SNMPv3 over IPv6/UDP)
( cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.Udp6TransportTarget(('::1', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# N-th target
# ...
)
diff --git a/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py b/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
index af3a40f6..80ff0fe1 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
@@ -29,11 +29,11 @@ targets = (
# 3-nd target (SNMPv3 over IPv4/UDP)
( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'system'), ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'system'), ) ),
# 4-th target (SNMPv3 over IPv6/UDP)
( cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.Udp6TransportTarget(('::1', 161)),
- ( cmdgen.MibVariable('IF-MIB', 'ifTable'), ) )
+ ( cmdgen.ObjectIdentity('IF-MIB', 'ifTable'), ) )
# N-th target
# ...
)
diff --git a/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py b/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py
index 1b7d1565..94c1f541 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py
@@ -35,18 +35,18 @@ targets = (
# 1-st target (SNMPv1 over IPv4/UDP)
( cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 2-nd target (SNMPv2c over IPv4/UDP)
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 1161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 3-nd target (SNMPv3 over IPv4/UDP)
( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 2161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) )
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) )
# N-th target
# ...
)
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py
index 60ab7b26..5e8c0535 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py
@@ -20,17 +20,15 @@ from pysnmp.entity.rfc3413.oneliner import ntforg
from pysnmp.proto import rfc1902
snmpEngine = engine.SnmpEngine()
-snmpContext = context.SnmpContext(
- snmpEngine,contextEngineId=rfc1902.OctetString(hexValue='8000000004030201')
-)
-ntfOrg = ntforg.NotificationOriginator(snmpEngine, snmpContext)
+ntfOrg = ntforg.NotificationOriginator(snmpEngine)
errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
ntforg.UsmUserData('usr-md5-none', 'authkey1'),
ntforg.UdpTransportTarget(('localhost', 162)),
'inform',
- '1.3.6.1.6.3.1.1.5.2'
+ ntforg.NotificationType(ntforg.ObjectIdentity('1.3.6.1.6.3.1.1.5.2')),
+ contextEngineId=rfc1902.OctetString(hexValue='8000000004030201')
)
if errorIndication:
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py
index 1d1085e5..dfe0ad04 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py
@@ -15,22 +15,17 @@
# the ContextName being used.
#
from pysnmp.entity import engine
-from pysnmp.entity.rfc3413 import context
from pysnmp.entity.rfc3413.oneliner import ntforg
snmpEngine = engine.SnmpEngine()
-snmpContext = context.SnmpContext(snmpEngine)
-# register default collection of Managed Objects under new contextName
-snmpContext.registerContextName('my-context', snmpContext.getMibInstrum())
-
-ntfOrg = ntforg.NotificationOriginator(snmpEngine, snmpContext)
+ntfOrg = ntforg.NotificationOriginator(snmpEngine)
errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
ntforg.UsmUserData('usr-md5-none', 'authkey1'),
ntforg.UdpTransportTarget(('localhost', 162)),
'inform',
- '1.3.6.1.6.3.1.1.5.2',
+ ntforg.NotificationType(ntforg.ObjectIdentity('1.3.6.1.6.3.1.1.5.2')),
contextName='my-context'
)
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py
index e2ba44a4..7db778e3 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py
@@ -15,6 +15,9 @@
#
from pysnmp.entity.rfc3413.oneliner import ntforg
from pysnmp.proto import rfc1902
+#from pysnmp import debug
+
+#debug.setLogger(debug.Debug('mibview'))
ntfOrg = ntforg.NotificationOriginator()
@@ -22,11 +25,14 @@ errorIndication = ntfOrg.sendNotification(
ntforg.CommunityData('public', mpModel=0),
ntforg.UdpTransportTarget(('localhost', 162)),
'trap',
- '1.3.6.1.4.1.20408.4.1.1.2.0.432',
- ('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'))
+ ntforg.NotificationType(
+ ntforg.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:
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py
index 4a845f40..beab6e7c 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py
@@ -22,9 +22,12 @@ errorIndication = ntfOrg.sendNotification(
ntforg.CommunityData('public', mpModel=0),
ntforg.UdpTransportTarget(('localhost', 162)),
'trap',
- '1.3.6.1.6.3.1.1.5.2',
- ('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'))
+ ntforg.NotificationType(
+ ntforg.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:
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py b/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py
index ca51d280..330b6b24 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py
@@ -19,8 +19,11 @@ errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
ntforg.CommunityData('public'),
ntforg.UdpTransportTarget(('localhost', 162)),
'inform',
- ntforg.MibVariable('SNMPv2-MIB', 'coldStart'),
- ( ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'my system' ),
+ ntforg.NotificationType(
+ ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds(
+ ( ntforg.ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'my system' )
+ ),
lookupNames=True, lookupValues=True
)
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py b/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py
index 7d018833..502b3a0e 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py
@@ -18,8 +18,7 @@ errorIndication = ntfOrg.sendNotification(
ntforg.CommunityData('public'),
ntforg.UdpTransportTarget(('localhost', 162)),
'trap',
- ntforg.MibVariable('SNMPv2-MIB', 'coldStart'),
- ( ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new name' )
+ ntforg.NotificationType(ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart'))
)
if errorIndication:
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py b/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py
index 41d996ee..f9abe916 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py
@@ -19,8 +19,11 @@ errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
ntforg.UdpTransportTarget(('localhost', 162)),
'inform',
- '1.3.6.1.6.3.1.1.5.2',
- ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('system name'))
+ ntforg.NotificationType(
+ ntforg.ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
+ ).addVarBinds(
+ ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('system name'))
+ )
)
if errorIndication:
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py
index 7aa72f45..60cb0a6c 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py
@@ -30,7 +30,9 @@ errorIndication = ntfOrg.sendNotification(
privProtocol=ntforg.usmAesCfb128Protocol),
ntforg.UdpTransportTarget(('127.0.0.1', 162)),
'trap',
- ntforg.MibVariable('SNMPv2-MIB', 'authenticationFailure')
+ ntforg.NotificationType(
+ ntforg.ObjectIdentity('SNMPv2-MIB', 'authenticationFailure')
+ )
)
if errorIndication:
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
index d58ad9ca..6732ec29 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
@@ -15,7 +15,10 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- (cmdgen.MibVariable('SNMPv2-MIB', 'sysORDescr', 1), 'new system name')
+ cmdgen.ObjectType(
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
+ 'new system name'
+ )
)
# Check for errors and print out results
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
new file mode 100644
index 00000000..2c696993
--- /dev/null
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
@@ -0,0 +1,34 @@
+#
+# Command Generator
+#
+# 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
+#
+from pysnmp.entity.rfc3413.oneliner import cmdgen
+
+cmdGen = cmdgen.CommandGenerator()
+
+errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
+ cmdgen.CommunityData('public'),
+ cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
+ cmdgen.ObjectIdentity('IF-MIB', 'ifInOctets', 1).addMibCompiler('file:///usr/share/snmp', 'http://mibs.snmplabs.com/asn1/<mib>'),
+ 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 oid, val in varBinds:
+ print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py
index e273bba6..f28063b1 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py
@@ -19,7 +19,10 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- (cmdgen.MibVariable('SNMPv2-MIB', 'sysORDescr', 1), 'new system name'),
+ cmdgen.ObjectType(
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
+ 'new system name'
+ ),
contextEngineId=rfc1902.OctetString(hexValue='80004fb805636c6f75644dab22cc'),
contextName='da761cfc8c94d3aceef4f60f049105ba'
)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
index 04ee0bf5..124a26fa 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
@@ -23,7 +23,10 @@ errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
)
),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- (cmdgen.MibVariable('SNMPv2-MIB', 'sysORDescr', 1), 'new system name'),
+ cmdgen.ObjectType(
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
+ 'new system name'
+ )
)
# Check for errors and print out results
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
index a0f0f298..4ca6b6e9 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
@@ -22,7 +22,7 @@ errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
cmdgen.UsmUserData('usr-none-none'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
0, 50,
- cmdgen.MibVariable('TCP-MIB', 'tcpConnTable').addMibSource('/tmp/mymibs'),
+ cmdgen.ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource('/tmp/mibs'),
lexicographicMode=True, maxRows=100, maxCalls=10,ignoreNonIncreasingOid=True
)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
index 452c8113..b766fad9 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
@@ -6,7 +6,7 @@
# * with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols
# * over IPv6/UDP
# * to an Agent at [::1]:161
-# * for three OIDs: one passed as a MibVariable object while others are
+# * for three OIDs: one passed as a ObjectIdentity object while others are
# * in string form
#
from pysnmp.entity.rfc3413.oneliner import cmdgen
@@ -16,7 +16,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.Udp6TransportTarget(('::1', 161)),
- cmdgen.MibVariable('1.3.6.1.2.1.1.1.0'),
+ cmdgen.ObjectIdentity('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'
)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
index 35fe0df4..c6419934 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
@@ -16,7 +16,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.UsmUserData('usr-none-none'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.MibVariable('IF-MIB', 'ifInOctets', '1'),
+ cmdgen.ObjectIdentity('IF-MIB', 'ifInOctets', 1),
lookupNames=True, lookupValues=True
)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
index 74f31b0e..8bc4562b 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
@@ -17,7 +17,7 @@ errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
authProtocol=cmdgen.usmHMACSHAAuthProtocol,
privProtocol=cmdgen.usmAesCfb128Protocol ),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.MibVariable('TCP-MIB', 'tcpConnLocalAddress', '0.0.0.0', 22, '0.0.0.0', 0)
+ cmdgen.ObjectIdentity('TCP-MIB', 'tcpConnLocalAddress', '0.0.0.0', 22, '0.0.0.0', 0)
)
# Check for errors and print out results
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
index 7291ee8f..99df3c11 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
@@ -22,8 +22,8 @@ errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.Udp6TransportTarget(('::1', 161)),
1, 25,
- cmdgen.MibVariable('IP-MIB', 'ipAdEntAddr'),
- cmdgen.MibVariable('IF-MIB', 'ifEntry'),
+ cmdgen.ObjectIdentity('IP-MIB', 'ipAdEntAddr'),
+ cmdgen.ObjectIdentity('IF-MIB', 'ifEntry'),
lookupNames=True, lookupValues=True, maxRows=20
)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py
index 2e9c9f43..bdeda853 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py
@@ -21,7 +21,7 @@ errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
authProtocol=cmdgen.usmHMACSHAAuthProtocol,
privProtocol=cmdgen.usmAesCfb128Protocol),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.MibVariable('IF-MIB', '').loadMibs(),
+ cmdgen.ObjectIdentity('IF-MIB', '').loadMibs(),
lexicographicMode=True, maxRows=100,
ignoreNonIncreasingOid=True
)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py b/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
index 6354572c..847ba252 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
@@ -19,7 +19,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.Udp6TransportTarget(('::1', 161)),
- cmdgen.MibVariable('IF-MIB', 'ifEntry'),
+ cmdgen.ObjectIdentity('IF-MIB', 'ifEntry'),
lookupNames=True, lookupValues=True
)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py
index 25352de8..2d62e85c 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py
@@ -19,7 +19,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.MibVariable('IF-MIB', ''),
+ cmdgen.ObjectIdentity('IF-MIB', ''),
lookupValues=True
)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
index 2a698959..7be99e22 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
@@ -18,11 +18,11 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.MibVariable('IF-MIB', 'ifDescr'),
- cmdgen.MibVariable('IF-MIB', 'ifType'),
- cmdgen.MibVariable('IF-MIB', 'ifMtu'),
- cmdgen.MibVariable('IF-MIB', 'ifSpeed'),
- cmdgen.MibVariable('IF-MIB', 'ifPhysAddress')
+ cmdgen.ObjectIdentity('IF-MIB', 'ifDescr'),
+ cmdgen.ObjectIdentity('IF-MIB', 'ifType'),
+ cmdgen.ObjectIdentity('IF-MIB', 'ifMtu'),
+ cmdgen.ObjectIdentity('IF-MIB', 'ifSpeed'),
+ cmdgen.ObjectIdentity('IF-MIB', 'ifPhysAddress')
)
if errorIndication:
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py b/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py
index df22afb7..5d589f93 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py
@@ -28,29 +28,29 @@ targets = (
# 1-st target (SNMPv1 over IPv4/UDP)
( cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 2-nd target (SNMPv2c over IPv4/UDP)
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 3-nd target (SNMPv2c over IPv4/UDP) - same community and
# different transport address.
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysContact', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysContact', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysName', 0) ) ),
# 4-nd target (SNMPv3 over IPv4/UDP)
( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# 5-th target (SNMPv3 over IPv6/UDP)
( cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.Udp6TransportTarget(('::1', 161)),
- ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
# N-th target
# ...
)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py
index 5392c0c9..47f025f1 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py
@@ -15,7 +15,7 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.MibVariable('IF-MIB', 'ifInOctets', '1')
+ cmdgen.ObjectIdentity('IF-MIB', 'ifInOctets', 1)
)
# Check for errors and print out results
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py
index f05c5f80..664df9dd 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py
@@ -16,8 +16,8 @@ cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.MibVariable('iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0'),
- cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0)
+ cmdgen.ObjectIdentity('iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0'),
+ cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)
)
# Check for errors and print out results
diff --git a/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py b/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py
index a3fbb8d5..8f70ef9e 100644
--- a/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py
+++ b/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py
@@ -18,7 +18,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
# Create SNMP engine instance
@@ -80,9 +80,6 @@ config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (), (), (1,3,6))
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
-# Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Error/confirmation receiver
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
@@ -94,18 +91,15 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
# Build and submit notification message to dispatcher
sendRequestHandle = ntfOrg.sendVarBinds(
snmpEngine,
- # Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name (SNMPv2-MIB::coldStart)
- (1,3,6,1,6,3,1,1,5,1),
- # instance Index
- None,
- # additional var-binds: ( (oid, value), ... )
- [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')) ],
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds
+ [
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
+ ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
+ # additional var-binds: ( (oid, value), ... )
+ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator'))
+ ],
cbFun
)
diff --git a/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py b/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py
index 329268f1..709e9720 100644
--- a/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py
+++ b/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py
@@ -16,7 +16,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
# Create SNMP engine instance
@@ -74,25 +74,20 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
-# Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Build and submit notification message to dispatcher
ntfOrg.sendVarBinds(
snmpEngine,
# Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name (SNMPv2-MIB::coldStart)
- (1,3,6,1,6,3,1,1,5,1),
- # instance Index
- None,
- # additional var-binds: ( (oid, value), ... )
- [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
- ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ]
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds
+ [
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
+ ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
+ # additional var-binds: ( (oid, value), ... )
+ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
+ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
+ ]
)
print('Notifications are scheduled to be sent')
diff --git a/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py b/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py
index ea204f2c..e2589da7 100644
--- a/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py
+++ b/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py
@@ -15,7 +15,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp, udp6
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
# Create SNMP engine instance
@@ -73,25 +73,20 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
- # Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Build and submit notification message to dispatcher
ntfOrg.sendVarBinds(
snmpEngine,
# Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name (SNMPv2-MIB::coldStart)
- (1,3,6,1,6,3,1,1,5,1),
- # instance Index
- None,
- # additional var-binds: ( (oid, value), ... )
- [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
- ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ]
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds
+ [
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
+ ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
+ # additional var-binds: ( (oid, value), ... )
+ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
+ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
+ ]
)
print('Notification is scheduled to be sent')
diff --git a/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py b/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py
index 2bfa05d6..04dcd569 100644
--- a/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py
+++ b/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py
@@ -13,7 +13,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
# Create SNMP engine instance
@@ -57,22 +57,16 @@ config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
- # Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Build and submit notification message to dispatcher
ntfOrg.sendVarBinds(
snmpEngine,
- # Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name (SNMPv2-MIB::coldStart)
- (1,3,6,1,6,3,1,1,5,1),
- # instance Index
- None
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds
+ [
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
+ ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1)))
+ ]
)
print('Notification is scheduled to be sent')
diff --git a/examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py b/examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py
index 0ca3d702..cd6432b5 100644
--- a/examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py
+++ b/examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py
@@ -16,7 +16,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
# Create SNMP engine instance
@@ -70,22 +70,23 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# *** SNMP engine configuration is complete by this line ***
-# Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Create Notification Originator App instance.
-ntfOrg = ntforg.NotificationOriginator(snmpContext)
+ntfOrg = ntforg.NotificationOriginator()
# Build and submit notification message to dispatcher
-ntfOrg.sendNotification(
+ntfOrg.sendVarBinds(
snmpEngine,
# Notification targets
- 'my-notification',
- # Trap OID (SNMPv2-MIB::coldStart)
- (1,3,6,1,6,3,1,1,5,1),
- # ( (oid, value), ... )
- ( ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
- ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) )
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds
+ [
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
+ ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
+ # additional var-binds: ( (oid, value), ... )
+ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
+ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
+ ]
)
print('Notifications are scheduled to be sent')
diff --git a/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py b/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py
index facebe34..ef5355ad 100644
--- a/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py
+++ b/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py
@@ -13,7 +13,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
# Create SNMP engine instance
@@ -54,11 +54,8 @@ config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (), (), (1,3,6))
# *** SNMP engine configuration is complete by this line ***
-# Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Create Notification Originator App instance.
-ntfOrg = ntforg.NotificationOriginator(snmpContext)
+ntfOrg = ntforg.NotificationOriginator()
# Error/confirmation receiver
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
@@ -71,18 +68,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
# Build and submit notification message to dispatcher
sendRequestHandle = ntfOrg.sendVarBinds(
snmpEngine,
- # Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name (SNMPv2-MIB::coldStart)
- (1,3,6,1,6,3,1,1,5,1),
- # instance Index
- None,
- # additional var-binds: ( (oid, value), ... )
- [ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('system name')) ],
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds: SNMPv2-MIB::coldStart, ...
+ [ ((1,3,6,1,6,3,1,1,5,1), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
+ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('system name')) ],
cbFun
)
diff --git a/examples/v3arch/asyncore/agent/ntforg/v1-trap.py b/examples/v3arch/asyncore/agent/ntforg/v1-trap.py
index f21bde50..2ac50718 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v1-trap.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v1-trap.py
@@ -17,7 +17,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
#from pysnmp import debug
@@ -64,28 +64,21 @@ config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
- # Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Build and submit notification message to dispatcher
ntfOrg.sendVarBinds(
snmpEngine,
# Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name: Generic Trap #6 (enterpriseSpecific)
- # and Specific Trap 432
- '1.3.6.1.4.1.20408.4.1.1.2.0.432',
- # instance Index
- None,
- # additional var-binds
- [
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds
+ [
# Uptime value with 12345
(v2c.ObjectIdentifier('1.3.6.1.2.1.1.3.0'),
v2c.TimeTicks(12345)),
+ # trap OID: Generic Trap #6 (enterpriseSpecific)
+ # and Specific Trap 432
+ (v2c.ObjectIdentifier('1.3.6.1.6.3.1.1.5.1'),
+ v2c.ObjectIdentifier('1.3.6.1.4.1.20408.4.1.1.2.0.432')),
# Agent Address with '127.0.0.1'
(v2c.ObjectIdentifier('1.3.6.1.6.3.18.1.3.0'),
v2c.IpAddress('127.0.0.1')),
diff --git a/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py b/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py
index 08993b0e..9c52655d 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py
@@ -15,7 +15,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
# Create SNMP engine instance
@@ -59,9 +59,6 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
-# Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Error/confirmation receiver
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
@@ -73,19 +70,16 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
# Build and submit notification message to dispatcher
sendRequestHandle = ntfOrg.sendVarBinds(
snmpEngine,
- # Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name (SNMPv2-MIB::coldStart)
- (1,3,6,1,6,3,1,1,5,1),
- # instance Index
- None,
- # additional var-binds: ( (oid, value), ... )
- [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
- ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ],
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds
+ [
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
+ ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
+ # additional var-binds: ( (oid, value), ... )
+ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
+ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
+ ],
cbFun
)
diff --git a/examples/v3arch/asyncore/agent/ntforg/v2c-trap-via-notification-type.py b/examples/v3arch/asyncore/agent/ntforg/v2c-trap-via-notification-type.py
index e4ac2e01..ad17348a 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v2c-trap-via-notification-type.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v2c-trap-via-notification-type.py
@@ -8,28 +8,24 @@
# * over IPv4/UDP
# * send TRAP notification
# * to a Manager at 127.0.0.1:162
-# * with TRAP ID ACCOUNTING-CONTROL-MIB::acctngFileFull as MIB symbol
+# * with TRAP ID IF-MIB::ifLink as MIB symbol
#
-# The ACCOUNTING-CONTROL-MIB::acctngFileFull NOTIFICATION-TYPE implies
-# including three other var-binds into the TRAP describing the incident
-# occurred. These var-binds are:
-# ACCOUNTING-CONTROL-MIB::acctngFileMaximumSize.0
-# ACCOUNTING-CONTROL-MIB::acctngFileNameSuffix.0
-# ACCOUNTING-CONTROL-MIB::acctngFileName.0
+# The IF-MIB::ifLink NOTIFICATION-TYPE implies including four other
+# var-binds into the notification message describing the incident
+# occurred. These var-binds are:
+# IF-MIB::ifIndex."x"
+# IF-MIB::ifAdminStatus."x"
+# IF-MIB::ifOperStatus."x"
+# IF-MIB::ifDescr."x"
#
-# To run this example make sure to have ACCOUNTING-CONTROL-MIB.py in
-# search path.
+# Where "x" is MIB table index (instance index).
+#
+# To run this example make sure to have IF-MIB.py in search path.
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
-from pysnmp.proto.api import v2c
-
-# Create SNMP engine instance
-snmpEngine = engine.SnmpEngine()
-
-# Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
+from pysnmp.entity.rfc3413 import ntforg
+from pysnmp.smi import rfc1902, view
#
# Here we fill in some values for Managed Objects Instances (invoked
@@ -37,33 +33,19 @@ snmpContext = context.SnmpContext(snmpEngine)
# In real Agent app, these values should already be initialized during
# Agent runtime.
#
+instanceIndex = (1,)
+objects = {
+ ('IF-MIB', 'ifIndex'): instanceIndex[0],
+ ('IF-MIB', 'ifAdminStatus'): 'up',
+ ('IF-MIB', 'ifOperStatus'): 'down',
+ ('IF-MIB', 'ifDescr'): 'eth0'
+}
-mibInstrumCtl = snmpContext.getMibInstrum('')
-( MibScalarInstance, ) = mibInstrumCtl.mibBuilder.importSymbols(
- 'SNMPv2-SMI',
- 'MibScalarInstance'
- )
-( acctngFileFull,
- acctngFileMaximumSize,
- acctngFileNameSuffix,
- acctngFileName ) = mibInstrumCtl.mibBuilder.importSymbols(
- 'ACCOUNTING-CONTROL-MIB',
- 'acctngFileFull',
- 'acctngFileMaximumSize',
- 'acctngFileNameSuffix',
- 'acctngFileName'
- )
-
-mibInstrumCtl.mibBuilder.exportSymbols(
- '__ACCOUNTING-CONTROL-MIB',
- MibScalarInstance(acctngFileMaximumSize.name, (0,), acctngFileMaximumSize.syntax.clone(123)),
- MibScalarInstance(acctngFileNameSuffix.name, (0,), acctngFileNameSuffix.syntax.clone('.log')),
- MibScalarInstance(acctngFileName.name, (0,), acctngFileName.syntax.clone('mylogfile')),
-)
+# Create SNMP engine instance
+snmpEngine = engine.SnmpEngine()
-#
-# End of Agent's Managed Object Instances initialization
-#
+# MIB view controller is used for MIB lookup purposes
+mibViewController = view.MibViewController(snmpEngine.getMibBuilder())
# SecurityName <-> CommunityName mapping
config.addV1System(snmpEngine, 'my-area', 'public', transportTag='all-my-managers')
@@ -107,16 +89,13 @@ ntfOrg = ntforg.NotificationOriginator()
# Build and submit notification message to dispatcher
ntfOrg.sendVarBinds(
snmpEngine,
- # Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name
- ('ACCOUNTING-CONTROL-MIB', 'acctngFileFull'),
- # MIB scalar/table instances of NOTIFICATION-TYPE objects
- (0,)
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ rfc1902.NotificationType(
+ rfc1902.ObjectIdentity('IF-MIB', 'linkUp'),
+ instanceIndex=instanceIndex,
+ objects=objects
+ ).resolveWithMib(mibViewController)
)
print('Notification is scheduled to be sent')
diff --git a/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py b/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py
index 4e3465b2..d63a371e 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py
@@ -15,7 +15,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
# Create SNMP engine instance
@@ -58,9 +58,6 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
- # Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Error/confirmation receiver
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
@@ -73,18 +70,16 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
sendRequestHandle = ntfOrg.sendVarBinds(
snmpEngine,
# Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name (SNMPv2-MIB::coldStart)
- (1,3,6,1,6,3,1,1,5,1),
- # instance Index
- None,
- # additional var-binds: ( (oid, value), ... )
- [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
- ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ],
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds
+ [
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
+ ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
+ # additional var-binds: ( (oid, value), ... )
+ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')),
+ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
+ ],
cbFun
)
diff --git a/examples/v3arch/asyncore/agent/ntforg/v3-trap.py b/examples/v3arch/asyncore/agent/ntforg/v3-trap.py
index bff341a3..266d91ec 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v3-trap.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v3-trap.py
@@ -13,7 +13,7 @@
#
from pysnmp.entity import engine, config
from pysnmp.carrier.asynsock.dgram import udp
-from pysnmp.entity.rfc3413 import ntforg, context
+from pysnmp.entity.rfc3413 import ntforg
from pysnmp.proto.api import v2c
# Create SNMP engine instance with specific (and locally unique)
@@ -62,24 +62,19 @@ config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (), (), (1,3,6))
# Create Notification Originator App instance.
ntfOrg = ntforg.NotificationOriginator()
- # Create default SNMP context where contextEngineId == SnmpEngineId
-snmpContext = context.SnmpContext(snmpEngine)
-
# Build and submit notification message to dispatcher
ntfOrg.sendVarBinds(
snmpEngine,
# Notification targets
- 'my-notification',
- # SNMP Context
- snmpContext,
- # contextName
- '',
- # notification name (SNMPv2-MIB::coldStart)
- (1,3,6,1,6,3,1,1,5,1),
- # instance Index
- None,
- # additional var-binds: ( (oid, value), ... )
- [ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('system name')) ]
+ 'my-notification', # notification targets
+ None, '', # contextEngineId, contextName
+ # var-binds
+ [
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart
+ ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))),
+ # additional var-binds: ( (oid, value), ... )
+ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example'))
+ ]
)
print('Notification is scheduled to be sent')
diff --git a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py
new file mode 100644
index 00000000..a8c5b35b
--- /dev/null
+++ b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py
@@ -0,0 +1,88 @@
+#
+# GETNEXT Command Generator
+#
+# Send a series of SNMP GETNEXT requests
+# with SNMPv1, community 'public'
+# over IPv4/UDP
+# to an Agent at 195.218.195.228:161
+# for two OIDs in tuple form
+# stop on end-of-mib condition for both OIDs
+#
+# This script performs similar to the following Net-SNMP command:
+#
+# $ snmpwalk -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1
+#
+from pysnmp.entity import engine, config
+from pysnmp.carrier.asynsock.dgram import udp
+from pysnmp.entity.rfc3413 import cmdgen
+from pysnmp.smi import compiler, view, rfc1902
+
+# Create SNMP engine instance
+snmpEngine = engine.SnmpEngine()
+
+# Attach MIB compiler to SNMP Engine (MIB Builder)
+compiler.addMibCompiler(snmpEngine.getMibBuilder())
+
+# Used for MIB objects resolution
+mibViewController = view.MibViewController(snmpEngine.getMibBuilder())
+
+#
+#
+# SNMPv1/2c setup
+#
+
+# SecurityName <-> CommunityName mapping
+config.addV1System(snmpEngine, 'my-area', 'public')
+
+# Specify security settings per SecurityName (SNMPv1 - 0, SNMPv2c - 1)
+config.addTargetParams(snmpEngine, 'my-creds', 'my-area', 'noAuthNoPriv', 1)
+
+#
+# Setup transport endpoint and bind it with security settings yielding
+# a target name
+#
+
+# UDP/IPv4
+config.addTransport(
+ snmpEngine,
+ udp.domainName,
+ udp.UdpSocketTransport().openClientMode()
+)
+config.addTargetAddr(
+ snmpEngine, 'my-router',
+ udp.domainName, ('195.218.195.228', 161),
+ 'my-creds'
+)
+
+# Error/response receiver
+def cbFun(snmpEngine, sendRequestHandle, errorIndication,
+ errorStatus, errorIndex, varBindTable, cbCtx):
+ if errorIndication:
+ print(errorIndication)
+ return
+ # SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
+ # so we ignore noSuchName error here
+ if errorStatus and errorStatus != 2:
+ print('%s at %s' % (
+ errorStatus.prettyPrint(),
+ errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
+ )
+ )
+ return # stop on error
+ for varBindRow in varBindTable:
+ for varBind in varBindRow:
+ print(rfc1902.ObjectType(rfc1902.ObjectIdentity(varBind[0]), varBind[1]).resolveWithMib(mibViewController).prettyPrint())
+ return 1 # signal dispatcher to continue
+
+# Prepare initial request to be sent
+cmdgen.NextCommandGenerator().sendVarBinds(
+ snmpEngine,
+ 'my-router',
+ None, '', # contextEngineId, contextName
+ [ rfc1902.ObjectType(rfc1902.ObjectIdentity('iso.org.dod')).resolveWithMib(mibViewController),
+ rfc1902.ObjectType(rfc1902.ObjectIdentity('IF-MIB', 'ifMIB')).resolveWithMib(mibViewController) ],
+ cbFun
+)
+
+# Run I/O dispatcher which would send pending queries and process responses
+snmpEngine.transportDispatcher.runDispatcher()