8
8
from app .api import deps
9
9
from app import tools
10
10
from app .db .session import client
11
- from app .api .api_v1 .endpoints .utils import add_notifications
11
+ from app .api .api_v1 .endpoints .utils import add_notifications , ccf_logs
12
12
from .ue_movement import retrieve_ue_state , retrieve_ue
13
+ import logging
13
14
14
15
router = APIRouter ()
15
16
db_collection = 'MonitoringEvent'
@@ -41,6 +42,16 @@ def read_active_subscriptions(
41
42
if retrieved_docs :
42
43
http_response = JSONResponse (content = retrieved_docs , status_code = 200 )
43
44
add_notifications (http_request , http_response , False )
45
+ #CAPIF Core Function Logging Service
46
+ try :
47
+ response = http_response .body .decode ("utf-8" )
48
+ json_response = {}
49
+ json_response .update ({"response" : response })
50
+ json_response .update ({"status_code" : str (http_response .status_code )})
51
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
52
+ except TypeError as error :
53
+ logging .critical (f"Error: { error } " )
54
+
44
55
return http_response
45
56
else :
46
57
return Response (status_code = 204 )
@@ -72,6 +83,14 @@ def create_subscription(
72
83
73
84
UE = ue .get_externalId (db = db , externalId = str (item_in .externalId ), owner_id = current_user .id )
74
85
if not UE :
86
+ #CAPIF Core Function Logging Service
87
+ try :
88
+ json_response = {}
89
+ json_response .update ({"response" : "UE with this external identifier doesn't exist" })
90
+ json_response .update ({"status_code" : "409" })
91
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
92
+ except TypeError as error :
93
+ logging .critical (f"Error: { error } " )
75
94
raise HTTPException (status_code = 409 , detail = "UE with this external identifier doesn't exist" )
76
95
77
96
@@ -98,12 +117,30 @@ def create_subscription(
98
117
http_response = JSONResponse (content = json_compatible_item_data , status_code = 200 )
99
118
add_notifications (http_request , http_response , False )
100
119
120
+ #CAPIF Core Function Logging Service
121
+ try :
122
+ response = http_response .body .decode ("utf-8" )
123
+ json_response = {}
124
+ json_response .update ({"response" : response })
125
+ json_response .update ({"status_code" : str (http_response .status_code )})
126
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
127
+ except TypeError as error :
128
+ logging .error (f"Error: { error } " )
129
+
101
130
return http_response
102
131
#Subscription
103
132
elif item_in .monitoringType == "LOCATION_REPORTING" and item_in .maximumNumberOfReports > 1 :
104
133
105
134
#Check if subscription with externalid exists
106
135
if crud_mongo .read_by_multiple_pairs (db_mongo , db_collection , externalId = item_in .externalId , monitoringType = item_in .monitoringType ):
136
+ #CAPIF Core Function Logging Service
137
+ try :
138
+ json_response = {}
139
+ json_response .update ({"response" : f"There is already an active subscription for UE with external id { item_in .externalId } - Monitoring Type = { item_in .monitoringType } " })
140
+ json_response .update ({"status_code" : "409" })
141
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
142
+ except TypeError as error :
143
+ logging .critical (f"Error: { error } " )
107
144
raise HTTPException (status_code = 409 , detail = f"There is already an active subscription for UE with external id { item_in .externalId } - Monitoring Type = { item_in .monitoringType } " )
108
145
109
146
json_data = jsonable_encoder (item_in .dict (exclude_unset = True ))
@@ -126,8 +163,27 @@ def create_subscription(
126
163
http_response = JSONResponse (content = updated_doc , status_code = 201 , headers = response_header )
127
164
add_notifications (http_request , http_response , False )
128
165
166
+ #CAPIF Core Function Logging Service
167
+ try :
168
+ response = http_response .body .decode ("utf-8" )
169
+ json_response = {}
170
+ json_response .update ({"response" : response })
171
+ json_response .update ({"status_code" : str (http_response .status_code )})
172
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
173
+ except TypeError as error :
174
+ logging .error (f"Error: { error } " )
175
+
129
176
return http_response
130
177
elif (item_in .monitoringType == "LOSS_OF_CONNECTIVITY" or item_in .monitoringType == "UE_REACHABILITY" ) and item_in .maximumNumberOfReports == 1 :
178
+
179
+ #CAPIF Core Function Logging Service
180
+ try :
181
+ json_response = {}
182
+ json_response .update ({"response" : "\" maximumNumberOfReports\" should be greater than 1 in case of LOSS_OF_CONNECTIVITY event" })
183
+ json_response .update ({"status_code" : "403" })
184
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
185
+ except TypeError as error :
186
+ logging .critical (f"Error: { error } " )
131
187
return JSONResponse (content = jsonable_encoder (
132
188
{
133
189
"title" : "The requested parameters are out of range" ,
@@ -140,6 +196,14 @@ def create_subscription(
140
196
elif (item_in .monitoringType == "LOSS_OF_CONNECTIVITY" or item_in .monitoringType == "UE_REACHABILITY" ) and item_in .maximumNumberOfReports > 1 :
141
197
#Check if subscription with externalid && monitoringType exists
142
198
if crud_mongo .read_by_multiple_pairs (db_mongo , db_collection , externalId = item_in .externalId , monitoringType = item_in .monitoringType ):
199
+ #CAPIF Core Function Logging Service
200
+ try :
201
+ json_response = {}
202
+ json_response .update ({"response" : f"There is already an active subscription for UE with external id { item_in .externalId } - Monitoring Type = { item_in .monitoringType } " })
203
+ json_response .update ({"status_code" : "409" })
204
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
205
+ except TypeError as error :
206
+ logging .critical (f"Error: { error } " )
143
207
raise HTTPException (status_code = 409 , detail = f"There is already an active subscription for UE with external id { item_in .externalId } - Monitoring Type = { item_in .monitoringType } " )
144
208
145
209
json_data = jsonable_encoder (item_in .dict (exclude_unset = True ))
@@ -161,6 +225,16 @@ def create_subscription(
161
225
162
226
http_response = JSONResponse (content = updated_doc , status_code = 201 , headers = response_header )
163
227
add_notifications (http_request , http_response , False )
228
+
229
+ #CAPIF Core Function Logging Service
230
+ try :
231
+ response = http_response .body .decode ("utf-8" )
232
+ json_response = {}
233
+ json_response .update ({"response" : response })
234
+ json_response .update ({"status_code" : str (http_response .status_code )})
235
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
236
+ except TypeError as error :
237
+ logging .error (f"Error: { error } " )
164
238
165
239
return http_response
166
240
@@ -183,10 +257,26 @@ def update_subscription(
183
257
try :
184
258
retrieved_doc = crud_mongo .read_uuid (db_mongo , db_collection , subscriptionId )
185
259
except Exception as ex :
260
+ #CAPIF Core Function Logging Service
261
+ try :
262
+ json_response = {}
263
+ json_response .update ({"response" : "Please enter a valid uuid (24-character hex string)" })
264
+ json_response .update ({"status_code" : "400" })
265
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
266
+ except TypeError as error :
267
+ logging .critical (f"Error: { error } " )
186
268
raise HTTPException (status_code = 400 , detail = 'Please enter a valid uuid (24-character hex string)' )
187
269
188
270
#Check if the document exists
189
271
if not retrieved_doc :
272
+ #CAPIF Core Function Logging Service
273
+ try :
274
+ json_response = {}
275
+ json_response .update ({"response" : "Subscription not found" })
276
+ json_response .update ({"status_code" : "404" })
277
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
278
+ except TypeError as error :
279
+ logging .critical (f"Error: { error } " )
190
280
raise HTTPException (status_code = 404 , detail = "Subscription not found" )
191
281
#If the document exists then validate the owner
192
282
if not user .is_superuser (current_user ) and (retrieved_doc ['owner_id' ] != current_user .id ):
@@ -205,6 +295,17 @@ def update_subscription(
205
295
206
296
http_response = JSONResponse (content = updated_doc , status_code = 200 )
207
297
add_notifications (http_request , http_response , False )
298
+
299
+ #CAPIF Core Function Logging Service
300
+ try :
301
+ response = http_response .body .decode ("utf-8" )
302
+ json_response = {}
303
+ json_response .update ({"response" : response })
304
+ json_response .update ({"status_code" : str (http_response .status_code )})
305
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
306
+ except TypeError as error :
307
+ logging .error (f"Error: { error } " )
308
+
208
309
return http_response
209
310
else :
210
311
crud_mongo .delete_by_uuid (db_mongo , db_collection , subscriptionId )
@@ -228,10 +329,25 @@ def read_subscription(
228
329
try :
229
330
retrieved_doc = crud_mongo .read_uuid (db_mongo , db_collection , subscriptionId )
230
331
except Exception as ex :
332
+ try :
333
+ json_response = {}
334
+ json_response .update ({"response" : "Please enter a valid uuid (24-character hex string)" })
335
+ json_response .update ({"status_code" : "400" })
336
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
337
+ except TypeError as error :
338
+ logging .critical (f"Error: { error } " )
231
339
raise HTTPException (status_code = 400 , detail = 'Please enter a valid uuid (24-character hex string)' )
232
340
233
341
#Check if the document exists
234
342
if not retrieved_doc :
343
+ #CAPIF Core Function Logging Service
344
+ try :
345
+ json_response = {}
346
+ json_response .update ({"response" : "Subscription not found" })
347
+ json_response .update ({"status_code" : "404" })
348
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
349
+ except TypeError as error :
350
+ logging .critical (f"Error: { error } " )
235
351
raise HTTPException (status_code = 404 , detail = "Subscription not found" )
236
352
#If the document exists then validate the owner
237
353
if not user .is_superuser (current_user ) and (retrieved_doc ['owner_id' ] != current_user .id ):
@@ -244,6 +360,17 @@ def read_subscription(
244
360
http_response = JSONResponse (content = retrieved_doc , status_code = 200 )
245
361
246
362
add_notifications (http_request , http_response , False )
363
+
364
+ #CAPIF Core Function Logging Service
365
+ try :
366
+ response = http_response .body .decode ("utf-8" )
367
+ json_response = {}
368
+ json_response .update ({"response" : response })
369
+ json_response .update ({"status_code" : str (http_response .status_code )})
370
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
371
+ except TypeError as error :
372
+ logging .error (f"Error: { error } " )
373
+
247
374
return http_response
248
375
else :
249
376
crud_mongo .delete_by_uuid (db_mongo , db_collection , subscriptionId )
@@ -266,10 +393,25 @@ def delete_subscription(
266
393
try :
267
394
retrieved_doc = crud_mongo .read_uuid (db_mongo , db_collection , subscriptionId )
268
395
except Exception as ex :
396
+ try :
397
+ json_response = {}
398
+ json_response .update ({"response" : "Please enter a valid uuid (24-character hex string)" })
399
+ json_response .update ({"status_code" : "400" })
400
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
401
+ except TypeError as error :
402
+ logging .critical (f"Error: { error } " )
269
403
raise HTTPException (status_code = 400 , detail = 'Please enter a valid uuid (24-character hex string)' )
270
404
271
405
#Check if the document exists
272
406
if not retrieved_doc :
407
+ #CAPIF Core Function Logging Service
408
+ try :
409
+ json_response = {}
410
+ json_response .update ({"response" : "Subscription not found" })
411
+ json_response .update ({"status_code" : "404" })
412
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
413
+ except TypeError as error :
414
+ logging .critical (f"Error: { error } " )
273
415
raise HTTPException (status_code = 404 , detail = "Subscription not found" )
274
416
#If the document exists then validate the owner
275
417
if not user .is_superuser (current_user ) and (retrieved_doc ['owner_id' ] != current_user .id ):
@@ -280,6 +422,17 @@ def delete_subscription(
280
422
281
423
http_response = JSONResponse (content = retrieved_doc , status_code = 200 )
282
424
add_notifications (http_request , http_response , False )
425
+
426
+ #CAPIF Core Function Logging Service
427
+ try :
428
+ response = http_response .body .decode ("utf-8" )
429
+ json_response = {}
430
+ json_response .update ({"response" : response })
431
+ json_response .update ({"status_code" : str (http_response .status_code )})
432
+ ccf_logs (http_request , json_response , "service_monitoring_event.json" , token_payload .get ("sub" ))
433
+ except TypeError as error :
434
+ logging .error (f"Error: { error } " )
435
+
283
436
return http_response
284
437
285
438
0 commit comments