Skip to content
Snippets Groups Projects
Commit 6078a8ea authored by Robert Latta's avatar Robert Latta
Browse files

trap metadata api implementation

parent c6f200a9
No related branches found
No related tags found
No related merge requests found
......@@ -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)
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