Skip to content
Snippets Groups Projects
Commit af7c71b8 authored by Erik Reid's avatar Erik Reid
Browse files

added dashboards to interfaces response

parent ad924884
Branches
Tags
No related merge requests found
...@@ -49,6 +49,7 @@ These endpoints are intended for use by BRIAN. ...@@ -49,6 +49,7 @@ These endpoints are intended for use by BRIAN.
""" """
from enum import Enum, auto
import json import json
import logging import logging
import re import re
...@@ -68,6 +69,32 @@ routes = Blueprint('poller-support-routes', __name__) ...@@ -68,6 +69,32 @@ routes = Blueprint('poller-support-routes', __name__)
Gb = 1 << 30 Gb = 1 << 30
class BRIAN_DASHBOARDS(Enum):
CLS = auto()
RE_PEER = auto()
RE_CUST = auto()
GEANTOPEN = auto()
GCS = auto()
L2_CIRCUIT = auto()
LHCONE_PEER = auto()
LHCONE_CUST = auto()
MDVPN_CUSTOMERS = auto()
INFRASTRUCTURE_BACKBONE = auto()
IAS_PRIVATE = auto()
IAS_PUBLIC = auto()
IAS_CUSTOMER = auto()
IAS_UPSTREAM = auto()
GWS_PHY_UPSTREAM = auto()
# aggregate dashboards
CLS_PEERS = auto()
IAS_PEERS = auto()
GWS_UPSTREAMS = auto()
LHCONE = auto()
CAE1 = auto()
INTERFACE_LIST_SCHEMA = { INTERFACE_LIST_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#', '$schema': 'http://json-schema.org/draft-07/schema#',
...@@ -296,6 +323,69 @@ def after_request(resp): ...@@ -296,6 +323,69 @@ def after_request(resp):
return common.after_request(resp) return common.after_request(resp)
def _get_dashboards(interface):
router = interface.get('router', '').lower()
ifc_name = interface.get('name', '')
description = interface.get('description', '').strip()
if 'SRV_CLS' in description:
yield BRIAN_DASHBOARDS.CLS
if 'SRV_CLS PRIVATE' in description:
yield BRIAN_DASHBOARDS.CLS_PEERS
if 'SRV_IAS PUBLIC' in description:
yield BRIAN_DASHBOARDS.IAS_PUBLIC
yield BRIAN_DASHBOARDS.IAS_PEERS
if 'SRV_IAS PRIVATE' in description:
yield BRIAN_DASHBOARDS.IAS_PRIVATE
yield BRIAN_DASHBOARDS.IAS_PEERS
if 'SRV_IAS CUSTOMER' in description:
yield BRIAN_DASHBOARDS.IAS_CUSTOMER
if 'SRV_IAS UPSTREAM' in description:
yield BRIAN_DASHBOARDS.IAS_UPSTREAM
if 'SRV_GLOBAL RE_INTERCONNECT' in description:
yield BRIAN_DASHBOARDS.RE_PEER
if re.match('(PHY|LAG|SRV_GLOBAL) CUSTOMER', description):
yield BRIAN_DASHBOARDS.RE_CUST
if re.match('^SRV_GCS', description):
yield BRIAN_DASHBOARDS.GCS
if 'GEANTOPEN' in description:
yield BRIAN_DASHBOARDS.GEANTOPEN
if 'SRV_L2CIRCUIT' in description:
yield BRIAN_DASHBOARDS.L2_CIRCUIT
if 'LHCONE' in description:
if 'SRV_L3VPN RE' in description:
yield BRIAN_DASHBOARDS.LHCONE_PEER
if 'SRV_L3VPN CUSTOMER' in description:
yield BRIAN_DASHBOARDS.LHCONE_CUST
if re.match('SRV_L3VPN (CUSTOMER|RE_INTERCONNECT)', description):
yield BRIAN_DASHBOARDS.LHCONE
if re.match('^SRV_MDVPN CUSTOMER', description):
yield BRIAN_DASHBOARDS.MDVPN_CUSTOMERS
if 'LAG' in description and \
re.match('(SRV_GLOBAL|LAG|PHY) INFRASTRUCTURE BACKBONE',
description):
yield BRIAN_DASHBOARDS.INFRASTRUCTURE_BACKBONE
if router == 'mx1.lon.uk.geant.net' \
and re.match(r'^ae12(\.\d+|$)$', ifc_name):
yield BRIAN_DASHBOARDS.CAE1
if re.match('^PHY UPSTREAM', description):
yield BRIAN_DASHBOARDS.GWS_PHY_UPSTREAM
def _add_dashboards(interfaces):
"""
generator that dashboards to each interfaces.
:param interfaces: result of _load_interfaces
:return: generator with `dashboards` populated in each element
"""
for ifc in interfaces:
ifc['dashboards'] = sorted(list(_get_dashboards(ifc)))
yield ifc
def _load_interface_bundles(hostname=None): def _load_interface_bundles(hostname=None):
result = dict() result = dict()
...@@ -476,15 +566,20 @@ def _load_interfaces_to_poll(hostname=None): ...@@ -476,15 +566,20 @@ def _load_interfaces_to_poll(hostname=None):
:return: generator yielding interface elements :return: generator yielding interface elements
""" """
basic_interfaces = _load_interfaces(hostname) basic_interfaces = _load_interfaces(hostname)
# basic_interfaces = list(basic_interfaces)
with_bundles = _add_bundle_parents(basic_interfaces, hostname) with_bundles = _add_bundle_parents(basic_interfaces, hostname)
with_circuits = _add_circuits(with_bundles, hostname) with_circuits = _add_circuits(with_bundles, hostname)
# with_circuits = list(with_circuits)
with_snmp = _add_snmp_indexes(with_circuits, hostname) with_snmp = _add_snmp_indexes(with_circuits, hostname)
# with_snmp = list(with_snmp)
# only return interfaces that can be polled
def _has_snmp_index(ifc): def _has_snmp_index(ifc):
return 'snmp-index' in ifc return 'snmp-index' in ifc
# only return interfaces that can be polled to_poll = filter(_has_snmp_index, with_snmp)
return filter(_has_snmp_index, with_snmp)
return _add_dashboards(to_poll)
@routes.route("/interfaces", methods=['GET', 'POST']) @routes.route("/interfaces", methods=['GET', 'POST'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment