1 # Copyright (C) 2024 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from o2common.service.unit_of_work import AbstractUnitOfWork
18 from o2common.adapter.notifications import AbstractNotifications
20 from o2ims.adapter.clients.fault_client import StxEventClient
21 from o2ims.domain import commands, alarm_obj
23 from o2common.helper import o2logging
24 logger = o2logging.get_logger(__name__)
27 def purge_alarm_event(
28 cmd: commands.PubAlarm2SMO,
29 uow: AbstractUnitOfWork,
30 notifications: AbstractNotifications,
32 logger.debug('In purge_alarm_event')
33 fault_client = StxEventClient(uow)
36 alarm_event_record = uow.alarm_event_records.get(data.id)
37 alarm_id = json.loads(alarm_event_record.extensions).get('alarm_id')
39 events = fault_client.suppression_list(alarm_id)
40 for event_id in events:
41 event = fault_client.suppress(event_id.id)
42 alarm_event_record.hash = event.hash
43 alarm_event_record.extensions = json.dumps(event.filtered)
44 alarm_event_record.alarmChangedTime = event.updatetime.\
45 strftime("%Y-%m-%dT%H:%M:%S")
46 alarm_event_record.perceivedSeverity = \
47 alarm_obj.PerceivedSeverityEnum.CLEARED
49 uow.alarm_event_records.update(alarm_event_record)