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 e3473b6 commit a8a3e4b
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(

Check warning on line 169 in python/nav/models/manage.py

View check run for this annotation

Codecov / codecov/patch

python/nav/models/manage.py#L169

Added line #L169 was not covered by tests
"Broken management profile %s has no SNMP version", self.name
)
return None

Check warning on line 172 in python/nav/models/manage.py

View check run for this annotation

Codecov / codecov/patch

python/nav/models/manage.py#L172

Added line #L172 was not covered by tests

elif self.protocol == self.PROTOCOL_SNMPV3:
return 3

Expand Down

0 comments on commit a8a3e4b

Please sign in to comment.