diff --git a/inventory_provider/config.py b/inventory_provider/config.py index 8b9d0a6ddf94da9f1ebc79db75d828a232a6ed6d..4636d131f1a47e105dc980450ef067436fd3b57c 100644 --- a/inventory_provider/config.py +++ b/inventory_provider/config.py @@ -111,6 +111,7 @@ CONFIG_SCHEMA = { 'gws-direct-interface': { 'type': 'object', 'properties': { + 'info': {'type': 'string'}, 'tag': {'type': 'string'}, 'counters': {'$ref': '#/definitions/gws-direct-counters'} }, diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index f4fa2897c37f676b7d89c049703998745b348ba7..1b3de81627e01328400aa2c3247b5fb7e8fd384c 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -309,7 +309,8 @@ GWS_DIRECT_DATA_SCHEMA = { 'type': 'array', 'items': {'$ref': '#/definitions/counter'}, 'minItems': 1 - } + }, + 'info': {'type': 'string'} }, 'required': [ 'nren', 'isp', 'hostname', 'tag', 'counters'], @@ -1003,7 +1004,7 @@ def gws_direct(): snmp_params['priv'] = host['priv'] for ifc in host['interfaces']: - yield { + ifc_data = { 'nren': nren_isp['nren'], 'isp': nren_isp['isp'], 'hostname': host['hostname'], @@ -1016,6 +1017,9 @@ def gws_direct(): } for k, v in ifc['counters'].items()] } + if 'info' in ifc: + ifc_data['info'] = ifc['info'] + yield ifc_data result = json.dumps(list(_interfaces())) @@ -1333,21 +1337,10 @@ def gws_direct_config(): 'snmp': snmp_version, 'interface': ifc['tag'], 'field': field, - 'oid': oid + 'oid': oid, + 'info': ifc.get('info', '') } - def _to_row(counter, header=False): - _columns = ( - 'nren', 'isp', 'hostname', 'snmp', 'interface', 'field', 'oid') - elems = ['<tr>'] - for name in _columns: - if header: - elems.append(f'<th>{name}</th>') - else: - elems.append(f'<td>{counter[name]}</td>') - elems.append('</tr>') - return ''.join(elems) - if format == 'json': if not request.accept_mimetypes.accept_json: return Response( @@ -1363,12 +1356,50 @@ def gws_direct_config(): status=406, mimetype="text/html") - elems = ['<html>', '<body>', '<table>'] - elems.append(_to_row(None, header=True)) - elems += map(_to_row, _counters()) - elems += ['</table>', '</body>', '</html>'] + page = '''<!doctype html> +<html lang="en"> + <head> + <!-- Required meta tags --> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> + + <!-- Bootstrap CSS --> + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> + + <title>GWS Direct config</title> + </head> + <body> + <table class="table table-striped"> + <thead> +{header_row} + </thead> + <tbody> +{data_rows} + </tbody> + </table> + </body> +</html>''' # noqa: E501 + + def _to_row(counter, header=False): + _columns = ( + 'nren', 'isp', 'hostname', + 'snmp', 'interface', 'field', 'oid', 'info') + elems = ['<tr>'] + for name in _columns: + if header: + elems.append(f'<th scope="col">{name}</th>') + else: + elems.append(f'<td scope="row">{counter[name]}</td>') + elems.append('</tr>') + return ''.join(elems) + + header_row = _to_row(None, header=True) + data_rows = map(_to_row, _counters()) + page = page.format( + header_row=header_row, + data_rows='\n'.join(data_rows)) return Response( - response=''.join(elems), + response=page, status=200, mimetype="text/html") diff --git a/setup.py b/setup.py index b7e45b147356e075b6fd400d70707af69d9181a5..0cdd6a901bc7107fccb0d7ea956f6a27f225a2fd 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='inventory-provider', - version="0.72", + version="0.73", author='GEANT', author_email='swd@geant.org', description='Dashboard inventory provider', diff --git a/test/data/gws-direct.json b/test/data/gws-direct.json index 3e399fc623f0ffa1481f8c90ed4075af08186918..c2232886f75f5274905fd5e367abb81cbb605f0d 100644 --- a/test/data/gws-direct.json +++ b/test/data/gws-direct.json @@ -264,6 +264,7 @@ "interfaces": [ { "tag": "a", + "info": "Some PSNC CenturyLink text, interface XX-9/9/9.123 #123", "counters": { "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.675", "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.675" @@ -304,6 +305,7 @@ "interfaces": [ { "tag": "a", + "info": "Some HEANET CenturyLink text", "counters": { "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.645", "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.645" diff --git a/test/test_general_poller_routes.py b/test/test_general_poller_routes.py index f9244bb5e6ef72d9a8225f83a868ecdc21004737..9e01321e02b554c6c5aa581239459d72095acea5 100644 --- a/test/test_general_poller_routes.py +++ b/test/test_general_poller_routes.py @@ -76,7 +76,7 @@ def test_gws_direct(client): assert rv.is_json response_data = json.loads(rv.data.decode('utf-8')) jsonschema.validate(response_data, poller.GWS_DIRECT_DATA_SCHEMA) - assert response_data, "the subscription list shouldn't be empty" + assert response_data, "the service list shouldn't be empty" def test_gws_indirect(client): @@ -337,5 +337,4 @@ def test_gws_config_html(client): response_data = rv.data.decode('utf-8') # just a sanity check, no validation # ... for now, this isn't an important interface - assert response_data.startswith('<html>') assert response_data.endswith('</html>')