Skip to content
Snippets Groups Projects
Select Git revision
  • fbfc3afde2a0a591e4da7faabbd8b7e88e1a0ef2
  • develop default
  • master protected
  • inventoryProvider-functional
  • inventoryProvider-morework2
  • circuit-service-details-fix
  • lookup-SPECTRUM-SCHF-ports
  • inventoryProvider-1267-cleanup
  • inventoryProvider-moreWork
  • feature/DBOARD3-958
  • release/0.110
  • fix-uuid-validation-error
  • docker-poc
  • 0.161
  • 0.160
  • 0.159
  • 0.158
  • 0.157
  • 0.156
  • 0.155
  • 0.154
  • 0.153
  • 0.152
  • 0.151
  • 0.150
  • 0.149
  • 0.148
  • 0.147
  • 0.146
  • 0.145
  • 0.144
  • 0.143
  • 0.142
33 results

test_general_data_routes.py

Blame
  • eumetsat.py 3.37 KiB
    import operator
    from brian_dashboard_manager.templating.helpers \
        import get_dashboard_data, letter_generator, create_panel
    
    
    def get_panel_data(all_subscriptions):
        """
        Helper for generating multicast panel data from subscriptions
        which are duplicated across all routers
    
        :param all_subscriptions: list of subscriptions
        :return: dict of dashboard name to list of panels.
        """
    
        result = dict()
    
        def _panel(s):
            return {
                'measurement': 'multicast_rates',
                'title': f'{s["subscription"]} on {s["router"]}',
                'subscription': s['subscription'],
                'hostname': s['router']
            }
    
        for subscription in all_subscriptions:
            dashboard_name = f'{subscription["router"]} subscriptions'
            result.setdefault(dashboard_name, []).append(_panel(subscription))
    
        # make the panels sorted deterministically
        for name in result.keys():
            result[name] = sorted(
                result[name],
                key=operator.itemgetter('subscription'))
    
        return result
    
    
    def get_panel_fields(panel, panel_type, datasource):
        """
        Helper for generating a single multicast panel
    
        :param panel: panel data
        :param panel_type: type of panel (traffic, errors, etc.)
        :param datasource: datasource to use
        :return: panel data
        """
        letters = letter_generator()
    
        def get_target_data(alias, field):
            return {
                # panel includes identifying information
                # such as hostname, subscription, etc.
                **panel,
                'alias': alias,
                'refId': next(letters),
                'select_field': field
                # 'percentile': 'percentile' in alias.lower(),
            }
    
        targets = [("Multicast Traffic", "octets")]
        title = panel.pop("title").format(panel_type)
        return create_panel(
            **panel,
            datasource=datasource,
            linewidth=1,
            title=title,
            panel_targets=[get_target_data(*target) for target in targets],
            y_axis_type="bits",
        )
    
    
    def subscription_panel_generator(gridPos):
        """
        Generates panels used for multicast traffic dashboards
    
        :param gridPos: generator of grid positions
        :return: function that generates panels
        """
        def get_panel_definitions(panels, datasource, errors=False):
            result = []
    
            for panel in panels:
                result.append(get_panel_fields({
                    **panel,
                    **next(gridPos)
                }, 'traffic', datasource))
                if panel.get('has_v6', False):
                    result.append(get_panel_fields({
                        **panel,
                        **next(gridPos)
                    }, 'IPv6', datasource))
                if errors:
                    result.append(get_panel_fields({
                        **panel,
                        **next(gridPos)
                    }, 'errors', datasource))
    
            return result
    
        return get_panel_definitions
    
    
    def generate_eumetsat_multicast(subscriptions, datasource):
        """
        Generates EUMETSAT multicast dashboards
    
        :param subscriptions: list of subscriptions
        :param datasource: datasource to use
        :return: generator of dashboards
        """
    
        panel_data = get_panel_data(subscriptions)
        for dash in get_dashboard_data(
                data=panel_data,
                datasource=datasource,
                tag='EUMET_MULTICAST',
                panel_generator=subscription_panel_generator):
    
            yield dash