From e4a800cd7fb2d186de5541110b8ef1b65f178cda Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Thu, 27 Jun 2019 16:51:51 +0200 Subject: [PATCH] removed get_router_snmp_indexes --- inventory_provider/snmp.py | 53 ------------------------------ inventory_provider/tasks/worker.py | 5 ++- 2 files changed, 2 insertions(+), 56 deletions(-) diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py index b8ee1f85..06681911 100644 --- a/inventory_provider/snmp.py +++ b/inventory_provider/snmp.py @@ -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)) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 71d8e000..8779a1d4 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -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)) -- GitLab