-# Copyright (C) 2021 Wind River Systems, Inc.
+# Copyright (C) 2021-2024 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
from o2common.views.pagination_route import link_header, PAGE_PARAM
from o2common.views.route_exception import NotFoundException, \
BadRequestException
+from o2ims.domain.alarm_obj import PerceivedSeverityEnum
from o2ims.views import alarm_view
from o2ims.views.api_ns import api_ims_monitoring as api_monitoring_v1
-from o2ims.views.alarm_dto import AlarmDTO, SubscriptionDTO
+from o2ims.views.alarm_dto import AlarmDTO, SubscriptionDTO, \
+ MonitoringApiV1DTO
from o2common.helper import o2logging
logger = o2logging.get_logger(__name__)
# ---------- API versions ---------- #
@api_monitoring_v1.route("/v1/api_versions")
class VersionRouter(Resource):
+ model = MonitoringApiV1DTO.api_version_info_get
+
@api_monitoring_v1.doc('Get Monitoring API version')
+ @api_monitoring_v1.marshal_list_with(model)
def get(self):
return {
'uriPrefix': request.base_url.rsplit('/', 1)[0],
class AlarmGetRouter(Resource):
model = AlarmDTO.alarm_event_record_get
+ patch = AlarmDTO.alarm_event_record_patch
@api_monitoring_v1.doc('Get Alarm Event Record Information')
@api_monitoring_v1.marshal_with(model)
raise NotFoundException(
"Alarm Event Record {} doesn't exist".format(alarmEventRecordId))
+ @api_monitoring_v1.doc('Patch Alarm Event Record Information')
+ @api_monitoring_v1.expect(patch)
+ @api_monitoring_v1.marshal_with(patch)
+ def patch(self, alarmEventRecordId):
+ data = api_monitoring_v1.payload
+ ack_action = data.get('alarmAcknowledged', None)
+ clear_action = data.get('perceivedSeverity', None)
+
+ ack_is_none = ack_action is None
+ clear_is_none = clear_action is None
+ if (ack_is_none and clear_is_none) or (not ack_is_none and
+ not clear_is_none):
+ raise BadRequestException('Either "alarmAcknowledged" or '
+ '"perceivedSeverity" shall be included '
+ 'in a request, but not both.')
+ if ack_action:
+ result = alarm_view.alarm_event_record_ack(alarmEventRecordId,
+ bus.uow)
+ if result is not None:
+ return result
+ elif clear_action:
+ if clear_action != PerceivedSeverityEnum.CLEARED:
+ raise BadRequestException(
+ 'Only the value "5" for "CLEARED" is permitted of '
+ '"perceivedSeverity".')
+
+ result = alarm_view.alarm_event_record_clear(alarmEventRecordId,
+ bus.uow)
+ if result is not None:
+ return result
+ raise NotFoundException(
+ "Alarm Event Record {} doesn't exist".format(alarmEventRecordId))
+
# ---------- Alarm Subscriptions ---------- #
@api_monitoring_v1.route("/v1/alarmSubscriptions")