Exemplo n.º 1
0
    def consume_dispatcher(self, event, *args, **kargs):

        selector = self.get_ready_record(event)

        if selector:

            event_id = event['_id']

            # Loads associated class
            selector = Selector(
                storage=self.storage, record=selector,
                logging_level=self.logging_level)

            name = selector.display_name

            self.logger.debug('----------SELECTOR----------\n')

            self.logger.debug(u'Selector {} found, start processing..'.format(
                name
            ))

            update_extra_fields = {}
            # Selector event have to be published when do state is true.
            if selector.dostate:
                rk, selector_event, publish_ack = selector.event()

                # Compute previous event to know if any difference next turn
                previous_metrics = {}
                for metric in selector_event['perf_data_array']:
                    previous_metrics[metric['metric']] = metric['value']
                update_extra_fields['previous_metrics'] = previous_metrics

                do_publish_event = selector.have_to_publish(selector_event)

                if do_publish_event:
                    update_extra_fields['last_publication_date'] = \
                        selector.last_publication_date

                    self.publish_event(
                        selector,
                        rk,
                        selector_event,
                        publish_ack
                    )

                # When selector computed, sla may be asked to be computed.
                if selector.dosla:

                    self.logger.debug('----------SLA----------\n')

                    # Retrieve user ui settings
                    # This template should be always set
                    template = selector.get_sla_output_tpl()
                    # Timewindow computation duration
                    timewindow = selector.get_sla_timewindow()
                    sla_warning = selector.get_sla_warning()
                    sla_critical = selector.get_sla_critical()
                    alert_level = selector.get_alert_level()
                    display_name = selector.display_name

                    rk = get_routingkey(selector_event)

                    sla = Sla(
                        self.storage,
                        rk,
                        template,
                        timewindow,
                        sla_warning,
                        sla_critical,
                        alert_level,
                        display_name,
                        logger=self.logger
                    )
                    self.publish_sla_event(
                        sla.get_event(),
                        display_name
                    )

            else:
                self.logger.debug(u'Nothing to do with selector {}'.format(
                    name
                ))

            # Update crecords informations
            self.crecord_task_complete(event_id, update_extra_fields)

        self.nb_beat += 1
Exemplo n.º 2
0
    def work(self, event, *args, **kwargs):
        # Loads associated class
        selector = Selector(
            storage=self.storage,
            record=Record(event),
            logging_level=self.logging_level
        )

        name = selector.display_name

        self.logger.debug(u'Start processing selector: {0}'.format(name))

        # Selector event have to be published when do state is true.
        if selector.dostate:
            rk, event, publish_ack = selector.event()

            # Compute previous event to know if any difference next turn
            selector.data['previous_metrics'] = {
                metric['metric']: metric['value']
                for metric in event['perf_data_array']
            }

            do_publish_event = selector.have_to_publish(event)

            if do_publish_event:
                self.publish_event(selector, rk, event, publish_ack)

            # When selector computed, sla may be asked to be computed.
            if selector.dosla:
                self.logger.debug(u'Start processing SLA')

                # Retrieve user ui settings
                # This template should be always set
                template = selector.get_sla_output_tpl()
                # Timewindow computation duration
                timewindow = selector.get_sla_timewindow()
                sla_warning = selector.get_sla_warning()
                sla_critical = selector.get_sla_critical()
                alert_level = selector.get_alert_level()
                display_name = selector.display_name

                rk = get_routingkey(event)

                sla = Sla(
                    self.storage,
                    rk,
                    template,
                    timewindow,
                    sla_warning,
                    sla_critical,
                    alert_level,
                    display_name,
                    logger=self.logger
                )
                self.publish_sla_event(
                    sla.get_event(),
                    display_name
                )

        else:
            self.logger.debug(u'Nothing to do')

        selector.save()