Skip to content
Snippets Groups Projects
Commit 75b01fc8 authored by Erik Reid's avatar Erik Reid
Browse files

zip v4 interface responses

parent 27040d4f
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,6 @@ def walk(agent_hostname, community, base_oid): ...@@ -33,7 +33,6 @@ def walk(agent_hostname, community, base_oid):
# Pre-load MIB modules we expect to work with # Pre-load MIB modules we expect to work with
mibBuilder.loadModules('SNMPv2-MIB', 'SNMP-COMMUNITY-MIB', 'RFC1213-MIB') mibBuilder.loadModules('SNMPv2-MIB', 'SNMP-COMMUNITY-MIB', 'RFC1213-MIB')
print("walking %s: %s" % (agent_hostname, base_oid)) print("walking %s: %s" % (agent_hostname, base_oid))
for (engineErrorIndication, for (engineErrorIndication,
pduErrorIndication, pduErrorIndication,
...@@ -50,13 +49,14 @@ def walk(agent_hostname, community, base_oid): ...@@ -50,13 +49,14 @@ def walk(agent_hostname, community, base_oid):
assert not engineErrorIndication assert not engineErrorIndication
assert not pduErrorIndication assert not pduErrorIndication
assert errorIndex == 0 assert errorIndex == 0
varBinds = [ # varBinds = [
rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]),x[1]) # rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]),x[1])
.resolveWithMib(mibViewController) # .resolveWithMib(mibViewController)
for x in varBinds] # for x in varBinds]
for oid, val in varBinds: for oid, val in varBinds:
print("\toid: '%s', val: '%s'" % ( yield {"oid": "." + str(oid), "value": val.prettyPrint()}
oid.prettyPrint(), val.prettyPrint())) # print("\toid: '%s', val: '%s'" % (
# oid.prettyPrint(), val.prettyPrint()))
def _validate_config(ctx, param, value): def _validate_config(ctx, param, value):
""" """
...@@ -135,6 +135,59 @@ def _db_test(db, router): ...@@ -135,6 +135,59 @@ def _db_test(db, router):
print(absid) print(absid)
def get_router_interfaces(router):
with open("oid_list.conf") as f:
oid_map = load_oids(f)
details = {}
for name, oid in oid_map.items():
details[name] = walk(router["hostname"], router["community"], oid)
print(name)
details[name] = list(details[name])
print(details[name])
# assert len(details["v4Address"]) == len(details["v4Mask"])
# assert len(details["v4Address"]) == len(details["v4InterfaceOID"])
interface_names = dict([x["oid"], x["value"]]
for x in details["v4InterfaceName"])
interfaces = []
for v4Address, v4Mask, v4InterfaceOID in zip(
details["v4Address"],
details["v4Mask"],
details["v4InterfaceOID"]):
ifc_oid = oid_map["v4InterfaceName"] + "." + v4InterfaceOID["value"]
v4InterfaceName = interface_names[ifc_oid]
interfaces.append({
"v4Address": v4Address["value"],
"v4Mask": v4Mask["value"],
"v4InterfaceName": v4InterfaceName
})
print(interfaces)
return interfaces
"""
v4Address=.1.3.6.1.2.1.4.20.1.1
v4InterfaceOID=.1.3.6.1.2.1.4.20.1.2
v4InterfaceName=.1.3.6.1.2.1.31.1.1.1.1
v4Mask=.1.3.6.1.2.1.4.20.1.3
## IPv6
v6AddressAndMask=.1.3.6.1.2.1.55.1.8.1.2
v6InterfaceName=.1.3.6.1.2.1.55.1.5.1.2
"""
# interfaces = []
#
# # for name, oid in
# # # 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")
# print(details)
#
#
@click.command() @click.command()
@click.option( @click.option(
"--config", "--config",
...@@ -144,13 +197,14 @@ def _db_test(db, router): ...@@ -144,13 +197,14 @@ def _db_test(db, router):
default=open("config.json"), default=open("config.json"),
callback=_validate_config) callback=_validate_config)
def cli(config): def cli(config):
with connection(config["alarms-db"]) as c: with open("routers_community.conf") as f:
with open("routers_community.conf") as f: for r in load_routers(f):
for r in load_routers(f):
with connection(config["alarms-db"]) as c:
_db_test(c, r) _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") get_router_interfaces(r)
break break
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment