The o2ims-infrastructure Monitoring alarms doesnt display the 60/14760/1
authorvpachchi <vineela.pachchipulusu@windriver.com>
Tue, 22 Jul 2025 14:41:10 +0000 (10:41 -0400)
committerJon Zhang <rong.zhang@windriver.com>
Wed, 20 Aug 2025 01:39:59 +0000 (01:39 +0000)
deleted FM alarm

Test Plan:

PASS - Verify that the regression testing works
PASS - The delete alarms are not seen in the O2ims infrastructure
monitoring alarms

Change-Id: I42b5a65b2351678eeb63003b86550dff77d79cf6
Signed-off-by: vpachchi <vineela.pachchipulusu@windriver.com>
(cherry picked from commit 0e93e0325314971d22703e4668f684ccb41f3560)

o2ims/service/watcher/alarm_watcher.py

index c445031..51badc3 100644 (file)
@@ -37,13 +37,41 @@ class AlarmWatcher(BaseWatcher):
     def _targetname(self):
         return "alarm"
 
+    def _prune_stale_alarms(self):
+        """Prune alarms from DB that no longer exist in FM."""
+        try:
+            current_alarms = self._client.list()
+            # Build set of current alarm IDs from FM
+            current_ids = set([a.id for a in current_alarms])
+            logger.info(f'Current alarm IDs from FM: {current_ids}')
+            with self._bus.uow as uow:
+                db_alarms = list(uow.alarm_event_records.list().all())
+                db_ids = set(a.alarmEventRecordId for a in db_alarms)
+                deleted_ids = db_ids - current_ids
+
+                # TODO: When an alarm is deleted, the SMO must be notified.
+
+                for del_id in deleted_ids:
+                    alarm_obj = uow.alarm_event_records.get(del_id)
+                    if alarm_obj:
+                        uow.alarm_event_records.delete(alarm_obj)
+                if deleted_ids:
+                    logger.info(f'Committing pruning of {deleted_ids} alarms \
+                                from DB')
+                    uow.commit()
+        except Exception as e:
+            logger.error(f'Error pruning stale alarms: {str(e)}')
+
     def _probe(self, parent: StxGenericModel, tags: object = None):
+
         # Set a tag for children resource
         self._tags.pool = parent.res_pool_id
         self._set_respool_client()
 
         resourcepoolid = parent.id
 
+        # Check and clear the pruned alarms
+        self._prune_stale_alarms()
         # Check and delete expired alarms before getting new alarms
         self._check_and_delete_expired_alarms()