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

removed get_router_snmp_indexes

parent cc5a5598
No related branches found
No related tags found
No related merge requests found
......@@ -88,56 +88,3 @@ def get_router_snmp_indexes(hostname, community):
assert m, 'sanity failure parsing oid: %r' % ifc['oid']
indexes[ifc['value']] = int(m.group(1))
return indexes
def get_router_interfaces(hostname, community, config):
oid_map = config["oids"]
details = {}
for name, oid in oid_map.items():
details[name] = walk(hostname, community, oid)
details[name] = list(details[name])
v4IfcNames = {}
for v4IfcName in details["v4InterfaceName"]:
m = re.match(r'.*\.(\d+)$', v4IfcName["oid"])
assert m, "sanity failure parsing oid: " + v4IfcName["oid"]
v4IfcNames[m.group(1)] = v4IfcName["value"]
for v4Address, v4Mask, v4InterfaceOID in zip(
details["v4Address"],
details["v4Mask"],
details["v4InterfaceOID"]):
yield {
"v4Address": v4Address["value"],
"v4Mask": v4Mask["value"],
"v4InterfaceName": v4IfcNames[v4InterfaceOID["value"]],
"index": v4InterfaceOID["value"]
}
v6IfcNames = {}
for v6InterfaceName in details["v6InterfaceName"]:
m = re.match(r'.*\.(\d+)$', v6InterfaceName["oid"])
assert m, "sanity failure parsing oid: " + v6InterfaceName["oid"]
v6IfcNames[m.group(1)] = v6InterfaceName["value"]
for v6AddressAndMask in details["v6AddressAndMask"]:
pattern = (
r'^'
+ oid_map["v6AddressAndMask"].replace(r'.', r'\.')
+ r'\.(\d+)\.(.+)$'
)
m = re.match(pattern, v6AddressAndMask["oid"])
assert m, "sanity failure parsing oid: " + v6InterfaceName["oid"]
yield {
"v6Address": _v6address_oid2str(m.group(2)),
"v6Mask": v6AddressAndMask["value"],
"v6InterfaceName": v6IfcNames[m.group(1)],
"index": m.group(1)
}
if __name__ == "__main__":
hostname = 'mx1.ams.nl.geant.net'
community = '0pBiFbD'
interfaces = get_router_snmp_indexes(hostname, community)
for name, index in interfaces.items():
print('%s: %s' % (name, index))
......@@ -91,10 +91,9 @@ def snmp_refresh_interfaces(hostname, community):
_save_value_json(
'snmp-interfaces:' + hostname,
list(snmp.get_router_interfaces(
list(snmp.get_router_snmp_indexes(
hostname,
community,
InventoryTask.config)))
community)))
logger.debug(
'<<< snmp_refresh_interfaces(%r, %r)' % (hostname, community))
......
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