Commit f72095e7 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'fix-avs-alarm-labels-calc' into 'master'

Fix calculate effective_labels.

See merge request noc/noc!5891
parents fb0ccec3 d950216e
......@@ -8,6 +8,7 @@
# Python modules
import datetime
from collections import defaultdict
from itertools import chain
from typing import Optional, Set, Any, Dict
# Third-party modules
......@@ -174,7 +175,7 @@ class ActiveAlarm(Document):
self.rca_neighbors = data.rca_neighbors
self.dlm_windows = data.dlm_windows
if not self.id:
self.effective_labels = self.iter_effective_labels(self)
self.effective_labels = list(chain.from_iterable(self.iter_effective_labels(self)))
def safe_save(self, **kwargs):
"""
......@@ -855,14 +856,16 @@ class ActiveAlarm(Document):
@classmethod
def iter_effective_labels(cls, instance: "ActiveAlarm"):
return [ll for ll in instance.managed_object.effective_labels if cls.can_set_label(ll)]
yield instance.labels
yield [
ll
for ll in instance.managed_object.effective_labels
if Label.get_effective_setting(ll, "expose_alarm")
]
@classmethod
def can_set_label(cls, label):
return Label.get_effective_setting(label, "enable_alarm") or Label.get_effective_setting(
label, "expose_alarm"
)
return Label.get_effective_setting(label, "enable_alarm")
class ComponentHub(object):
......
......@@ -34,7 +34,7 @@ class Group(object):
reference_template: Template
alarm_class: AlarmClass
title_template: Template
labels: Optional[List[str]]
labels: Optional[List[str]] = None
@dataclass
......@@ -42,7 +42,7 @@ class GroupItem(object):
reference: str
alarm_class: AlarmClass
title: str
labels: Optional[List[str]]
labels: Optional[List[str]] = None
class AlarmRule(object):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment