示例#1
0
    def set_panel(self, panel_sequence, panel_class, **panel_definition):
        '''
        Updates an existing dashboard panel at a given index
        '''

        # get the container and panel info
        i,j = self._obj.getPanelPositionBySequence(panel_sequence)
        
        if panel_class == None:
            raise ValueError, 'Cannot set panel with unknown class; panel_definition=%s' % panel_definition

        panel_object = self._obj.rows[i][j]
        
        # for now, remove any time terms from saved search mode
        # TODO: revisit when we verify support for this
        if panel_definition.get('searchMode') == 'saved':
            panel_definition['searchEarliestTime'] = None
            panel_definition['searchLatestTime'] = None
        
        # if the class changes, make a new object
        if panel_class != panel_object.matchTagName:
            newPanel = panel.createPanel(panel_class)
            newPanel.fromJsonable(panel_definition)
            self._obj.rows[i][j] = newPanel
        else:
            panel_object.fromJsonable(panel_definition)
示例#2
0
    def set_panel(self, panel_sequence, panel_class, **panel_definition):
        '''
        Updates an existing dashboard panel at a given index
        '''

        # get the container and panel info
        i, j = self._obj.getPanelPositionBySequence(panel_sequence)

        if panel_class == None:
            raise ValueError, 'Cannot set panel with unknown class; panel_definition=%s' % panel_definition

        panel_object = self._obj.rows[i][j]

        # for now, remove any time terms from saved search mode
        # TODO: revisit when we verify support for this
        if panel_definition.get('searchMode') == 'saved':
            panel_definition['searchEarliestTime'] = None
            panel_definition['searchLatestTime'] = None

        # if the class changes, make a new object
        if panel_class != panel_object.matchTagName:
            newPanel = panel.createPanel(panel_class)
            newPanel.fromJsonable(panel_definition)
            self._obj.rows[i][j] = newPanel
        else:
            panel_object.fromJsonable(panel_definition)
示例#3
0
    def create_panel(self, type, saved_search=None, **panel_definition):
        '''
        type: table, chart, html, event or list
        '''
        chart_type = None
        chart_types = [
            'bar',
            'area',
            'column',
            'bubble',
            'pie',
            'scatter',
            'line',
            'radialGauge',
            'fillerGauge',
            'markerGauge',
        ]

        # if the type matches an enriched chart, remap
        if chart_types.count(type) > 0:
            chart_type = type
            type = 'chart'

        # calculate desired number of panels that constitute a complete row
        row_count = len(self._obj.rows)
        if row_count == 0:
            expected_row_size = DEFAULT_DASHBOARD_ROW_SIZE
        else:
            expected_row_size = min(
                MAX_DASHBOARD_ROW_SIZE,
                int(math.floor(sum(map(len, self._obj.rows)) / row_count)))

        # if last row still has room, don't add row; otherwise create new row
        if row_count > 0 and len(self._obj.rows[-1]) < expected_row_size:
            pass
        else:
            self._obj.rows.append([])
            self._obj.rowGrouping.append(None)

        if saved_search is not None:
            panel_definition['searchCommand'] = saved_search
            panel_definition['searchMode'] = 'saved'

        if chart_type:
            panel_definition.setdefault('options', {})
            panel_definition['options']['charting.chart'] = chart_type

        # generate new panel object
        panel_object = panel.createPanel(type)
        panel_object.fromJsonable(panel_definition)

        # insert into view object into last row
        self._obj.rows[-1].append(panel_object)

        # update the internal member
        self.data = et.tostring(self._obj.toXml(),
                                xml_declaration=True,
                                encoding='utf-8',
                                pretty_print=True)
示例#4
0
    def create_panel(self, type, saved_search=None, **panel_definition):
        '''
        type: table, chart, html, event or list
        '''
        chart_type = None
        chart_types = [
            'bar',
            'area',
            'column',
            'bubble',
            'pie',
            'scatter',
            'line',
            'radialGauge',
            'fillerGauge',
            'markerGauge',
        ]

        # if the type matches an enriched chart, remap
        if chart_types.count(type) > 0:
            chart_type = type
            type = 'chart'
       
        # calculate desired number of panels that constitute a complete row
        row_count = len(self._obj.rows)
        if row_count == 0:
            expected_row_size = DEFAULT_DASHBOARD_ROW_SIZE
        else:
            expected_row_size = min(MAX_DASHBOARD_ROW_SIZE, int(math.floor(sum(map(len, self._obj.rows)) / row_count)))

        # if last row still has room, don't add row; otherwise create new row
        if row_count > 0 and len(self._obj.rows[-1]) < expected_row_size:
            pass
        else:
            self._obj.rows.append([])
            self._obj.rowGrouping.append(None)

        if saved_search is not None:
            panel_definition['searchCommand'] = saved_search
            panel_definition['searchMode'] = 'saved'
        
        if chart_type:
            panel_definition.setdefault('options', {})
            panel_definition['options']['charting.chart'] = chart_type

        # generate new panel object
        panel_object = panel.createPanel(type)
        panel_object.fromJsonable(panel_definition)

        # insert into view object into last row
        self._obj.rows[-1].append(panel_object)
        
        # update the internal member
        self.data = et.tostring(self._obj.toXml(), xml_declaration=True, encoding='utf-8', pretty_print=True)