def get_object_profile_metrics(cls, p_id: int) -> Dict[str, MetricConfig]: r = {} opr = ManagedObjectProfile.get_by_id(id=p_id) if not opr: return r for m in opr.metrics: mt_id = m.get("metric_type") if not mt_id: continue mt = MetricType.get_by_id(mt_id) if not mt: continue if m.get("threshold_profile"): threshold_profile = ThresholdProfile.get_by_id( m.get("threshold_profile")) else: threshold_profile = None r[mt.name] = MetricConfig( mt, m.get("enable_box", True), m.get("enable_periodic", True), m.get("is_stored", True), threshold_profile, ) return r
def get_object_profile_metrics(cls, p_id): r = {} opr = ManagedObjectProfile.get_by_id(id=p_id) if not opr: return r for m in opr.metrics: mt_id = m.get("metric_type") if not mt_id: continue mt = MetricType.get_by_id(mt_id) if not mt: continue le = m.get("low_error") lw = m.get("low_warn") he = m.get("high_error") hw = m.get("high_warn") lew = AlarmSeverity.severity_for_weight(int(m.get("low_error_weight", 10))) lww = AlarmSeverity.severity_for_weight(int(m.get("low_warn_weight", 1))) hew = AlarmSeverity.severity_for_weight(int(m.get("high_error_weight", 1))) hww = AlarmSeverity.severity_for_weight(int(m.get("high_warn_weight", 10))) threshold_profile = None if m.get("threshold_profile"): threshold_profile = ThresholdProfile.get_by_id(m.get("threshold_profile")) r[mt.name] = MetricConfig( mt, m.get("enable_box", True), m.get("enable_periodic", True), m.get("is_stored", True), m.get("window_type", "m"), int(m.get("window", 1)), m.get("window_function", "last"), m.get("window_config"), m.get("window_related", False), int(le) if le is not None else None, int(lw) if lw is not None else None, int(hw) if hw is not None else None, int(he) if he is not None else None, lew, lww, hww, hew, threshold_profile, le is not None or lw is not None or he is not None or hw is not None ) return r
def get_weight(cls, summary): """ Convert result of *get_object_summary* to alarm weight """ w = 0 subscribers = summary.get("subscriber", {}) for s in subscribers: sp = SubscriberProfile.get_by_id(s) if sp and sp.weight: w += sp.weight * subscribers[s] services = summary.get("service", {}) for s in services: sp = ServiceProfile.get_by_id(s) if sp and sp.weight: w += sp.weight * services[s] objects = summary.get("object", {}) for s in objects: sp = ManagedObjectProfile.get_by_id(s) if sp and sp.weight: w += sp.weight * objects[s] return w