From a8a3e4bc03bf62f260fa1dda93a7f7723d60ab85 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Mon, 20 Nov 2023 11:22:41 +0100 Subject: [PATCH] Protect against faulty SNMP profiles ManagementProfile.snmp_version now avoids crashing in the case of faulty SNMP profiles. Since it was used to sort multiple profiles in order of SNMP version while fetching preferred profiles, the presence of any faulty profile on a Netbox would make `get_preferred_snmp_profile()` unable to fetch any valid profile without crashing. This was discovered by our test suite. --- python/nav/models/manage.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/python/nav/models/manage.py b/python/nav/models/manage.py index 3aa6b748bf..2d5c3492ce 100644 --- a/python/nav/models/manage.py +++ b/python/nav/models/manage.py @@ -160,10 +160,17 @@ def is_snmp(self): def snmp_version(self): """Returns the configured SNMP version as an integer""" if self.protocol == self.PROTOCOL_SNMP: - value = self.configuration['version'] + value = self.configuration.get("version") if value == "2c": return 2 - return int(value) + if value: + return int(value) + else: + _logger.error( + "Broken management profile %s has no SNMP version", self.name + ) + return None + elif self.protocol == self.PROTOCOL_SNMPV3: return 3