from typing import DefaultDict from brian_dashboard_manager.templating.helpers import get_dashboard_data def get_panel_data(interfaces): result = DefaultDict(list) count = {} def add_num(iface): name = iface['nren'] + iface['isp'] + iface['tag'] count[name] = count.get(name, 0) + 1 iface['num'] = count[name] return iface # Add a number to multiple interfaces for same nren/isp combination, # as they share the same tag if the hostnames are different. interfaces = list(map(add_num, interfaces)) for interface in interfaces: isp = interface.get('isp') nren = interface.get('nren') hostname = interface.get('hostname') # identifier for interface, as we don't have their names interface_tag = interface.get('tag') if_num = interface.get('num') counters = interface.get('counters') skip = True for counter in counters: if counter.get('field') in ['traffic_in', 'traffic_out']: skip = False if skip: # only process interfaces where we are polling traffic data continue gws_measurement = 'gwsd_rates' title = f'{nren} GWS Direct {isp} Interface {if_num} ({hostname})' result[f'GWS Direct - {isp}'].append({ 'isp': isp, 'nren': nren, 'measurement': gws_measurement, 'title': title, 'interface_tag': interface_tag, 'hostname': hostname, 'has_v6': False }) return result def get_gws_indirect_panel_data(interfaces): result = DefaultDict(list) for interface in interfaces: hostname = interface.get('hostname').replace('.geant.net', '') if_name = interface.get('interface') service_name = interface.get('name') customer = interface.get('customer') measurement = 'dscp32_rates' panel_title = f'{hostname} - {{}} - {if_name} - #{service_name} IASGWS' result[f'GWS Indirect - {customer}'].append({ 'measurement': measurement, 'title': panel_title, 'interface': if_name, 'hostname': interface.get('hostname'), 'has_v6': False }) return result def generate_gws(gws_data, datasource): panel_data = get_panel_data(gws_data) for dash in get_dashboard_data(panel_data, datasource, 'GWS_DIRECT'): yield dash def generate_indirect(gws_data, datasource): panel_data = get_gws_indirect_panel_data(gws_data) for dash in get_dashboard_data(panel_data, datasource, 'GWS_INDIRECT'): yield dash