Bug 2079 fixed: added more operators to the metric evaluation 00/12200/2
authorPedro Escaleira <escaleira@av.it.pt>
Tue, 14 Jun 2022 12:27:32 +0000 (13:27 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 23 Aug 2022 15:05:29 +0000 (17:05 +0200)
Change-Id: Ied173778c8350a141a9237289d40a904d032bb13
Signed-off-by: Pedro Escaleira <escaleira@av.it.pt>
osm_mon/evaluator/service.py

index 9049d95..ae6191b 100644 (file)
@@ -54,6 +54,12 @@ class EvaluatorService:
         ).get_metric_value(metric_name, tags)
 
     def _evaluate_metric(self, alarm: Alarm):
+        """Method to evaluate a metric value comparing it against an alarm threshold.
+
+        Args:
+            alarm (Alarm): the alarm with the threshold to compare the metric against
+        """
+
         log.debug("_evaluate_metric")
         metric_value = self._get_metric_value(alarm.metric, alarm.tags)
         if alarm.alarm_status.upper() != AlarmStatus.DISABLED.value.upper():
@@ -61,16 +67,32 @@ class EvaluatorService:
                 log.warning("No metric result for alarm %s", alarm.uuid)
                 self.queue.put((alarm, AlarmStatus.INSUFFICIENT))
             else:
-                if alarm.operation.upper() == "GT":
-                    if metric_value > alarm.threshold:
-                        self.queue.put((alarm, AlarmStatus.ALARM))
-                    else:
-                        self.queue.put((alarm, AlarmStatus.OK))
-                elif alarm.operation.upper() == "LT":
-                    if metric_value < alarm.threshold:
-                        self.queue.put((alarm, AlarmStatus.ALARM))
-                    else:
-                        self.queue.put((alarm, AlarmStatus.OK))
+                if (
+                    (alarm.operation.upper() == "GT" and metric_value > alarm.threshold)
+                    or (
+                        alarm.operation.upper() == "LT"
+                        and metric_value < alarm.threshold
+                    )
+                    or (
+                        alarm.operation.upper() == "GE"
+                        and metric_value >= alarm.threshold
+                    )
+                    or (
+                        alarm.operation.upper() == "LE"
+                        and metric_value <= alarm.threshold
+                    )
+                    or (
+                        alarm.operation.upper() == "EQ"
+                        and metric_value == alarm.threshold
+                    )
+                    or (
+                        alarm.operation.upper() == "NE"
+                        and metric_value != alarm.threshold
+                    )
+                ):
+                    self.queue.put((alarm, AlarmStatus.ALARM))
+                elif alarm.operation.upper() in ("GT", "LT", "GE", "LE", "EQ", "NE"):
+                    self.queue.put((alarm, AlarmStatus.OK))
 
     def update_alarm_status(self, alarm_state, uuid):
         alarm_data = self.common_db.get_alarm_by_uuid(uuid)