Fix INF-383 refactor to enrich alarmEventRecord with extension field
[pti/o2.git] / o2ims / views / alarm_dto.py
1 # Copyright (C) 2021 Wind River Systems, Inc.
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 from flask_restx import fields
16
17 from o2common.views.flask_restx_fields import Json2Dict
18 from o2ims.views.api_ns import api_ims_monitoring as api_monitoring_v1
19
20
21 class AlarmDTO:
22
23     alarm_event_record_get = api_monitoring_v1.model(
24         "AlarmGetDto",
25         {
26             'alarmEventRecordId': fields.String(
27                 required=True,
28                 description='Alarm Event Record ID'),
29             'resourceTypeId': fields.String,
30             'resourceTypeID': fields.String(attribute='resourceTypeId'),
31             'resourceId': fields.String,
32             'resourceID': fields.String(attribute='resourceId'),
33             'alarmDefinitionId': fields.String,
34             'alarmDefinitionID': fields.String(attribute='alarmDefinitionId'),
35             'probableCauseId': fields.String,
36             'probableCauseID': fields.String(attribute='probableCauseId'),
37             'alarmRaisedTime': fields.String,
38             'alarmChangedTime': fields.String,
39             'alarmAcknowledgeTime': fields.String,
40             'alarmAcknowledged': fields.Boolean,
41             'perceivedSeverity': fields.String,
42             'extensions': Json2Dict(attribute='extensions')
43         }
44         # mask='{alarmEventRecordId,resourceTypeID,resourceID,' +
45         # 'alarmDefinitionID,probableCauseID,' +
46         # 'alarmRaisedTime,perceivedSeverity,alarmChangedTime,' +
47         # 'alarmAcknowledgeTime,alarmAcknowledged,extensions}'
48     )
49
50
51 class SubscriptionDTO:
52
53     subscription_get = api_monitoring_v1.model(
54         "AlarmSubscriptionGetDto",
55         {
56             'alarmSubscriptionId': fields.String(
57                 required=True,
58                 description='Alarm Subscription ID'),
59             'callback': fields.String,
60             'consumerSubscriptionId': fields.String,
61             'filter': fields.String,
62         },
63         mask='{alarmSubscriptionId,callback}'
64     )
65
66     subscription_create = api_monitoring_v1.model(
67         "AlarmSubscriptionCreateDto",
68         {
69             'callback': fields.String(
70                 required=True,
71                 description='Alarm Subscription callback address'),
72             'consumerSubscriptionId': fields.String,
73             'filter': fields.String,
74         }
75     )