diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index 85dcbd779d3d419b12625f402b9b17c16ca8a55f..1fbb0793a182a2b0d6b79b09c32801636b4155d7 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)