def getSubComponentsNoIndexGen(self): """Recursively gets every sub component for this component. We use the slow method of just looking at every object underneath this object and yielding those that are DeviceComponents. NOTE: this does not use a catalog and is used only to index a catalog. It is painfully inefficient @rtype: generator @return: Every subcomponent directly under this component """ subObjects = getAllConfmonObjects(self) for obj in subObjects: if isinstance(obj, DeviceComponent): yield obj
def getSubComponentsNoIndexGen(self): """Recursively gets every sub component for this component. We use the slow method of just looking at every object underneath this object and yielding those that are DeviceComponents. NOTE: this does not use a catalog and is used only to index a catalog. It is painfully inefficient @rtype: generator @return: Every subcomponent directly under this component """ subObjects = getAllConfmonObjects(self) for obj in subObjects: if isinstance(obj, DeviceComponent): yield obj
def rebuild(self): repair = self.options.repair ccount = 0 self.log.info("Checking relations...") for object in getAllConfmonObjects(self.dmd): ccount += 1 self.log.debug("checking relations on object %s" % object.getPrimaryDmdId()) object.checkRelations(repair=repair) ch = object._p_changed if not ch: object._p_deactivate() if ccount >= self.options.savepoint: transaction.savepoint() ccount = 0 if self.options.nocommit: self.log.info("not commiting any changes") else: trans = transaction.get() trans.note('CheckRelations cleaned relations') trans.commit()
def rebuild(self): repair = self.options.repair ccount = 0 self.log.info("Checking relations...") for object in getAllConfmonObjects(self.dmd): ccount += 1 self.log.debug("checking relations on object %s" % object.getPrimaryDmdId()) object.checkRelations(repair=repair) ch = object._p_changed if not ch: object._p_deactivate() if ccount >= self.options.savepoint: transaction.savepoint() ccount = 0 if self.options.nocommit: self.log.info("not commiting any changes") else: trans = transaction.get() trans.note('CheckRelations cleaned relations' ) trans.commit()
def scan_relationships(attempt_fix, max_cycles, use_unlimited_memory, dmd, log, counters): '''Scan through zodb relationships looking for broken references''' # ENTIRETY OF REBUILD CODE FROM ZenUtils/CheckRelations.py (for reference) # def rebuild(self): # repair = self.options.repair # ccount = 0 # for object in getAllConfmonObjects(self.dmd): # ccount += 1 # self.log.debug("checking relations on object %s" # % object.getPrimaryDmdId()) # object.checkRelations(repair=repair) # ch = object._p_changed # if not ch: object._p_deactivate() # if ccount >= self.options.savepoint: # transaction.savepoint() # ccount = 0 # if self.options.nocommit: # self.log.info("not commiting any changes") # else: # trans = transaction.get() # trans.note('CheckRelations cleaned relations' ) # trans.commit() PROGRESS_INTERVAL = 829 # Prime number near 1000 ending in a 9, used for progress bar print("[%s] Examining ZenRelations...\n" % (time.strftime("%Y-%m-%d %H:%M:%S"))) log.info("Examining ZenRelations...") number_of_issues = -1 current_cycle = 0 if not attempt_fix: max_cycles = 1 progress_bar(counters['item_count'].value(), counters['error_count'].value(), counters['repair_count'].value(), attempt_fix) while ((current_cycle < max_cycles) and (number_of_issues != 0)): number_of_issues = 0 current_cycle += 1 if (attempt_fix): log.info("Beginning cycle %d" % (current_cycle)) try: relationships_to_check = getAllConfmonObjects(dmd) except Exception: raise while True: try: object = relationships_to_check.next() counters['item_count'].increment() if (counters['item_count'].value() % PROGRESS_INTERVAL) == 0: if not use_unlimited_memory: transaction.abort() progress_bar(counters['item_count'].value(), counters['error_count'].value(), counters['repair_count'].value(), attempt_fix) log.debug("Processed %d items" % (counters['item_count'].value())) try: object.checkRelations(repair=attempt_fix) changed = object._p_changed if not changed: object._p_deactivate() else: transaction.commit() log.debug("Checked object %s" % (object.getPrimaryDmdId())) except Exception as e: log.exception(e) counters['error_count'].increment() counters['repair_count'].increment() except: try: log.error("Object %s had broken relationship" % (object.getPrimaryDmdId())) except: log.error("Object had issues loading - PKE") counters['error_count'].increment() counters['repair_count'].increment() except StopIteration: break except Exception as e: log.exception(e) if not use_unlimited_memory: transaction.abort() progress_bar(counters['item_count'].value(), counters['error_count'].value(), counters['repair_count'].value(), attempt_fix) print("\n\n#################################################################") print "CRITICAL: Exception encountered - aborting. Please see log file." print("#################################################################") return if not use_unlimited_memory: transaction.abort() progress_bar(counters['item_count'].value(), counters['error_count'].value(), counters['repair_count'].value(), attempt_fix) print
def scan_relationships(attempt_fix, max_cycles, use_unlimited_memory, dmd, log, counters): '''Scan through zodb relationships looking for broken references''' # ENTIRETY OF REBUILD CODE FROM ZenUtils/CheckRelations.py (for reference) # def rebuild(self): # repair = self.options.repair # ccount = 0 # for object in getAllConfmonObjects(self.dmd): # ccount += 1 # self.log.debug("checking relations on object %s" # % object.getPrimaryDmdId()) # object.checkRelations(repair=repair) # ch = object._p_changed # if not ch: object._p_deactivate() # if ccount >= self.options.savepoint: # transaction.savepoint() # ccount = 0 # if self.options.nocommit: # self.log.info("not commiting any changes") # else: # trans = transaction.get() # trans.note('CheckRelations cleaned relations' ) # trans.commit() PROGRESS_INTERVAL = 829 # Prime number near 1000 ending in a 9, used for progress bar print("[%s] Examining ZenRelations...\n" % (time.strftime("%Y-%m-%d %H:%M:%S"))) log.info("Examining ZenRelations...") number_of_issues = -1 current_cycle = 0 if not attempt_fix: max_cycles = 1 progress_bar(counters['item_count'].value(), counters['error_count'].value(), counters['repair_count'].value(), attempt_fix) while ((current_cycle < max_cycles) and (number_of_issues != 0)): number_of_issues = 0 current_cycle += 1 if (attempt_fix): log.info("Beginning cycle %d" % (current_cycle)) try: relationships_to_check = getAllConfmonObjects(dmd) except Exception: raise while True: try: object = relationships_to_check.next() counters['item_count'].increment() if (counters['item_count'].value() % PROGRESS_INTERVAL) == 0: if not use_unlimited_memory: transaction.abort() progress_bar(counters['item_count'].value(), counters['error_count'].value(), counters['repair_count'].value(), attempt_fix) log.debug("Processed %d items" % (counters['item_count'].value())) try: object.checkRelations(repair=attempt_fix) changed = object._p_changed if not changed: object._p_deactivate() else: transaction.commit() log.debug("Checked object %s" % (object.getPrimaryDmdId())) except Exception as e: log.exception(e) counters['error_count'].increment() counters['repair_count'].increment() except: try: log.error("Object %s had broken relationship" % (object.getPrimaryDmdId())) except: log.error("Object had issues loading - PKE") counters['error_count'].increment() counters['repair_count'].increment() except StopIteration: break except Exception as e: log.exception(e) if not use_unlimited_memory: transaction.abort() progress_bar(counters['item_count'].value(), counters['error_count'].value(), counters['repair_count'].value(), attempt_fix) print("\n\n#################################################################") print "CRITICAL: Exception encountered - aborting. Please see log file." print("#################################################################") return if not use_unlimited_memory: transaction.abort() progress_bar(counters['item_count'].value(), counters['error_count'].value(), counters['repair_count'].value(), attempt_fix) print