From e2bb2d00f3075f693442db2d5d3dfcf02deed01a Mon Sep 17 00:00:00 2001 From: davidkneipp Date: Tue, 7 Nov 2023 12:52:51 +1000 Subject: [PATCH] SQN resync via geored --- CHANGELOG.md | 1 + lib/database.py | 20 +++++++++++++++----- services/apiService.py | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44bccd4..63cb5e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Reduced verbosity of failing subscriber lookups to debug - Added CORS headers: [Zarya/171](https://github.com/nickvsnetworking/pyhss/pull/171) - Gx RAR now dynamically creates TFT up to 512k based on UE request. +- SQN Resync now propogates via Geored when enabled ### Fixed diff --git a/lib/database.py b/lib/database.py index 8b7dca0..2d9644a 100755 --- a/lib/database.py +++ b/lib/database.py @@ -1556,9 +1556,19 @@ def Get_APN_by_Name(self, apn): self.safe_close(session) return result - def Update_AuC(self, auc_id, sqn=1): - self.logTool.log(service='Database', level='debug', message="Updating AuC record for sub " + str(auc_id), redisClient=self.redisMessaging) + def Update_AuC(self, auc_id, sqn=1, propagate=True): + self.logTool.log(service='Database', level='debug', message=f"Updating AuC record for ID: {auc_id}", redisClient=self.redisMessaging) self.logTool.log(service='Database', level='debug', message=self.UpdateObj(AUC, {'sqn': sqn}, auc_id, True), redisClient=self.redisMessaging) + + if propagate: + if self.config['geored'].get('enabled', False) == True: + aucBody = { + "auc_id": auc_id, + "sqn": sqn, + } + self.handleGeored(aucBody) + self.logTool.log(service='Database', level='debug', message=f"Sent Geored update for AuC: {auc_id} with SQN {sqn}", redisClient=self.redisMessaging) + return def Update_Serving_MME(self, imsi, serving_mme, serving_mme_realm=None, serving_mme_peer=None, serving_mme_timestamp=None, propagate=True): @@ -1626,7 +1636,7 @@ def Update_Serving_MME(self, imsi, serving_mme, serving_mme_realm=None, serving_ result.serving_mme_timestamp = None result.serving_mme_realm = None result.serving_mme_peer = None - serving_mme_timestamp_string = result.serving_mme_timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') if serving_mme_timestamp is not None else datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') + serving_mme_timestamp_string = datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') session.commit() objectData = self.GetObj(SUBSCRIBER, result.subscriber_id) @@ -1687,7 +1697,7 @@ def Update_Proxy_CSCF(self, imsi, proxy_cscf, pcscf_realm=None, pcscf_peer=None, result.pcscf_realm = None result.pcscf_peer = None result.pcscf_active_session = None - pcscf_timestamp_string = result.pcscf_timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') if pcscf_timestamp is not None else datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') + pcscf_timestamp_string = datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') session.commit() objectData = self.GetObj(IMS_SUBSCRIBER, result.ims_subscriber_id) @@ -1741,7 +1751,7 @@ def Update_Serving_CSCF(self, imsi, serving_cscf, scscf_realm=None, scscf_peer=N result.scscf_timestamp = None result.scscf_realm = None result.scscf_peer = None - scscf_timestamp_string = result.scscf_timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') if scscf_timestamp is not None else datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') + scscf_timestamp_string = datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') session.commit() objectData = self.GetObj(IMS_SUBSCRIBER, result.ims_subscriber_id) diff --git a/services/apiService.py b/services/apiService.py index bee3d1a..c889800 100644 --- a/services/apiService.py +++ b/services/apiService.py @@ -190,7 +190,9 @@ 'serving_pgw_timestamp' : "string", 'scscf' : "string", 'imei' : "string", - 'match_response_code' : "string" + 'match_response_code' : "string", + 'auc_id': "int", + 'sqn': "int", } @@ -1615,7 +1617,7 @@ def get(self, subscriber_routing): @ns_geored.route('/') class PyHSS_Geored(Resource): - @ns_geored.doc('Create ChargingRule Object') + @ns_geored.doc('Receive GeoRed data') @ns_geored.expect(GeoRed_model) @no_auth_required def patch(self): @@ -1708,6 +1710,17 @@ def patch(self): "geored_host": request.remote_addr, }, metricExpiry=60) + if 'auc_id' in json_data: + print("Updating AuC") + response_data.append(databaseClient.Update_AuC(json_data['auc_id'], json_data['sqn'], propagate=False)) + redisMessaging.sendMetric(serviceName='api', metricName='prom_flask_http_geored_endpoints', + metricType='counter', metricAction='inc', + metricValue=1.0, metricHelp='Number of Geored Pushes Received', + metricLabels={ + "endpoint": "SQN", + "geored_host": request.remote_addr, + }, + metricExpiry=60) return response_data, 200 except Exception as E: print("Exception when updating: " + str(E))