diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index c78f35f7cefcfc42e35fc9ae124e6e1e1b67505f..ad3b5db05214a1133e607b1a49b8e6ec7a55c0ac 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -240,7 +240,7 @@ def get_juniper_link_info(source_equipment, interface): # cache this data for the next call r.set(cache_key, result.encode('utf-8')) - return Response(result, mimetype="application/json") + return Response(result, mimetype='application/json') def ix_peering_info(peer_info): @@ -362,14 +362,14 @@ def peer_info(address): 'locations': [] } - info = r.get('ix_public_peer:%s' % address) + info = r.get(f'ix_public_peer:{address}') if info: info = info.decode('utf-8') info = json.loads(info) result['ix-public-peer-info'] = ix_peering_info(info) result['locations'] += _locations_from_router(info['router']) - info = r.get('vpn_rr_peer:%s' % address) + info = r.get(f'vpn_rr_peer:{address}') if info: info = info.decode('utf-8') info = json.loads(info) @@ -383,12 +383,21 @@ def peer_info(address): result['locations'] += [ _location_from_service_dict(s) for s in i['services']] + snmp_info = r.get( + f'snmp-peerings:{address}') + if snmp_info: + snmp_info = json.loads(snmp_info.decode('utf-8')) + result['snmp'] = { + 'community': snmp_info['community'], + 'oid': snmp_info['oid'] + } + result['locations'] = _remove_duplicates_from_list(result['locations']) result = json.dumps(result) # cache this data for the next call r.set(cache_key, result.encode('utf-8')) - return Response(result, mimetype="application/json") + return Response(result, mimetype='application/json') @routes.route("/infinera-lambda-info/" @@ -442,7 +451,7 @@ def get_trap_metadata(source_equipment, interface, circuit_id): # cache this data for the next call r.set(cache_key, result.encode('utf-8')) - return Response(result, mimetype="application/json") + return Response(result, mimetype='application/json') @routes.route("/infinera-fiberlink-info/<ne_name_str>/<object_name_str>", @@ -512,7 +521,7 @@ def get_fiberlink_trap_metadata(ne_name_str, object_name_str): status=404, mimetype="text/html") - return Response(result, mimetype="application/json") + return Response(result, mimetype='application/json') @routes.route('/coriant-info/<equipment_name>/<path:entity_string>', @@ -575,4 +584,4 @@ def get_coriant_info(equipment_name, entity_string): result = json.dumps(result).encode('utf-8') r.set(cache_key, result) - return Response(result, mimetype="application/json") + return Response(result, mimetype='application/json') diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index c263c4168260ccf2c0fd276fe0b45831e87acd9d..2f6edb33781a803d9e6b8627dd9ea350e18d22d7 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -90,6 +90,8 @@ class InventoryTask(Task): def snmp_refresh_peerings(self, hostname, community): try: peerings = list(snmp.get_peer_state_info(hostname, community)) + for p in peerings: + p['community'] = community except ConnectionError: msg = f'error loading snmp peering data from {hostname}' logger.exception(msg)