Skip to content
Snippets Groups Projects
Select Git revision
  • 4ecd816e70deaf3ed8e6595ddfb03d6cf8d970c6
  • develop default
  • master protected
  • async-provision
  • DBOARD3-1252/inventory-api
  • 0.90
  • 0.89
  • 0.88
  • 0.87
  • 0.86
  • 0.85
  • 0.84
  • 0.83
  • 0.82
  • 0.81
  • 0.80
  • 0.79
  • 0.78
  • 0.77
  • 0.76
  • 0.75
  • 0.74
  • 0.73
  • 0.72
  • 0.71
25 results

eumetsat.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