Skip to content
Snippets Groups Projects
Commit fab575f6 authored by Erik Reid's avatar Erik Reid
Browse files
parent 135074e8
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,6 @@ from pysnmp.hlapi import nextCmd, SnmpEngine, CommunityData, \
UdpTransportTarget, ContextData, ObjectType, ObjectIdentity
def walk(agent_hostname, community, base_oid):
"""
https://stackoverflow.com/a/45001921
......@@ -16,11 +15,25 @@ def walk(agent_hostname, community, base_oid):
http://snmplabs.com/pysnmp/faq/pass-custom-mib-to-manager.html
https://github.com/etingof/pysnmp/blob/master/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py
http://snmplabs.com/pysnmp/examples/smi/manager/browsing-mib-tree.html
:param agent_hostname:
:param community:
:param base_oid:
:return:
"""
from pysnmp.smi import builder, view, compiler, rfc1902
mibBuilder = builder.MibBuilder()
mibViewController = view.MibViewController(mibBuilder)
compiler.addMibCompiler(mibBuilder, sources=['http://mibs.snmplabs.com/asn1/@mib@'])
# Pre-load MIB modules we expect to work with
mibBuilder.loadModules('SNMPv2-MIB', 'SNMP-COMMUNITY-MIB', 'RFC1213-MIB')
print("walking %s: %s" % (agent_hostname, base_oid))
for (engineErrorIndication,
pduErrorIndication,
......@@ -30,8 +43,11 @@ def walk(agent_hostname, community, base_oid):
CommunityData(community),
UdpTransportTarget((agent_hostname, 161)),
ContextData(),
ObjectType(ObjectIdentity(base_oid)),
lexicographicMode=False):
ObjectType(ObjectIdentity(base_oid)
.addAsn1MibSource('http://mibs.snmplabs.com/asn1/@mib@')),
lexicographicMode=False,
lookupNames=True,
lookupValues=True):
assert not engineErrorIndication
assert not pduErrorIndication
assert errorIndex == 0
......@@ -39,6 +55,14 @@ def walk(agent_hostname, community, base_oid):
print("\toid: '%s', val: '%s'" % (
oid.prettyPrint(), val.prettyPrint()))
zzz = [
rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]),x[1])
.resolveWithMib(mibViewController) for x
in
varBinds]
for z in zzz:
print('zzz: %s' % z.prettyPrint())
def _validate_config(ctx, param, value):
"""
......@@ -130,7 +154,10 @@ def cli(config):
with open("routers_community.conf") as f:
for r in load_routers(f):
_db_test(c, r)
# walk(r["address"], r["community"], ".1.3.6.1.2.1.4.20.1.1")
walk(r["hostname"], r["community"], ".1.3.6.1.2.1.4.20.1.1")
break
if __name__ == "__main__":
cli()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment