def __init__(self, skip_rabbit): self.faucet_event = [] self.m_queue = queue.Queue() self.skip_rabbit = skip_rabbit self.logger = logger # get config options self.controller = Config().get_config() # timer class to call things periodically in own thread self.schedule = schedule # setup prometheus self.prom = Prometheus() try: self.prom.initialize_metrics() except Exception as e: # pragma: no cover self.logger.debug( 'Prometheus metrics are already initialized: {0}'.format( str(e))) Prometheus.start() # initialize sdnconnect self.s = SDNConnect() # retrieve endpoints from redis self.s.get_stored_endpoints() # set all retrieved endpoints to inactive at the start for endpoint in self.s.endpoints: if not endpoint.ignore: if endpoint.state != 'inactive': if endpoint.state == 'mirroring': endpoint.p_next_state = 'mirror' elif endpoint.state == 'reinvestigating': endpoint.p_next_state = 'reinvestigate' elif endpoint.state == 'queued': endpoint.p_next_state = 'queue' elif endpoint.state in ['known', 'abnormal']: endpoint.p_next_state = endpoint.state endpoint.endpoint_data['active'] = 0 endpoint.inactive() endpoint.p_prev_states.append( (endpoint.state, int(time.time()))) # store changes to state self.s.store_endpoints() # schedule periodic scan of endpoints thread self.schedule.every(self.controller['scan_frequency']).seconds.do( partial(schedule_job_kickurl, func=self)) # schedule periodic reinvestigations thread self.schedule.every( self.controller['reinvestigation_frequency']).seconds.do( partial(schedule_job_reinvestigation, func=self)) # schedule all threads self.schedule_thread = threading.Thread(target=partial( schedule_thread_worker, schedule=self.schedule), name='st_worker')
def __init__(self, skip_rabbit, controller=None): self.faucet_event = [] self.m_queue = queue.Queue() self.job_queue = queue.Queue() self.skip_rabbit = skip_rabbit self.logger = logger self.rabbit_channel_connection_local = None self.rabbit_channel_connection_local_fa = None # get config options if controller is None: self.controller = Config().get_config() else: self.controller = controller # timer class to call things periodically in own thread self.schedule = schedule # setup prometheus self.prom = Prometheus() try: self.prom.initialize_metrics() except Exception as e: # pragma: no cover self.logger.debug( 'Prometheus metrics are already initialized: {0}'.format( str(e))) Prometheus.start() # initialize sdnconnect self.s = SDNConnect(self.controller) # schedule periodic scan of endpoints thread self.schedule.every(self.controller['scan_frequency']).seconds.do( self.schedule_job_kickurl) # schedule periodic reinvestigations thread self.schedule.every( self.controller['reinvestigation_frequency']).seconds.do( self.schedule_job_reinvestigation) # schedule all threads self.schedule_thread = threading.Thread(target=partial( schedule_thread_worker, schedule=self.schedule), name='st_worker')