From b257f451ae281c32fb850f3848d3b8b99d9b4d4d Mon Sep 17 00:00:00 2001 From: davidkneipp Date: Wed, 11 Oct 2023 20:10:13 +1000 Subject: [PATCH] Reduce verbosity of failed lookup --- CHANGELOG.md | 9 ++++++++- lib/diameter.py | 35 ++++++++++++++++------------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2879763..0d1dd4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to PyHSS are documented in this file, beginning from [Servic The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.1] - Unreleased + +### Changed + +- Reduced verbosity of failing subscriber lookups to debug + + ## [1.0.0] - 2023-09-27 ### Added @@ -45,4 +52,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Multithreading in all services, except for metricService -[1.0.0]: https://github.com/nickvsnetworking/pyhss/releases/tag/v1.0.0 \ No newline at end of file +[1.0.0]: https://github.com/nickvsnetworking/pyhss/releases/tag/1.0.0 \ No newline at end of file diff --git a/lib/diameter.py b/lib/diameter.py index 4692925..a07f669 100644 --- a/lib/diameter.py +++ b/lib/diameter.py @@ -1183,12 +1183,12 @@ def Answer_16777251_316(self, packet_vars, avps): return response except ValueError as e: - self.logTool.log(service='HSS', level='info', message="failed to get data backfrom database for imsi " + str(imsi), redisClient=self.redisMessaging) - self.logTool.log(service='HSS', level='info', message="Error is " + str(e), redisClient=self.redisMessaging) - self.logTool.log(service='HSS', level='info', message="Responding with DIAMETER_ERROR_USER_UNKNOWN", redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="failed to get data backfrom database for imsi " + str(imsi), redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Error is " + str(e), redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Responding with DIAMETER_ERROR_USER_UNKNOWN", redisClient=self.redisMessaging) avp += self.generate_avp(268, 40, self.int_to_hex(5030, 4)) response = self.generate_diameter_packet("01", "40", 316, 16777251, packet_vars['hop-by-hop-identifier'], packet_vars['end-to-end-identifier'], avp) #Generate Diameter packet - self.logTool.log(service='HSS', level='info', message="Diameter user unknown - Sending ULA with DIAMETER_ERROR_USER_UNKNOWN", redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Diameter user unknown - Sending ULA with DIAMETER_ERROR_USER_UNKNOWN", redisClient=self.redisMessaging) return response except Exception as ex: template = "An exception of type {0} occurred. Arguments:\n{1!r}" @@ -1745,7 +1745,6 @@ def Answer_16777238_272(self, packet_vars, avps): except Exception as e: #Get subscriber details #Handle if the subscriber is not present in HSS return "DIAMETER_ERROR_USER_UNKNOWN" self.logTool.log(service='HSS', level='debug', message="[diameter.py] [Answer_16777238_272] [CCA] Subscriber " + str(imsi) + " unknown in HSS for CCR", redisClient=self.redisMessaging) - self.logTool.log(service='HSS', level='debug', message=traceback.format_exc(), redisClient=self.redisMessaging) self.redisMessaging.sendMetric(serviceName='diameter', metricName='prom_diam_auth_event_count', metricType='counter', metricAction='inc', @@ -1797,8 +1796,8 @@ def Answer_16777216_300(self, packet_vars, avps): self.logTool.log(service='HSS', level='debug', message="Extracted imsi: " + str(imsi) + " now checking backend for this IMSI", redisClient=self.redisMessaging) ims_subscriber_details = self.database.Get_IMS_Subscriber(imsi=imsi) except Exception as E: - self.logTool.log(service='HSS', level='error', message="Threw Exception: " + str(E), redisClient=self.redisMessaging) - self.logTool.log(service='HSS', level='error', message="No known MSISDN or IMSI in Answer_16777216_300() input", redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Threw Exception: " + str(E), redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message=f"No known MSISDN or IMSI in Answer_16777216_300()", redisClient=self.redisMessaging) self.redisMessaging.sendMetric(serviceName='diameter', metricName='prom_diam_auth_event_count', metricType='counter', metricAction='inc', metricValue=1.0, @@ -1897,8 +1896,8 @@ def Answer_16777216_301(self, packet_vars, avps): imsi = ims_subscriber_details['imsi'] domain = "ims.mnc" + str(self.MNC).zfill(3) + ".mcc" + str(self.MCC).zfill(3) + ".3gppnetwork.org" except Exception as E: - self.logTool.log(service='HSS', level='error', message="Threw Exception: " + str(E), redisClient=self.redisMessaging) - self.logTool.log(service='HSS', level='error', message="No known MSISDN or IMSI in Answer_16777216_301() input", redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Threw Exception: " + str(E), redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message=f"No known MSISDN or IMSI in Answer_16777216_301()", redisClient=self.redisMessaging) result_code = 5005 #Experimental Result AVP avp_experimental_result = '' @@ -1958,8 +1957,6 @@ def Answer_16777216_302(self, packet_vars, avps): avp += self.generate_avp(277, 40, "00000001") #Auth Session State avp += self.generate_avp(260, 40, "0000010a4000000c000028af000001024000000c01000000") #Vendor-Specific-Application-ID for Cx - - try: self.logTool.log(service='HSS', level='debug', message="Checking if username present", redisClient=self.redisMessaging) username = self.get_avp_data(avps, 601)[0] @@ -1982,8 +1979,8 @@ def Answer_16777216_302(self, packet_vars, avps): avp += self.generate_vendor_avp(602, "c0", 10415, str(binascii.hexlify(str.encode("sip:scscf.ims.mnc" + str(self.MNC).zfill(3) + ".mcc" + str(self.MCC).zfill(3) + ".3gppnetwork.org")),'ascii')) self.logTool.log(service='HSS', level='debug', message="Using generated iFC", redisClient=self.redisMessaging) except Exception as E: - self.logTool.log(service='HSS', level='error', message="Threw Exception: " + str(E), redisClient=self.redisMessaging) - self.logTool.log(service='HSS', level='error', message="No known MSISDN or IMSI in Answer_16777216_302() input", redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Threw Exception: " + str(E), redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message=f"No known MSISDN or IMSI in Answer_16777216_302()", redisClient=self.redisMessaging) result_code = 5001 self.redisMessaging.sendMetric(serviceName='diameter', metricName='prom_diam_auth_event_count', metricType='counter', metricAction='inc', @@ -2749,12 +2746,12 @@ def Answer_16777291_8388622(self, packet_vars, avps): subscriber_details = self.database.Get_Subscriber(msisdn=msisdn) self.logTool.log(service='HSS', level='debug', message="Got subscriber_details from MSISDN: " + str(subscriber_details), redisClient=self.redisMessaging) except Exception as E: - self.logTool.log(service='HSS', level='info', message="No MSISDN or IMSI returned in Answer_16777291_8388622 input", redisClient=self.redisMessaging) - self.logTool.log(service='HSS', level='info', message="Error is " + str(E), redisClient=self.redisMessaging) - self.logTool.log(service='HSS', level='info', message="Responding with DIAMETER_ERROR_USER_UNKNOWN", redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="No MSISDN or IMSI returned in Answer_16777291_8388622 input", redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Error is " + str(E), redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Responding with DIAMETER_ERROR_USER_UNKNOWN", redisClient=self.redisMessaging) avp += self.generate_avp(268, 40, self.int_to_hex(5030, 4)) response = self.generate_diameter_packet("01", "40", 8388622, 16777291, packet_vars['hop-by-hop-identifier'], packet_vars['end-to-end-identifier'], avp) #Generate Diameter packet - self.logTool.log(service='HSS', level='info', message="Diameter user unknown - Sending ULA with DIAMETER_ERROR_USER_UNKNOWN", redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Diameter user unknown - Sending ULA with DIAMETER_ERROR_USER_UNKNOWN", redisClient=self.redisMessaging) return response @@ -2999,8 +2996,8 @@ def Request_16777251_319(self, packet_vars, avps, **kwargs): try: subscriber_details = self.database.Get_Subscriber(imsi=imsi) #Get subscriber details except ValueError as e: - self.logTool.log(service='HSS', level='error', message="failed to get data backfrom database for imsi " + str(imsi), redisClient=self.redisMessaging) - self.logTool.log(service='HSS', level='error', message="Error is " + str(e), redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="failed to get data backfrom database for imsi " + str(imsi), redisClient=self.redisMessaging) + self.logTool.log(service='HSS', level='debug', message="Error is " + str(e), redisClient=self.redisMessaging) raise except Exception as ex: template = "An exception of type {0} occurred. Arguments:\n{1!r}"