diff options
author | elie <elie> | 2015-05-17 21:01:43 +0000 |
---|---|---|
committer | elie <elie> | 2015-05-17 21:01:43 +0000 |
commit | a4fb54639e97cb572689e24a5c5e42b4f66a62e0 (patch) | |
tree | 96ae7dcd54ba6cbc090d33018993f4f993bab72e /examples/v3arch | |
parent | 1118e0d43b694f8a1b68e4d0b9d72b2e7e6c8277 (diff) | |
download | pysnmp-a4fb54639e97cb572689e24a5c5e42b4f66a62e0.tar.gz |
- Initial PySMI integration. Original ASN.1 MIBs could now be parsed, stored
at a local pysnmp MIBs repository and loaded into SNMP Engine.
- smi.MibBuilder will now raise more specific exceptions (MibLoadError,
MibNotFoundError) on MIB loading problems rather than more generic
SmiError.
- MibBuilder.addMibSources() convenience method added.
Diffstat (limited to 'examples/v3arch')
-rw-r--r-- | examples/v3arch/oneliner/manager/cmdgen/get-v2c-with-asn1-mib-lookup.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/v3arch/oneliner/manager/cmdgen/get-v2c-with-asn1-mib-lookup.py b/examples/v3arch/oneliner/manager/cmdgen/get-v2c-with-asn1-mib-lookup.py new file mode 100644 index 0000000..a8f1e73 --- /dev/null +++ b/examples/v3arch/oneliner/manager/cmdgen/get-v2c-with-asn1-mib-lookup.py @@ -0,0 +1,37 @@ +# +# 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 +from pysnmp import debug + +#debug.setLogger(debug.Debug('mibbuild')) + +cmdGen = cmdgen.CommandGenerator() + +errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( + cmdgen.CommunityData('public'), + cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), + cmdgen.MibVariable('IF-MIB', 'ifInOctets', '1').addAsn1Sources('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 name, val in varBinds: + print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) |