Skip to content
Snippets Groups Projects

Regions included in dashboard generation

Merged Sam Roberts requested to merge feature/POL1-430-more-changes into develop
@@ -469,7 +469,7 @@ def after_request(resp):
return common.after_request(resp)
def _get_dashboards(interface):
def _get_dashboards(interface, region=None):
"""
Yield enums from BRIAN_DASHBOARDS to indicate which dashboards
this interface should be included in.
@@ -482,12 +482,14 @@ def _get_dashboards(interface):
inventory_provider.routes.poller._DASHBOARD_IDS
:param interface: a dict with keys like router, name, description
:param region: a key from the regions dict
:return: generator that yields enums from BRIAN_DASHBOARDS
"""
router = interface.get('router', '').lower()
ifc_name = interface.get('name', '')
description = interface.get('description', '').strip()
if 'SRV_L3VPN' in description and 'COPERNICUS' in description:
yield BRIAN_DASHBOARDS.COPERNICUS
if re.match(r'SRV_CLS\s', description):
@@ -539,11 +541,12 @@ def _get_dashboards(interface):
if re.match(r'PHY UPSTREAM\s', description):
yield BRIAN_DASHBOARDS.GWS_PHY_UPSTREAM
regex = r'(PHY|LAG|(SRV_(GLOBAL|LHCONE|MDVPN|IAS|CLS|L3VPN))) CUSTOMER\s'
if re.match(regex, description):
if re.match(regex, description) and region is None:
yield BRIAN_DASHBOARDS.NREN
if "GA-" in description and "ANA-" in description:
yield BRIAN_DASHBOARDS.ANA
if region == 'EAP':
yield BRIAN_DASHBOARDS.EAP
def _get_dashboard_data(ifc, customers, regions=None):
if regions is None:
@@ -873,6 +876,10 @@ def load_interfaces_to_poll(config, hostname=None, no_lab=False, use_next_redis=
_get_services_and_customers(config, hostname, use_next_redis)
snmp_indexes = common.load_snmp_indexes(config, hostname, use_next_redis)
nren_regions = _load_nren_regions(config, use_next_redis)
unique_regions = set(nren_regions.values())
region_index = {}
for region_key in unique_regions:
region_index[region_key] = {nren for nren, reg in nren_regions.items() if reg == region_key}
def _get_populated_interfaces(all_interfaces):
if use_next_redis:
@@ -900,7 +907,16 @@ def load_interfaces_to_poll(config, hostname=None, no_lab=False, use_next_redis=
and ifc_services_and_customers['services']:
ifc['circuits'] = ifc_services_and_customers['services']
dashboards = _get_dashboards(ifc)
_customers = ifc_services_and_customers.get('customers', [])
customer_set = {c['name'] for c in _customers}
region = None
for region_name in region_index:
# check if any of the customers are in this region
if region_index[region_name] & customer_set:
# customers will only have one region, so if there's a match, break here
region = region_name
break
dashboards = _get_dashboards(ifc, region)
ifc['dashboards'] = sorted([d.name for d in dashboards])
ifc = _get_dashboard_data(
Loading