Add capacity values for the DMS K8S profile
[pti/o2.git] / o2ims / service / auditor / alarm_handler.py
index 4c7c054..5f6ed35 100644 (file)
@@ -41,10 +41,6 @@ def update_alarm(
 
         alarm_event_record = uow.alarm_event_records.get(fmobj.id)
         if not alarm_event_record:
-            logger.info("add alarm event record:" + fmobj.name
-                        + " update_at: " + str(fmobj.updatetime)
-                        + " id: " + str(fmobj.id)
-                        + " hash: " + str(fmobj.hash))
             localmodel = create_by(fmobj)
             content = json.loads(fmobj.content)
             entity_type_id = content['entity_type_id']
@@ -65,6 +61,14 @@ def update_alarm(
                     extensions = json.loads(host.extensions)
                     if extensions['hostname'] == hostname:
                         localmodel.resourceId = host.resourceId
+                        break
+                else:
+                    # Example would be when alarm has host=controller
+                    # TODO: Handle host=controller better
+                    logger.warning(
+                        'Couldnt match alarm event '
+                        f'to hostname for: {content}')
+                    return
                 uow.alarm_event_records.add(localmodel)
                 logger.info("Add the alarm event record: " + fmobj.id
                             + ", name: " + fmobj.name)
@@ -137,9 +141,10 @@ def create_by(fmobj: FaultGenericModel) -> AlarmEventRecord:
 def update_by(target: AlarmEventRecord, fmobj: FaultGenericModel
               ) -> None:
     # content = json.loads(fmobj.content)
-    target.hash = fmobj.hash
     if fmobj.status == 'clear':
         target.perceivedSeverity = alarm_obj.PerceivedSeverityEnum.CLEARED
+
+    target.hash = fmobj.hash
     target.events.append(events.AlarmEventChanged(
         id=fmobj.id,
         notificationEventType=AlarmNotificationEventEnum.CLEAR,