def get_nested_alarms(self, alarm): """ Return nested alarms as a part of NodeInterface :param alarm: :return: """ children = [] for ac in (ActiveAlarm, ArchivedAlarm): for a in ac.objects.filter(root=alarm.id): s = AlarmSeverity.get_severity(a.severity) c = { "id": str(a.id), "subject": a.subject, "alarm_class": str(a.alarm_class.id), "alarm_class__label": a.alarm_class.name, "managed_object": a.managed_object.id, "managed_object__label": a.managed_object.name, "timestamp": self.to_json(a.timestamp), "iconCls": "icon_error", "row_class": s.style.css_class_name } nc = self.get_nested_alarms(a) if nc: c["children"] = nc c["expanded"] = True else: c["leaf"] = True children += [c] return children
def instance_to_dict(self, o, fields=None): row_class = None if o.status in ("A", "S"): subject = o.subject repeats = o.repeats duration = o.duration n_alarms = len(o.alarms) if n_alarms: row_class = AlarmSeverity.get_severity_css_class_name(get_severity(o.alarms)) else: subject = None repeats = None duration = None n_alarms = None d = { "id": str(o.id), "status": o.status, "managed_object": o.managed_object.id, "managed_object__label": o.managed_object.name, "administrative_domain": o.managed_object.administrative_domain_id, "administrative_domain__label": o.managed_object.administrative_domain.name, "event_class": str(o.event_class.id) if o.status in ("A", "S") else None, "event_class__label": o.event_class.name if o.status in ("A", "S") else None, "timestamp": self.to_json(o.timestamp), "subject": subject, "repeats": repeats, "duration": duration, "alarms": n_alarms, "row_class": row_class, } if fields: d = dict((k, d[k]) for k in fields) return d
def api_notification(self, request): delta = request.GET.get("delta") n = 0 sound = None volume = 0 if delta: dt = datetime.timedelta(seconds=int(delta)) t0 = datetime.datetime.now() - dt r = list(ActiveAlarm._get_collection().aggregate([{ "$match": { "timestamp": { "$gt": t0 } } }, { "$group": { "_id": "$item", "severity": { "$max": "$severity" } } }])) if r: s = AlarmSeverity.get_severity(r[0]["severity"]) if s and s.sound and s.volume: sound = "/ui/pkg/nocsound/%s.mp3" % s.sound volume = float(s.volume) / 100.0 return {"new_alarms": n, "sound": sound, "volume": volume}
def get_severity(cls, summary): """ Convert result of *get_object_summary* to alarm severity """ from noc.fm.models.alarmseverity import AlarmSeverity return AlarmSeverity.severity_for_weight(cls.get_weight(summary))
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 config_from_settings(m): """ Returns MetricConfig from .metrics field :param m: :return: """ return MetricConfig( m.metric_type, m.enable_box, m.enable_periodic, m.is_stored, m.window_type, m.window, m.window_function, m.window_config, m.window_related, m.low_error, m.low_warn, m.high_warn, m.high_error, AlarmSeverity.severity_for_weight(m.low_error_weight), AlarmSeverity.severity_for_weight(m.low_warn_weight), AlarmSeverity.severity_for_weight(m.high_warn_weight), AlarmSeverity.severity_for_weight(m.high_error_weight), m.threshold_profile, m.low_error is not None or m.low_warn is not None or m.high_warn is not None or m.high_error is not None )
def update_alarms(self): from noc.fm.models.alarmseverity import AlarmSeverity from noc.fm.models.alarmclass import AlarmClass prev_status = self.context.get("umbrella_settings", False) current_status = self.can_update_alarms() self.context["umbrella_settings"] = current_status if not prev_status and not current_status: return self.logger.info("Updating alarm statuses") umbrella_cls = AlarmClass.get_by_name(self.umbrella_cls) if not umbrella_cls: self.logger.info( "No umbrella alarm class. Alarm statuses not updated") return details = [] if current_status: fatal_weight = self.get_fatal_alarm_weight() weight = self.get_alarm_weight() for p in self.problems: if not p["alarm_class"]: continue ac = AlarmClass.get_by_name(p["alarm_class"]) if not ac: self.logger.info("Unknown alarm class %s. Skipping", p["alarm_class"]) continue details += [{ "alarm_class": ac, "path": p["path"], "severity": AlarmSeverity.severity_for_weight( fatal_weight if p["fatal"] else weight), "vars": { "path": p["path"], "message": p["message"] } }] else: # Clean up all open alarms as they has been disabled details = [] self.update_umbrella(umbrella_cls, details)
def instance_to_dict(self, o, fields=None): s = AlarmSeverity.get_severity(o.severity) n_events = (ActiveEvent.objects.filter(alarms=o.id).count() + ArchivedEvent.objects.filter(alarms=o.id).count()) d = { "id": str(o.id), "status": o.status, "managed_object": o.managed_object.id, "managed_object__label": o.managed_object.name, "administrative_domain": o.managed_object.administrative_domain_id, "administrative_domain__label": o.managed_object.administrative_domain.name, "severity": o.severity, "severity__label": s.name, "alarm_class": str(o.alarm_class.id), "alarm_class__label": o.alarm_class.name, "timestamp": self.to_json(o.timestamp), "subject": o.subject, "events": n_events, "duration": o.duration, "row_class": s.style.css_class_name } if fields: d = dict((k, d[k]) for k in fields) return d
def instance_to_dict(self, o, fields=None): s = AlarmSeverity.get_severity(o.severity) n_events = (ActiveEvent.objects.filter(alarms=o.id).count() + ArchivedEvent.objects.filter(alarms=o.id).count()) mtc = o.managed_object.id in Maintenance.currently_affected() if o.status == "C": # For archived alarms mtc = Maintenance.objects.filter( start__lte=o.clear_timestamp, stop__lte=o.timestamp, affected_objects__in=[ MaintenanceObject(object=o.managed_object) ]).count() > 0 d = { "id": str(o.id), "status": o.status, "managed_object": o.managed_object.id, "managed_object__label": o.managed_object.name, "administrative_domain": o.managed_object.administrative_domain_id, "administrative_domain__label": o.managed_object.administrative_domain.name, "severity": o.severity, "severity__label": s.name, "alarm_class": str(o.alarm_class.id), "alarm_class__label": o.alarm_class.name, "timestamp": self.to_json(o.timestamp), "subject": o.subject, "events": n_events, "duration": o.duration, "clear_timestamp": self.to_json(o.clear_timestamp) if o.status == "C" else None, "row_class": s.style.css_class_name, "segment__label": o.managed_object.segment.name, "segment": str(o.managed_object.segment.id), "location_1": self.location(o.managed_object.container.id)[0] if o.managed_object.container else "", "location_2": self.location(o.managed_object.container.id)[1] if o.managed_object.container else "", "escalation_tt": o.escalation_tt, "escalation_error": o.escalation_error, "platform": o.managed_object.platform.name if o.managed_object.platform else "", "address": o.managed_object.address, "isInMaintenance": mtc, "summary": self.f_glyph_summary({ "subscriber": SummaryItem.items_to_dict(o.total_subscribers), "service": SummaryItem.items_to_dict(o.total_services) }), "total_objects": sum(x.summary for x in o.total_objects) } if fields: d = dict((k, d[k]) for k in fields) return d
def get_data(self): if not self.object: return None # Get container path cp = [] if self.object.managed_object.container: c = self.object.managed_object.container.id while c: try: o = Object.objects.get(id=c) # @todo: Address data if o.container: cp.insert(0, {"id": o.id, "name": o.name}) c = o.container.id if o.container else None except DoesNotExist: metrics["error", ("type", "user_not_found")] += 1 break # Build log log = [] if self.object.log: log = [{ "timestamp": l.timestamp, "from_status": l.from_status, "to_status": l.to_status, "message": l.message } for l in self.object.log] # Build alarm tree alarms = self.get_alarms() # Service summary service_summary = { "service": SummaryItem.items_to_dict(self.object.total_services), "subscriber": SummaryItem.items_to_dict(self.object.total_subscribers) } # Maintenance mainteinance = Maintenance.objects.filter( is_completed=False, start__lte=datetime.datetime.now(), affected_objects__in=[ MaintenanceObject(object=self.object.managed_object) ]) mo = self.object.managed_object # Build result r = { "id": self.object.id, "alarm": self.object, "severity": AlarmSeverity.get_severity(self.object.severity), "managed_object": self.object.managed_object, "timestamp": self.object.timestamp, "duration": self.object.display_duration, "subject": self.object.subject, "body": self.object.body, "container_path": cp, "log": log, "service_summary": service_summary, "alarms": alarms, "diagnostic": AlarmDiagnostic.get_diagnostics(self.object), "maintenance": mainteinance, "lon": mo.x, "lat": mo.y, "zoom": mo.default_zoom, "tt_system": self.object.managed_object.tt_system.name if self.object.managed_object.tt_system else None, "tt_system_failed": (self.object.status == "A" and not self.object.escalation_tt and self.object.managed_object.tt_system and self.object.managed_object.tt_system.is_failed()), "escalation_ctx": self.object.escalation_ctx, "escalation_close_ctx": getattr(self.object, "escalation_close_ctx", None) } return r
def instance_to_dict(self, o, fields=None): s = AlarmSeverity.get_severity(o.severity) n_events = (ActiveEvent.objects.filter(alarms=o.id).count() + ArchivedEvent.objects.filter(alarms=o.id).count()) d = { "id": str(o.id), "status": o.status, "managed_object": o.managed_object.id, "managed_object__label": o.managed_object.name, "administrative_domain": o.managed_object.administrative_domain_id, "administrative_domain__label": o.managed_object.administrative_domain.name, "severity": o.severity, "severity__label": s.name, "alarm_class": str(o.alarm_class.id), "alarm_class__label": o.alarm_class.name, "timestamp": self.to_json(o.timestamp), "subject": o.subject, "events": n_events, "duration": o.duration, "clear_timestamp": self.to_json(o.clear_timestamp) if o.status == "C" else None, "row_class": s.style.css_class_name, "segment__label": o.managed_object.segment.name, "segment": str(o.managed_object.segment.id), "location_1": self.location(o.managed_object.container.id)[0] if o.managed_object.container else "", "location_2": self.location(o.managed_object.container.id)[1] if o.managed_object.container else "", "escalation_tt": o.escalation_tt, "escalation_error": o.escalation_error, "platform": o.managed_object.platform.name if o.managed_object.platform else "", "address": o.managed_object.address, "ack_ts": self.to_json(o.ack_ts), "ack_user": o.ack_user, "summary": self.f_glyph_summary({ "subscriber": SummaryItem.items_to_dict(o.total_subscribers), "service": SummaryItem.items_to_dict(o.total_services), }), "total_objects": sum(x.summary for x in o.total_objects), "total_subscribers": self.f_summary( {"subscriber": SummaryItem.items_to_dict(o.total_subscribers)}), "total_services": self.f_summary( {"service": SummaryItem.items_to_dict(o.total_services)}), "logs": [{ "timestamp": self.to_json(ll.timestamp), "user": ll.source or "NOC", "message": ll.message, } for ll in o.log if getattr(ll, "source", None) ][:config.web.api_alarm_comments_limit], } if fields: d = {k: d[k] for k in fields} return d