def main_loop(self): """ Main loop for configuration transfers """ self.logger.debug('Configuration backup started, TID:%s', gettid()) self.logger.debug('Starting transfer for %d host(s).', len(self.hosts)) for hid, host in self.hosts.items(): try: backup_method = self.backup_methods[host.method_id] except KeyError: self.logger.error( 'H:%d - Error finding method %s for host %s.', hid, host.method_name, host.display_name) continue if backup_method is None: self.logger.debug( 'H:%d - Config transfer disabled for %s, skipping', hid, host.display_name) continue self.logger.debug( 'H:%d - Starting config transfer for %s using %s', hid, host.display_name, host.method_name) self.current_host = host host.backup_method = backup_method backup_method.start(self, host) while True: if not self._poll(host): break
def consolidate(self): self.logger.info('Consolidator started TID:%d', gettid()) if not self.do_once: check_all_attributes_state(self.logger) while True: next_cons_time = datetime.datetime.now() +\ datetime.timedelta(seconds=self.consolidate_interval) self.logfile_consolidator.consolidate() if not self._poll(): return self.trap_consolidator.consolidate() if not self._poll(): return changed_attributes = process_events(self.logger) if not self._poll(): return changed_attributes.union(check_event_stop_time(self.logger)) if not self._poll(): return check_attribute_state(changed_attributes, self.logger) if not self._poll(): return sleep_time = int((next_cons_time - datetime.datetime.now()).total_seconds()) self.logger.debug("Next consolidation in %d secs", sleep_time) if self.do_once: return if not self.sleep(next_cons_time): return
def run(self): self.logger.info('SNMP trap daemon started TID:%s', gettid()) cache_clean_time = time.time() + CACHE_SECONDS while True: now = time.time() if now > cache_clean_time: self.clean_host_cache() cache_clean_time = now + CACHE_SECONDS sleep_time = max(cache_clean_time - now, 0) if not self.zmq_core.poll(sleep_time): return if self.end_thread: return
def main_loop(self): """ The main loop for the poller to do everything it needs to do. This will only exit if we have forced attributes and they are all polled. """ self.logger.debug('Poller started, TID:%d', gettid()) while True: now = datetime.datetime.now() polls_running = False if not self.forced_attributes and self.next_find_attribute < now: self.find_new_attributes() self.next_find_attribute = now +\ datetime.timedelta(seconds=self.find_attribute_interval) att_count = len(self.polling_attributes) if self.polling_attributes: self.check_polling_attributes() polls_running = True snmp_jobs = self.snmp_engine.poll() if snmp_jobs > 0: att_count -= snmp_jobs ntp_jobs = self.ntp_client.poll() att_count -= ntp_jobs tcp_jobs = self.tcp_client.poll() att_count -= tcp_jobs # Ping jobs is the only one that doesn't use zmqcore, bah (yet) ping_jobs = self.ping_client.poll() timeout = 1.0 if ping_jobs > 0: att_count -= ping_jobs timeout = 1.0 if not self.zmq_core.poll(timeout): transaction.commit() return if self.end_thread: break if not polls_running and (self.polling_attributes == {}): # If there are no pollers, we can sleep until we need to # look for more attributes to poll if self.do_once or self.end_thread: break transaction.commit() if self._sleep_until_next() is False: return self.wait_for_workers() transaction.commit()
def test_gettid(self): """ gettid() returns an integer > 1 """ tid = gettid() assert_is_instance(tid, int) assert_greater(tid, 1)