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

Merge branch 'noc-correlator-alarm-labels' into 'master'

correlator: `labels` field in dispose protocol

See merge request noc/noc!5889
parents a6307c4f 0ac08319
......@@ -52,6 +52,7 @@ in the `$op` field. Unknown message types and malformed messages are discarded.
| {{ tab }} `name` | String | Optional group name |
| {{ tab }} `alarm_class` | String | Optional group alarm class name |
| `vars` | Object {{ complex }} | Alarm variables |
| `labels` | Array of String | Optional list of alarm labels |
| `remote_system` | String | Optional Remote System ID |
| `remote_id` | String | Optional Remote ID |
......@@ -73,9 +74,12 @@ in the `$op` field. Unknown message types and malformed messages are discarded.
| `reference` | String | Alarm reference. See [alarm reference format](../alarm-reference-format.md) for details |
| `name` | String | Group alarm title |
| `alarm_class` | String | Optional group alarm class |
| `labels` | Array of String | Optional list of group alarm labels |
| `alarms` | Array of Object {{ complex}} | List of active alarms |
| {{ tab }} `reference` | String | Alarm reference. See [alarm reference format](../alarm-reference-format.md) for details |
| {{ tab }} `timestamp` | String | Optional timestamp in ISO 8601 format |
| {{ tab }} `managed_object` | String | Managed Object'd ID |
| {{ tab }} `alarm_class` | String | Alarm class name |
| {{ tab }} `vars` | Object {{ complex }} | Alarm variables |
| {{ tab }} `labels` | Array of String | Optional list of alarm labels |
......@@ -34,6 +34,7 @@ class Group(object):
reference_template: Template
alarm_class: AlarmClass
title_template: Template
labels: Optional[List[str]]
@dataclass
......@@ -41,6 +42,7 @@ class GroupItem(object):
reference: str
alarm_class: AlarmClass
title: str
labels: Optional[List[str]]
class AlarmRule(object):
......@@ -119,6 +121,7 @@ class AlarmRule(object):
reference=group.reference_template.render(**ctx),
alarm_class=group.alarm_class,
title=group.title_template.render(**ctx),
labels=group.labels,
)
......
......@@ -18,6 +18,7 @@ class AlarmItem(BaseModel):
alarm_class: str
timestamp: Optional[str]
vars: Optional[Dict[str, Any]]
labels: Optional[List[str]]
remote_system: Optional[str]
remote_id: Optional[str]
......@@ -27,4 +28,5 @@ class EnsureGroupRequest(BaseModel):
reference: str
name: Optional[str]
alarm_class: Optional[str]
labels: Optional[str]
alarms: List[AlarmItem]
......@@ -26,5 +26,6 @@ class RaiseRequest(BaseModel):
timestamp: Optional[str]
groups: Optional[List[GroupItem]]
vars: Optional[Dict[str, Any]]
labels: Optional[List[str]]
remote_system: Optional[str]
remote_id: Optional[str]
......@@ -366,6 +366,7 @@ class CorrelatorService(TornadoService):
remote_system: Optional[RemoteSystem] = None,
remote_id: Optional[str] = None,
groups: Optional[List[GroupItem]] = None,
labels: Optional[List[str]] = None,
) -> Optional[ActiveAlarm]:
"""
Raise alarm
......@@ -378,9 +379,11 @@ class CorrelatorService(TornadoService):
:param remote_system:
:param remote_id:
:param groups:
:param labels:
:returns: Alarm, if created, None otherwise
"""
scope_label = str(event.id) if event else "DIRECT"
labels = labels or []
# @todo: Make configurable
if not managed_object.is_managed:
self.logger.info("Managed object is not managed. Do not raise alarm")
......@@ -455,6 +458,7 @@ class CorrelatorService(TornadoService):
)
],
opening_event=event.id if event else None,
labels=labels,
remote_system=remote_system,
remote_id=remote_id,
)
......@@ -478,13 +482,14 @@ class CorrelatorService(TornadoService):
if event:
event.contribute_to_alarm(a)
self.logger.info(
"[%s|%s|%s] Raise alarm %s(%s): %r",
"[%s|%s|%s] Raise alarm %s(%s): %r [%s]",
scope_label,
managed_object.name,
managed_object.address,
a.alarm_class.name,
a.id,
a.vars,
", ".join(labels),
)
metrics["alarm_raise"] += 1
await self.correlate(a)
......@@ -745,6 +750,7 @@ class CorrelatorService(TornadoService):
vars=req.vars,
reference=req.reference,
groups=groups,
labels=req.labels,
remote_system=remote_system,
remote_id=req.remote_id if remote_system else None,
)
......@@ -824,6 +830,7 @@ class CorrelatorService(TornadoService):
alarm_class=alarm_class,
vars={"name": req.name or "Group"},
reference=req.reference,
labels=req.labels,
)
# Fetch all open alarms in group
open_alarms: Dict[bytes, ActiveAlarm] = {
......@@ -850,6 +857,7 @@ class CorrelatorService(TornadoService):
title=req.name or "Group",
)
],
labels=ai.labels,
)
# Close hanging alarms
for h_ref in set(open_alarms) - seen_refs:
......@@ -1089,6 +1097,7 @@ class CorrelatorService(TornadoService):
alarm_class=group.alarm_class,
vars={"name": group.title},
reference=group.reference,
labels=group.labels,
)
if g_alarm:
# Update cache
......
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