def test_01_InitPutGet(self): global selector selector = Selector( name="myselector", namespace='unittest', storage=storage) selector.nocache = True _id = selector._id print("Selector Id: %s" % _id) dump = selector.dump() ## Put in db storage.put(selector) ## Load selector = Selector(name="myselector", storage=storage) ndump = selector.dump() if dump['_id'] != ndump['_id'] or dump['namespace'] != ndump['namespace'] or dump['mfilter'] != ndump['mfilter'] or dump['aaa_owner'] != ndump['aaa_owner']: print(dump) print(ndump) raise Exception('Invalid dump ...')
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