Exemplo n.º 1
0
Arquivo: graph.py Projeto: csmall/rnms
    def _default(self, a):
        if tmpl_context.form_errors:
            self.process_form_errors()
            return {}
        my_attribute = Attribute.by_id(a)
        if my_attribute is None:
            flash('Attribute ID#{} not found'.format(a), 'error')
            return {}

        class SelectPanel(PanelTile):
            title = 'Select Graph'

            class MyGraphSelector(GraphSelector):
                attribute_type_id = my_attribute.attribute_type_id

        class GraphPanel(PanelTile):
            title = 'Attribute Graphs'
            fullwidth = True
            fullheight = True

            class GraphList(twc.Widget):
                template = 'rnms.templates.widgets.graphs'
                resources = [c3_min_js, d3_min_js, c3_min_css]

        return dict(attribute=my_attribute,
                    select_panel=SelectPanel,
                    graph_panel=GraphPanel)
Exemplo n.º 2
0
    def _default(self, a):
        if tmpl_context.form_errors:
            self.process_form_errors()
            return {}
        my_attribute = Attribute.by_id(a)
        if my_attribute is None:
            flash('Attribute ID#{} not found'.format(a), 'error')
            return {}

        class SelectPanel(PanelTile):
            title = 'Select Graph'

            class MyGraphSelector(GraphSelector):
                attribute_type_id = my_attribute.attribute_type_id

        class GraphPanel(PanelTile):
            title = 'Attribute Graphs'
            fullwidth = True
            fullheight = True

            class GraphList(twc.Widget):
                template = 'rnms.templates.widgets.graphs'
                resources = [c3_min_js, d3_min_js, c3_min_css]

        return dict(attribute=my_attribute,
                    select_panel=SelectPanel,
                    graph_panel=GraphPanel)
Exemplo n.º 3
0
    def bulk_add(self, h, attribs):
        """ From a discovery phase, add the following attributes """
        if tmpl_context.form_errors:
            self.process_form_errors()
            return {}

        host = Host.by_id(h)
        if host is None:
            return dict(errors='Unknown Host ID {}'.format(h))

        old_att_id = None
        new_count = 0

        decoded_attribs = json.loads(attribs)
        for vals in decoded_attribs:
            if old_att_id != vals['atype_id']:
                attribute_type = AttributeType.by_id(vals['atype_id'])
                if attribute_type is None:
                    return dict(errors='Unknown Attribute Type ID {}'.format(
                        vals['atype_id']))

            if Attribute.discovered_exists(host.id, attribute_type.id,
                                           vals['id']):
                continue
            new_attribute = Attribute(host=host,
                                      attribute_type=attribute_type,
                                      display_name=vals['display_name'],
                                      index=vals['id'])
            try:
                admin_state = State(name=vals['admin_state'])
            except ValueError:
                new_attribute.admin_state = State.UNKNOWN
            else:
                new_attribute.admin_state = int(admin_state)
            new_attribute.state = EventState.by_name(vals['oper_state'])
            if new_attribute.state is None:
                new_attribute.state = EventState.get_up()

            for tag, value in vals['fields'].items():
                new_attribute.set_field(tag, value)
            DBSession.add(new_attribute)
            new_count += 1

        return dict(status='{} Attributes added'.format(new_count))
Exemplo n.º 4
0
    def _default(self, a):
        if tmpl_context.form_errors:
            self.process_form_errors()
            return dict(page='attribute')
        attribute = Attribute.by_id(a)
        if attribute is None:
            flash('Attribute ID#{} not found'.format(a), 'error')
            return dict(page='attribute')
        this_attribute = attribute
        this_graph_type = attribute.attribute_type.get_graph_type()

        class DetailsPanel(PanelTile):
            title = 'Attribute Details'

            class MyAttributeDetails(AttributeDetails):
                attribute = this_attribute

        if this_graph_type:

            class GraphPanel(PanelTile):
                title = this_graph_type.formatted_title(this_attribute)
                fullheight = True
                fillrow = True

                class AttributeChart(C3Chart):
                    attribute = this_attribute
                    show_legend = True
                    graph_type = this_graph_type
                    attribute_id = a
                    chart_height = 200

            graph_panel = GraphPanel()
        else:
            graph_panel = None

        class EventsPanel(PanelTile):
            title = 'Events for {} - {}'.format(attribute.host.display_name,
                                                attribute.display_name)
            fullwidth = True

            class AttributeEvents(EventTable):
                filter_params = {'a': a}

        return dict(
            page='attribute',
            attribute=attribute,
            attribute_id=a,
            details_panel=DetailsPanel(),
            graph_panel=graph_panel,
            eventsgrid=EventsPanel(),
        )
Exemplo n.º 5
0
 def _sleep_until_next(self):
     """
     Stay in this loop until we need to go into the main loop again.
     Returns False if we have broken out of the poll
     """
     next_attribute = Attribute.next_sla_analysis()
     if next_attribute is None:
         return self.sleep(self.next_find_attribute)
     else:
         self.logger.info("Next SLA Analysis #%d at %s", next_attribute.id,
                          next_attribute.next_sla.ctime())
         if self.next_find_attribute > next_attribute.next_sla:
             self.next_find_attribute = next_attribute.next_sla
         return self.sleep(self.next_find_attribute)
Exemplo n.º 6
0
 def matched_attribute(self, match, host):
     """
     Return the matched attribute
     """
     if self.attribute_match is None:
         return None
     try:
         groupid = int(self.attribute_match)
     except ValueError:
         return None
     try:
         display_name = match.group(groupid)
     except IndexError:
         return None
     return Attribute.by_display_name(host, unicode(display_name))
Exemplo n.º 7
0
 def _sleep_until_next(self):
     """
     Stay in this loop until we need to go into the main loop again.
     Returns False if we have broken out of the poll
     """
     next_attribute = Attribute.next_sla_analysis()
     if next_attribute is None:
         return self.sleep(self.next_find_attribute)
     else:
         self.logger.info(
             "Next SLA Analysis #%d at %s",
             next_attribute.id, next_attribute.next_sla.ctime())
         if self.next_find_attribute > next_attribute.next_sla:
             self.next_find_attribute = next_attribute.next_sla
         return self.sleep(self.next_find_attribute)
Exemplo n.º 8
0
 def matched_attribute(self, match, host):
     """
     Return the matched attribute
     """
     if self.attribute_match is None:
         return None
     try:
         groupid = int(self.attribute_match)
     except ValueError:
         return None
     try:
         display_name = match.group(groupid)
     except IndexError:
         return None
     return Attribute.by_display_name(host, unicode(display_name))
Exemplo n.º 9
0
    def _default(self, a):
        if tmpl_context.form_errors:
            self.process_form_errors()
            return dict(page='attribute')
        attribute = Attribute.by_id(a)
        if attribute is None:
            flash('Attribute ID#{} not found'.format(a), 'error')
            return dict(page='attribute')
        this_attribute = attribute
        this_graph_type = attribute.attribute_type.get_graph_type()

        class DetailsPanel(PanelTile):
            title = 'Attribute Details'

            class MyAttributeDetails(AttributeDetails):
                attribute = this_attribute

        if this_graph_type:
            class GraphPanel(PanelTile):
                title = this_graph_type.formatted_title(this_attribute)
                fullheight = True
                fillrow = True

                class AttributeChart(C3Chart):
                    attribute = this_attribute
                    show_legend = True
                    graph_type = this_graph_type
                    attribute_id = a
                    chart_height = 200
            graph_panel = GraphPanel()
        else:
            graph_panel = None

        class EventsPanel(PanelTile):
            title = 'Events for {} - {}'.format(
                attribute.host.display_name, attribute.display_name)
            fullwidth = True

            class AttributeEvents(EventTable):
                filter_params = {'a': a}

        return dict(page='attribute',
                    attribute=attribute,
                    attribute_id=a,
                    details_panel=DetailsPanel(),
                    graph_panel=graph_panel,
                    eventsgrid=EventsPanel(),
                    )
Exemplo n.º 10
0
    def bulk_add(self, h, attribs):
        """ From a discovery phase, add the following attributes """
        if tmpl_context.form_errors:
            self.process_form_errors()
            return {}

        host = Host.by_id(h)
        if host is None:
            return dict(errors='Unknown Host ID {}'.format(h))

        old_att_id = None
        new_count = 0

        decoded_attribs = json.loads(attribs)
        for vals in decoded_attribs:
            if old_att_id != vals['atype_id']:
                attribute_type = AttributeType.by_id(vals['atype_id'])
                if attribute_type is None:
                    return dict(errors='Unknown Attribute Type ID {}'.
                                format(vals['atype_id']))

            if Attribute.discovered_exists(host.id, attribute_type.id,
                                           vals['id']):
                continue
            new_attribute = Attribute(
                host=host, attribute_type=attribute_type,
                display_name=vals['display_name'], index=vals['id'])
            try:
                admin_state = State(name=vals['admin_state'])
            except ValueError:
                new_attribute.admin_state = State.UNKNOWN
            else:
                new_attribute.admin_state = int(admin_state)
            new_attribute.state = EventState.by_name(vals['oper_state'])
            if new_attribute.state is None:
                new_attribute.state = EventState.get_up()

            for tag, value in vals['fields'].items():
                new_attribute.set_field(tag, value)
            DBSession.add(new_attribute)
            new_count += 1

        return dict(status='{} Attributes added'.format(new_count))
Exemplo n.º 11
0
 def _discovery_found(self, host, atype_id, attribute):
     """
     Autodiscovery has found a new attribute that is not stored in
     the database.
     """
     if host.autodiscovery_policy.can_add(attribute):
         self.logger.debug('H:%d AT:%d New Interface Found: %s', host.id,
                           atype_id, attribute.index)
     if host.autodiscovery_policy.permit_add:
         if self.print_only:
             self.logger.debug('H:%d AT:%d Added %s', host.id, atype_id,
                               attribute.index)
         else:
             real_att = Attribute.from_discovered(host, attribute)
             DBSession.add(real_att)
             DBSession.flush()
             self.logger.debug('H:%d AT:%d Added %s = %d', host.id,
                               atype_id, attribute.index, real_att.id)
Exemplo n.º 12
0
    def plot(self, a, gt, pt=None):
        """ Return the actual HTML for a graph """
        my_attribute = Attribute.by_id(a)
        my_graph_type = GraphType.by_id(gt)

        class MyPanel(PanelTile):
            title = '{} - {}'.format(my_attribute.host.display_name,
                                     my_attribute.display_name)
            subtitle = my_graph_type.formatted_title(my_attribute)
            fullwidth = True

            class MyChart(C3Chart):
                id = 'graph_{}_{}'.format(a, gt)
                attribute = my_attribute
                graph_type = my_graph_type
                chart_height = 200
                preset_time = pt

        return MyPanel().display()
Exemplo n.º 13
0
Arquivo: graph.py Projeto: csmall/rnms
    def plot(self, a, gt, pt=None):
        """ Return the actual HTML for a graph """
        my_attribute = Attribute.by_id(a)
        my_graph_type = GraphType.by_id(gt)

        class MyPanel(PanelTile):
            title = '{} - {}'.format(
                my_attribute.host.display_name,
                my_attribute.display_name)
            subtitle = my_graph_type.formatted_title(my_attribute)
            fullwidth = True

            class MyChart(C3Chart):
                id = 'graph_{}_{}'.format(a, gt)
                attribute = my_attribute
                graph_type = my_graph_type
                chart_height = 200
                preset_time = pt

        return MyPanel().display()
Exemplo n.º 14
0
 def _discovery_found(self, host, atype_id, attribute):
     """
     Autodiscovery has found a new attribute that is not stored in
     the database.
     """
     if host.autodiscovery_policy.can_add(attribute):
         self.logger.debug('H:%d AT:%d New Interface Found: %s',
                           host.id, atype_id, attribute.index)
     if host.autodiscovery_policy.permit_add:
         if self.print_only:
             self.logger.debug(
                 'H:%d AT:%d Added %s',
                 host.id, atype_id, attribute.index)
         else:
             real_att = Attribute.from_discovered(host, attribute)
             DBSession.add(real_att)
             DBSession.flush()
             self.logger.debug('H:%d AT:%d Added %s = %d',
                               host.id, atype_id, attribute.index,
                               real_att.id)
Exemplo n.º 15
0
 def find_new_attributes(self, next_sla_time):
     """ Add new attributes that need to have their SLA analyzed """
     return Attribute.have_sla(next_sla_time, self.attribute_ids,
                               self.host_ids)
Exemplo n.º 16
0
 def update_poll_time(self):
     attribute = Attribute.by_id(self.id)
     if attribute is not None:
         attribute.update_poll_time()
Exemplo n.º 17
0
 def find_new_attributes(self, next_sla_time):
     """ Add new attributes that need to have their SLA analyzed """
     return Attribute.have_sla(
         next_sla_time, self.attribute_ids, self.host_ids)
Exemplo n.º 18
0
 def update_poll_time(self):
     attribute = Attribute.by_id(self.id)
     if attribute is not None:
         attribute.update_poll_time()