Skip to content

Commit

Permalink
Protect against faulty SNMP profiles
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lunkwill42 committed Nov 20, 2023
1 parent ca39921 commit cab6497
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions python/nav/models/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cab6497

Please sign in to comment.