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

Merge branch 'feature/trap-inventory-response-api' into develop

parents c6f200a9 40a82881
No related branches found
No related tags found
No related merge requests found
...@@ -269,4 +269,18 @@ Any non-empty responses are JSON formatted messages. ...@@ -269,4 +269,18 @@ Any non-empty responses are JSON formatted messages.
"type": "array", "type": "array",
"items": {"type": "string"} "items": {"type": "string"}
} }
```
* /classifier/*`type`*/*`source-equipment`*/`*source-interface*`
The source-equipment is the equipment that causes the trap, not the NMS that
sends it.
The response will be an object containing the metadata
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object"
}
``` ```
\ No newline at end of file
...@@ -69,3 +69,43 @@ def juniper_addresses(): ...@@ -69,3 +69,43 @@ def juniper_addresses():
servers = json.loads(servers.decode('utf-8')) servers = json.loads(servers.decode('utf-8'))
jsonschema.validate(servers, backend_data_schema) jsonschema.validate(servers, backend_data_schema)
return jsonify([s['ip_address'] for s in servers]) 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)
...@@ -73,3 +73,39 @@ def test_juniper_addresses(mocker, client): ...@@ -73,3 +73,39 @@ def test_juniper_addresses(mocker, client):
jsonschema.validate(response_data, response_schema) jsonschema.validate(response_data, response_schema)
assert len(response_data) == len(test_data) assert len(response_data) == len(test_data)
assert set([x['ip_address'] for x in test_data]) == set(response_data) assert set([x['ip_address'] for x in test_data]) == set(response_data)
def test_trap_metadata(mocker, client):
test_data = [
{
"equipment": "test-equipment",
"manufacturer": "test-manufacturer",
"vendor": "test-vendor",
"absid": "1234",
"name": "test-service_1"
},
{
"equipment": "test-equipment",
"manufacturer": "test-manufacturer",
"vendor": "test-vendor",
"absid": "2345",
"name": "test-service_2"
}
]
mocked_redis = mocker.patch(
"inventory_provider.routes.classifier.db.get_redis")
mocked_redis.return_value.hget.return_value = json.dumps(test_data)\
.encode("utf-8")
response_schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object"
}
rv = client.get(
'/classifier/trap-metadata/BGP/dummy-equipment/xe-2/3/1',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, response_schema)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment