def correlate_merge_downlinks(ca: ActiveAlarm) -> bool: """ Donwlink merge correlation :param ca: :return: """ if not ca.uplinks or not ca.rca_neighbors: return False dlm_neighbors = { mo: w for mo, w in zip(ca.rca_neighbors, ca.dlm_windows) if w > 0 } dlm_candidates = set(neighbor_alarms) & set(dlm_neighbors) if not dlm_candidates: return False # Get possible candidates t0 = ca.timestamp candidates = list( sorted( (neighbor_alarms[mo] for mo in dlm_candidates if (t0 - neighbor_alarms[mo].timestamp ).total_seconds() <= dlm_neighbors[mo]), key=operator.attrgetter("timestamp"), )) if not candidates: return False ra = candidates[0] self.logger.info("[%s] Set root to %s (downlink merge)", ca.id, ra.id) ca.set_root(ra, rca_type=RCA_DOWNLINK_MERGE) metrics["alarm_correlated_topology"] += 1 return True
def correlate_uplinks(ca: ActiveAlarm) -> bool: """ Correlate with uplink alarms if all uplinks are faulty. :param a1: :return: """ if not all_uplinks_failed(ca): return False self.logger.info("[%s] All uplinks are faulty. Correlating", ca.id) ra = get_root(ca) if not ra: return False self.logger.info("[%s] Set root to %s", ca.id, ra.id) ca.set_root(ra, rca_type=RCA_TOPOLOGY) metrics["alarm_correlated_topology"] += 1 return True