Skip to content
Snippets Groups Projects

Feature/DBOARD3-917 Add endpoint for error report interfaces list

Merged Pelle Koster requested to merge feature/DBOARD3-917-error-report-interfaces into develop
Files
5
@@ -54,6 +54,12 @@ These endpoints are intended for use by BRIAN.
.. autofunction:: inventory_provider.routes.poller.get_service_types
/poller/error-report-interfaces</hostname>
------------------------------------------
.. autofunction:: inventory_provider.routes.poller.error_report_interfaces
support method: _get_dashboards
---------------------------------
@@ -209,6 +215,25 @@ INTERFACE_LIST_SCHEMA = {
'items': {'$ref': '#/definitions/interface'}
}
ERROR_REPORT_INTERFACE_LIST_SCHEMA = {
'$schema': 'https://json-schema.org/draft-07/schema#',
'definitions': {
'interface': {
'type': 'object',
'properties': {
'router': {'type': 'string'},
'name': {'type': 'string'},
'description': {'type': 'string'},
'vendor': {'type': 'string', 'enum': ['juniper', 'nokia']}
},
'required': ['router', 'name', 'description', 'vendor'],
'additionalProperties': False
},
},
'type': 'array',
'items': {'$ref': '#/definitions/interface'}
}
INTERFACE_SPEED_LIST_SCHEMA = {
'$schema': 'https://json-schema.org/draft-07/schema#',
@@ -883,6 +908,89 @@ def interfaces(hostname=None):
return Response(result, mimetype="application/json")
def load_error_report_interfaces(
config, hostname=None, use_next_redis=False
):
interfaces = _load_interfaces(config, hostname, use_next_redis=use_next_redis)
def filter_interface(interface: dict):
return all(
(
"phy" in interface["description"].lower(),
"spare" not in interface["description"].lower(),
"non-operational" not in interface["description"].lower(),
"reserved" not in interface["description"].lower(),
"test" not in interface["description"].lower(),
"dsc." not in interface["name"].lower(),
"fxp" not in interface["name"].lower(),
)
)
def transform_interface(interface: dict):
return {
"router": interface["router"],
"name": interface["name"],
"description": interface["description"],
# TODO: This is a complete hack until we have a proper way to determine
# router vendor
"vendor": "nokia" if interface["router"].startswith("rt0") else "juniper"
}
return sorted(
map(transform_interface, filter(filter_interface, interfaces)),
key=lambda i: (i["router"], i["name"]),
)
@routes.route("/error-report-interfaces", methods=['GET'])
@routes.route('/error-report-interfaces/<hostname>', methods=['GET'])
@common.require_accepts_json
def error_report_interfaces(hostname=None):
"""
Handler for `/poller/error-report-interfaces` and
`/poller/error-report-interfaces/<hostname>`
which returns information for either all interfaces
or those on the requested hostname.
The optional `no-lab` parameter omits lab routers
if it's truthiness evaluates to True.
The response is a list of information for all
interfaces that should be included in the neteng error report
and includes vendor information (either juniper or nokia)
.. asjson::
inventory_provider.routes.poller.ERROR_REPORT_INTERFACE_LIST_SCHEMA
:param hostname: optional, if present should be a router hostname
:return:
"""
suffix = hostname or "all"
cache_key = f'classifier-cache:error-report-interfaces:{suffix}'
r = common.get_current_redis()
result = _ignore_cache_or_retrieve(request, cache_key, r)
if not result:
interfaces = load_error_report_interfaces(
current_app.config['INVENTORY_PROVIDER_CONFIG'], hostname
)
result = json.dumps(interfaces).encode('utf-8')
# cache this data for the next call
r.set(cache_key, result)
if not result or result == b'[]':
return Response(
response='no interfaces found',
status=404,
mimetype='text/plain'
)
return Response(result, mimetype="application/json")
def interface_speed(ifc):
"""
Return the maximum bits per second expected for the given interface.
Loading