summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorelie <elie>2015-07-04 16:30:27 +0000
committerelie <elie>2015-07-04 16:30:27 +0000
commita39f371a33466985dee8b9712c820bfae6037954 (patch)
tree1e5b8d2ebae09b66b0595f9d668b1bfb915a94be /examples
parent8ffb93f364237f9b75db5e2017e57c808e200063 (diff)
downloadpysnmp-a39f371a33466985dee8b9712c820bfae6037954.tar.gz
* default /usr/share/mibs MIB source added
* compiler.addMibCompiler() now supports ifAvailable and ifNotAdded flags * rfc1902.ObjectIdentity() now always tries to instantiate and attach MIB compiler to snmpEngine (if not done yet), also .addMibCompiler() renamed to .addAsn1MibSource() to signify the fact that MIB compiler is attached behind the scene
Diffstat (limited to 'examples')
-rw-r--r--examples/smi/mib-lookup.py2
-rw-r--r--examples/v3arch/manager/cmdgen/getnext-v2c-with-mib-compilation-and-lookup.py3
-rw-r--r--examples/v3arch/oneliner/manager/cmdgen/get-v2c-with-mib-compilation-and-lookup.py3
3 files changed, 6 insertions, 2 deletions
diff --git a/examples/smi/mib-lookup.py b/examples/smi/mib-lookup.py
index a208897..69bb7dc 100644
--- a/examples/smi/mib-lookup.py
+++ b/examples/smi/mib-lookup.py
@@ -14,7 +14,7 @@ mibVar = rfc1902.ObjectIdentity('IF-MIB', 'ifInOctets', 1)
# create pysnmp MIBs on demand from ASN.1 sources downloaded from
# a web site.
try:
- mibVar.addMibCompiler('http://mibs.snmplabs.com/asn1/@mib@')
+ mibVar.addAsn1MibSource('http://mibs.snmplabs.com/asn1/@mib@')
except error.SmiError:
print('WARNING: not using MIB compiler (PySMI not installed)')
diff --git a/examples/v3arch/manager/cmdgen/getnext-v2c-with-mib-compilation-and-lookup.py b/examples/v3arch/manager/cmdgen/getnext-v2c-with-mib-compilation-and-lookup.py
index a8c5b35..eab7906 100644
--- a/examples/v3arch/manager/cmdgen/getnext-v2c-with-mib-compilation-and-lookup.py
+++ b/examples/v3arch/manager/cmdgen/getnext-v2c-with-mib-compilation-and-lookup.py
@@ -21,7 +21,10 @@ from pysnmp.smi import compiler, view, rfc1902
snmpEngine = engine.SnmpEngine()
# Attach MIB compiler to SNMP Engine (MIB Builder)
+# This call will fail if PySMI is not present on the system
compiler.addMibCompiler(snmpEngine.getMibBuilder())
+# ... alternatively, this call will not complain on missing PySMI
+#compiler.addMibCompiler(snmpEngine.getMibBuilder(), ifAvailable=True)
# Used for MIB objects resolution
mibViewController = view.MibViewController(snmpEngine.getMibBuilder())
diff --git a/examples/v3arch/oneliner/manager/cmdgen/get-v2c-with-mib-compilation-and-lookup.py b/examples/v3arch/oneliner/manager/cmdgen/get-v2c-with-mib-compilation-and-lookup.py
index 719460a..9c2db80 100644
--- a/examples/v3arch/oneliner/manager/cmdgen/get-v2c-with-mib-compilation-and-lookup.py
+++ b/examples/v3arch/oneliner/manager/cmdgen/get-v2c-with-mib-compilation-and-lookup.py
@@ -7,6 +7,7 @@
# * over IPv4/UDP
# * to an Agent at demo.snmplabs.com:161
# * for IF-MIB::ifInOctets.1 MIB object
+# * Pass attached MIB compiler non-default ASN.1 MIB source
#
from pysnmp.entity.rfc3413.oneliner import cmdgen
@@ -15,7 +16,7 @@ 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@'),
+ cmdgen.ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource('file:///usr/share/snmp', 'http://mibs.snmplabs.com/asn1/@mib@'),
lookupNames=True, lookupValues=True
)