From 6078a8eaae571909adc6a87b7d77e7427714cf40 Mon Sep 17 00:00:00 2001 From: Robert Latta <robert.latta@geant.org> Date: Fri, 25 Jan 2019 11:17:09 +0000 Subject: [PATCH] trap metadata api implementation --- inventory_provider/routes/classifier.py | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index 85dcbd77..1fbb0793 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -69,3 +69,43 @@ def juniper_addresses(): servers = json.loads(servers.decode('utf-8')) jsonschema.validate(servers, backend_data_schema) return jsonify([s['ip_address'] for s in servers]) + + +@routes.route("/trap-metadata/<trap_type>/<source_equipment>/<path:interface>", + methods=['GET', 'POST']) +@require_accepts_json +def get_trap_metadata(trap_type, source_equipment, interface): + # todo - Move this to config + interface_info_key = "interface_services" + r = db.get_redis() + + # todo - Change this to a call to the yet-to-be-created one source of all + # relevant information + # This could be different calls dependant on vendor, in which case we may + # need to check the trap type, or it could be a case of a key check for + # each possible data source + interface_info = r.hget(interface_info_key, + "{}::{}".format(source_equipment, interface)) + + if not interface_info: + return Response( + response="no available info for {} {}".format( + source_equipment, interface), + status=404, + mimetype="text/html") + + interface_info = json.loads(interface_info.decode('utf-8')) + + # todo - refactor once structure of new source is decided, currently this + # is just a list of services + vendor = interface_info[0]['manufacturer'] + hostname = interface_info[0]['equipment'] + result = { + "vendor": vendor, + "equipment-name": hostname, + "interface-name": interface, + "services": interface_info, + "type": trap_type + } + + return jsonify(result) -- GitLab