Commit 6c5a6c8f authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'patch-avs-add-field-tp-pm-alarm' into 'master'

Add labels, sensor and sla_probe field to PM Threshold alarm.

See merge request noc/noc!5641
parents 86db5eb8 42653663
...@@ -19,6 +19,18 @@ ...@@ -19,6 +19,18 @@
"name": "path", "name": "path",
"description": "Path to component raising alarm" "description": "Path to component raising alarm"
}, },
{
"name": "labels",
"description": "Metric labels"
},
{
"name": "sensor",
"description": "Sensor BI_ID for sensor alarm"
},
{
"name": "sla_probe",
"description": "SLA Probe BI_ID for SLA threshold"
},
{ {
"name": "value", "name": "value",
"description": "Metric value" "description": "Metric value"
......
...@@ -19,6 +19,18 @@ ...@@ -19,6 +19,18 @@
"name": "path", "name": "path",
"description": "Path to component raising alarm" "description": "Path to component raising alarm"
}, },
{
"name": "labels",
"description": "Metric labels"
},
{
"name": "sensor",
"description": "Sensor BI_ID for sensor alarm"
},
{
"name": "sla_probe",
"description": "SLA Probe BI_ID for SLA threshold"
},
{ {
"name": "value", "name": "value",
"description": "Metric value" "description": "Metric value"
......
...@@ -19,6 +19,18 @@ ...@@ -19,6 +19,18 @@
"name": "path", "name": "path",
"description": "Path to component raising alarm" "description": "Path to component raising alarm"
}, },
{
"name": "labels",
"description": "Metric labels"
},
{
"name": "sensor",
"description": "Sensor BI_ID for sensor alarm"
},
{
"name": "sla_probe",
"description": "SLA Probe BI_ID for SLA threshold"
},
{ {
"name": "value", "name": "value",
"description": "Metric value" "description": "Metric value"
......
...@@ -19,6 +19,18 @@ ...@@ -19,6 +19,18 @@
"name": "path", "name": "path",
"description": "Path to component raising alarm" "description": "Path to component raising alarm"
}, },
{
"name": "labels",
"description": "Metric labels"
},
{
"name": "sensor",
"description": "Sensor BI_ID for sensor alarm"
},
{
"name": "sla_probe",
"description": "SLA Probe BI_ID for SLA threshold"
},
{ {
"name": "value", "name": "value",
"description": "Metric value" "description": "Metric value"
......
...@@ -546,11 +546,11 @@ class MetricsCheck(DiscoveryCheck): ...@@ -546,11 +546,11 @@ class MetricsCheck(DiscoveryCheck):
if not path.endswith(m_path): if not path.endswith(m_path):
path = "%s | %s" % (path, m_path) path = "%s | %s" % (path, m_path)
if cfg.threshold_profile and m.abs_value is not None: if cfg.threshold_profile and m.abs_value is not None:
alarm, event = self.process_thresholds(m, cfg, path) alarm, event = self.process_thresholds(m, cfg, path, labels)
alarms += alarm alarms += alarm
events += event events += event
elif self.job.context["active_thresholds"].get(path): elif self.job.context["active_thresholds"].get(path):
alarm, event = self.clear_process_thresholds(m, cfg, path) alarm, event = self.clear_process_thresholds(m, cfg, path, labels)
alarms += alarm alarms += alarm
events += event events += event
else: else:
...@@ -717,11 +717,13 @@ class MetricsCheck(DiscoveryCheck): ...@@ -717,11 +717,13 @@ class MetricsCheck(DiscoveryCheck):
self.logger.error("Cannot calculate thresholds for %s (%s): %s", m.metric, m.labels, e) self.logger.error("Cannot calculate thresholds for %s (%s): %s", m.metric, m.labels, e)
return None return None
def clear_process_thresholds(self, m, cfg, path): def clear_process_thresholds(self, m, cfg, path, labels=None):
""" """
Check thresholds Check thresholds
:param m: dict with metric result :param m: dict with metric result
:param cfg: MetricConfig :param cfg: MetricConfig
:param path:
:param labels:
:return: List of umbrella alarm details :return: List of umbrella alarm details
""" """
alarms = [] alarms = []
...@@ -749,6 +751,7 @@ class MetricsCheck(DiscoveryCheck): ...@@ -749,6 +751,7 @@ class MetricsCheck(DiscoveryCheck):
threshold.close_event_class.name, threshold.close_event_class.name,
path, path,
m.value, m.value,
labels=labels,
) )
if threshold.close_handler: if threshold.close_handler:
if threshold.close_handler.allow_threshold: if threshold.close_handler.allow_threshold:
...@@ -762,12 +765,15 @@ class MetricsCheck(DiscoveryCheck): ...@@ -762,12 +765,15 @@ class MetricsCheck(DiscoveryCheck):
self.logger.warning("Handler is not allowed for Thresholds") self.logger.warning("Handler is not allowed for Thresholds")
return alarms, events return alarms, events
def process_thresholds(self, m: MData, cfg: MetricConfig, path: str): def process_thresholds(
self, m: MData, cfg: MetricConfig, path: str, labels: Optional[List[str]] = None
):
""" """
Check thresholds Check thresholds
:param m: dict with metric result :param m: dict with metric result
:param cfg: MetricConfig :param cfg: MetricConfig
:param path: Metric path :param path: Metric path
:param labels: Metric labels
:return: List of umbrella alarm details :return: List of umbrella alarm details
""" """
alarms = [] alarms = []
...@@ -802,6 +808,9 @@ class MetricsCheck(DiscoveryCheck): ...@@ -802,6 +808,9 @@ class MetricsCheck(DiscoveryCheck):
threshold.close_event_class.name, threshold.close_event_class.name,
path, path,
w_value, w_value,
labels=labels,
sensor=self.sensors_metrics.get(m.id),
sla_probe=self.sla_probe_metrics.get(m.id),
) )
if threshold.close_handler: if threshold.close_handler:
if threshold.close_handler.allow_threshold: if threshold.close_handler.allow_threshold:
...@@ -815,7 +824,15 @@ class MetricsCheck(DiscoveryCheck): ...@@ -815,7 +824,15 @@ class MetricsCheck(DiscoveryCheck):
self.logger.warning("Handler is not allowed for Thresholds") self.logger.warning("Handler is not allowed for Thresholds")
elif threshold.alarm_class: elif threshold.alarm_class:
# Remain umbrella alarm # Remain umbrella alarm
alarms += self.get_umbrella_alarm_cfg(cfg, threshold, path, w_value) alarms += self.get_umbrella_alarm_cfg(
cfg,
threshold,
path,
w_value,
labels=labels,
sensor=self.sensors_metrics.get(m.id),
sla_probe=self.sla_probe_metrics.get(m.id),
)
elif threshold: elif threshold:
if threshold.is_clear_match(w_value): if threshold.is_clear_match(w_value):
# Close Event # Close Event
...@@ -829,6 +846,9 @@ class MetricsCheck(DiscoveryCheck): ...@@ -829,6 +846,9 @@ class MetricsCheck(DiscoveryCheck):
threshold.close_event_class.name, threshold.close_event_class.name,
path, path,
w_value, w_value,
labels=labels,
sensor=self.sensors_metrics.get(m.id),
sla_probe=self.sla_probe_metrics.get(m.id),
) )
if threshold.close_handler: if threshold.close_handler:
if threshold.close_handler.allow_threshold: if threshold.close_handler.allow_threshold:
...@@ -842,7 +862,15 @@ class MetricsCheck(DiscoveryCheck): ...@@ -842,7 +862,15 @@ class MetricsCheck(DiscoveryCheck):
self.logger.warning("Handler is not allowed for Thresholds") self.logger.warning("Handler is not allowed for Thresholds")
if threshold.alarm_class: if threshold.alarm_class:
# Remain umbrella alarm # Remain umbrella alarm
alarms += self.get_umbrella_alarm_cfg(cfg, threshold, path, w_value) alarms += self.get_umbrella_alarm_cfg(
cfg,
threshold,
path,
w_value,
labels=labels,
sensor=self.sensors_metrics.get(m.id),
sla_probe=self.sla_probe_metrics.get(m.id),
)
else: else:
# Threshold has been reconfigured or deleted # Threshold has been reconfigured or deleted
if active.get("close_event_class"): if active.get("close_event_class"):
...@@ -853,6 +881,9 @@ class MetricsCheck(DiscoveryCheck): ...@@ -853,6 +881,9 @@ class MetricsCheck(DiscoveryCheck):
active["close_event_class"].name, active["close_event_class"].name,
path, path,
w_value, w_value,
labels=labels,
sensor=self.sensors_metrics.get(m.id),
sla_probe=self.sla_probe_metrics.get(m.id),
) )
if active.get("close_handler"): if active.get("close_handler"):
if active["close_handler"].allow_threshold: if active["close_handler"].allow_threshold:
...@@ -887,6 +918,9 @@ class MetricsCheck(DiscoveryCheck): ...@@ -887,6 +918,9 @@ class MetricsCheck(DiscoveryCheck):
threshold.open_event_class.name, threshold.open_event_class.name,
path, path,
w_value, w_value,
labels=labels,
sensor=self.sensors_metrics.get(m.id),
sla_probe=self.sla_probe_metrics.get(m.id),
) )
if threshold.open_handler: if threshold.open_handler:
if threshold.open_handler.allow_threshold: if threshold.open_handler.allow_threshold:
...@@ -901,24 +935,40 @@ class MetricsCheck(DiscoveryCheck): ...@@ -901,24 +935,40 @@ class MetricsCheck(DiscoveryCheck):
self.logger.warning("Handler is not allowed for Thresholds") self.logger.warning("Handler is not allowed for Thresholds")
if threshold.alarm_class: if threshold.alarm_class:
# Raise umbrella alarm # Raise umbrella alarm
alarms += self.get_umbrella_alarm_cfg(cfg, threshold, path, w_value) alarms += self.get_umbrella_alarm_cfg(
cfg,
threshold,
path,
w_value,
labels=labels,
sensor=self.sensors_metrics.get(m.id),
sla_probe=self.sla_probe_metrics.get(m.id),
)
break break
return alarms, events return alarms, events
def get_umbrella_alarm_cfg(self, metric_config, threshold, path, value): def get_umbrella_alarm_cfg(
self, metric_config, threshold, path, value, labels=None, sensor=None, sla_probe=None
):
""" """
Get configuration for umbrella alarm Get configuration for umbrella alarm
:param threshold: :param threshold:
:param path:
:param metric_config: :param metric_config:
:param value: :param value:
:param labels:
:param sensor:
:param sla_probe:
:return: List of dicts or empty list :return: List of dicts or empty list
""" """
self.logger.info("Get Umbrella Alarm CFG: %s", metric_config)
alarm_cfg = { alarm_cfg = {
"alarm_class": threshold.alarm_class, "alarm_class": threshold.alarm_class,
"path": path, "path": path,
"severity": threshold.alarm_class.default_severity.severity, "severity": threshold.alarm_class.default_severity.severity,
"vars": { "vars": {
"path": path, "path": path,
"labels": ";".join(labels or []),
"metric": metric_config.metric_type.name, "metric": metric_config.metric_type.name,
"value": value, "value": value,
"window_type": metric_config.threshold_profile.window_type, "window_type": metric_config.threshold_profile.window_type,
...@@ -926,6 +976,10 @@ class MetricsCheck(DiscoveryCheck): ...@@ -926,6 +976,10 @@ class MetricsCheck(DiscoveryCheck):
"window_function": metric_config.threshold_profile.window_function, "window_function": metric_config.threshold_profile.window_function,
}, },
} }
if sensor:
alarm_cfg["vars"]["sensor"] = str(sensor)
if sla_probe:
alarm_cfg["vars"]["sla_probe"] = str(sla_probe)
if metric_config.threshold_profile.umbrella_filter_handler: if metric_config.threshold_profile.umbrella_filter_handler:
if metric_config.threshold_profile.umbrella_filter_handler.allow_threshold_handler: if metric_config.threshold_profile.umbrella_filter_handler.allow_threshold_handler:
try: try:
...@@ -940,14 +994,29 @@ class MetricsCheck(DiscoveryCheck): ...@@ -940,14 +994,29 @@ class MetricsCheck(DiscoveryCheck):
self.logger.warning("Umbrella filter Handler is not allowed for Thresholds") self.logger.warning("Umbrella filter Handler is not allowed for Thresholds")
return [alarm_cfg] return [alarm_cfg]
def get_event_cfg(self, metric_config, threshold_profile, threshold, event_class, path, value): def get_event_cfg(
self,
metric_config,
threshold_profile,
threshold,
event_class,
path,
value,
labels=None,
sensor=None,
sla_probe=None,
):
""" """
Get configuration for umbrella alarm Get configuration for umbrella alarm
:param metric_config: :param metric_config:
:param threshold_profile:
:param threshold: :param threshold:
:param event_class: :param event_class:
:param path: :param path:
:param value: :param value:
:param labels:
:param sensor:
:param sla_probe:
:return: List of dicts or empty list :return: List of dicts or empty list
""" """
full_path = path full_path = path
...@@ -956,6 +1025,7 @@ class MetricsCheck(DiscoveryCheck): ...@@ -956,6 +1025,7 @@ class MetricsCheck(DiscoveryCheck):
result = False result = False
raw_vars = { raw_vars = {
"path": path.strip(), "path": path.strip(),
"labels": ";".join(labels or []),
"full_path": full_path, "full_path": full_path,
"threshold": threshold, "threshold": threshold,
"metric": metric_config.metric_type.name, "metric": metric_config.metric_type.name,
...@@ -964,6 +1034,10 @@ class MetricsCheck(DiscoveryCheck): ...@@ -964,6 +1034,10 @@ class MetricsCheck(DiscoveryCheck):
"window": str(threshold_profile.window), "window": str(threshold_profile.window),
"window_function": threshold_profile.window_function, "window_function": threshold_profile.window_function,
} }
if sensor:
raw_vars["sensor"] = str(sensor)
if sla_probe:
raw_vars["sla_probe"] = str(sla_probe)
if threshold_profile.umbrella_filter_handler: if threshold_profile.umbrella_filter_handler:
if threshold_profile.umbrella_filter_handler.allow_threshold_handler: if threshold_profile.umbrella_filter_handler.allow_threshold_handler:
try: try:
......
Supports Markdown
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