diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index 794046af1e36dde87afe1a46d7efbb8d99b06d8d..66cc126ac877d9310d8545eb588697087adf6c1d 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -1,6 +1,10 @@ import functools from flask import Blueprint, request, Response, current_app, jsonify +import json +import jsonschema + +from inventory_provider import db routes = Blueprint("inventory-data-classifier-support-routes", __name__) @@ -31,3 +35,29 @@ def infinera_addresses(): "INVENTORY_PROVIDER_CONFIG"]["infinera-dna"] return jsonify([dna['address'] for dna in infinera_config]) + +@routes.route("/juniper-server-addresses", methods=['GET', 'POST']) +@require_accepts_json +def juniper_addresses(): + backend_data_schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "array", + "items": { + "type": "object", + "properties": { + "ip_address": {"type": "string"} + }, + "required": ["ip_address"] + } + } + + servers = db.get_redis().get('alarmsdb:juniper_servers') + if not servers: + return Response( + response="no juniper server data found", + status=404, + mimetype="text/html") + + servers = json.loads(servers.decode('utf-8')) + jsonschema.validate(servers, backend_data_schema) + return jsonify([s['ip_address'] for s in servers])