Skip to content

Commit

Permalink
Merge "Fixed alarm related issues"
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrzhang authored and Gerrit Code Review committed May 21, 2024
2 parents c6b86db + 0d104e7 commit 33c7e7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 9 additions & 7 deletions o2ims/adapter/clients/fault_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,16 @@ def getSubcloudFaultClient(self, subcloud_id):
try:
sub_is_https = False
os_client_args = config.get_stx_access_info(
region_name=subcloud[0].name,
region_name=subcloud[0].region_name,
subcloud_hostname=subcloud[0].oam_floating_ip)
stx_client = get_stx_client(**os_client_args)
except EndpointException as e:
msg = e.format_message()
if CGTSCLIENT_ENDPOINT_ERROR_MSG in msg:
sub_is_https = True
os_client_args = config.get_stx_access_info(
region_name=subcloud[0].name, sub_is_https=sub_is_https,
region_name=subcloud[0].region_name,
sub_is_https=sub_is_https,
subcloud_hostname=subcloud[0].oam_floating_ip)
stx_client = get_stx_client(**os_client_args)
else:
Expand Down Expand Up @@ -192,16 +193,17 @@ def getAlarmList(self, **filters) -> List[alarmModel.FaultGenericModel]:
alarms = self.fmclient.alarm.list(expand=True)
if len(alarms) == 0:
return []
logger.debug('alarm 1:' + str(alarms[0].to_dict()))
# [print('alarm:' + str(alarm.to_dict())) for alarm in alarms if alarm]
[logger.debug(
'alarm:' + str(alarm.to_dict())) for alarm in alarms if alarm]
return [alarmModel.FaultGenericModel(
alarmModel.EventTypeEnum.ALARM, self._alarmconverter(alarm))
for alarm in alarms if alarm]

def getAlarmInfo(self, id) -> alarmModel.FaultGenericModel:
try:
alarm = self.fmclient.alarm.get(id)
logger.debug('get alarm id ' + id + ':' + str(alarm.to_dict()))
logger.debug(
'get alarm id: ' + id + ', result:' + str(alarm.to_dict()))
except HTTPNotFound:
event = self.fmclient.event_log.get(id)
return alarmModel.FaultGenericModel(
Expand All @@ -212,8 +214,8 @@ def getAlarmInfo(self, id) -> alarmModel.FaultGenericModel:

def getEventList(self, **filters) -> List[alarmModel.FaultGenericModel]:
events = self.fmclient.event_log.list(alarms=True, expand=True)
logger.debug('event 1:' + str(events[0].to_dict()))
# [print('alarm:' + str(event.to_dict())) for event in events if event]
[logger.debug(
'alarm:' + str(event.to_dict())) for event in events if event]
return [alarmModel.FaultGenericModel(
alarmModel.EventTypeEnum.EVENT, self._eventconverter(event))
for event in events if event]
Expand Down
12 changes: 8 additions & 4 deletions o2ims/service/auditor/alarm_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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)
Expand Down

0 comments on commit 33c7e7d

Please sign in to comment.