From 5b4e8d48b6dc3078a018530b9063d0f63d54093d Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Fri, 1 Dec 2023 11:40:51 +0100 Subject: [PATCH 1/3] Ensure AgentProxy.snmpVersion is prefixed by `v` If the `snmpVersion` argument to `AgentProxy` is not a version string prefixed by the letter `v`, `AgentProxy` will silently default to `v2c`. Using `2c` as a value works, since it defaults then to `v2c`. Using `3` also seems to work, as providing further SNMPv3 configuration arguments to the Net-SNMP library seems to automatically set the session version to `v3`, regardless of the version parameter. However, using `1` will not work, as that will also silently default the session to `v2c`, making SNMPv1 communication impossible. --- python/nav/ipdevpoll/snmp/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/nav/ipdevpoll/snmp/common.py b/python/nav/ipdevpoll/snmp/common.py index b17447e1cb..21a3f2b10c 100644 --- a/python/nav/ipdevpoll/snmp/common.py +++ b/python/nav/ipdevpoll/snmp/common.py @@ -240,7 +240,7 @@ def as_agentproxy_args(self) -> Dict[str, Any]: """Returns the SNMP session parameters in a dict format compatible with pynetsnmp.twistedsnmp.AgentProxy() keyword arguments. """ - kwargs = {"snmpVersion": self.version_string} + kwargs = {"snmpVersion": f"v{self.version_string}"} if self.version in (1, 2): kwargs["community"] = self.community if self.timeout: From afb047de5b4ba77242d328b4b7ba72720c8ddc35 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Fri, 1 Dec 2023 11:57:15 +0100 Subject: [PATCH 2/3] Update SNMPParameters tests Now need to test that the version argument is actually prefixed by `v` --- tests/unittests/ipdevpoll/snmp/common_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/ipdevpoll/snmp/common_test.py b/tests/unittests/ipdevpoll/snmp/common_test.py index 6b34caffd7..dc7558b729 100644 --- a/tests/unittests/ipdevpoll/snmp/common_test.py +++ b/tests/unittests/ipdevpoll/snmp/common_test.py @@ -31,7 +31,7 @@ def test_should_contain_cmdline_args(self, snmpv3_params): def test_should_contain_version_argument(self, snmpv3_params): kwargs = snmpv3_params.as_agentproxy_args() - assert kwargs.get("snmpVersion") == "3" + assert kwargs.get("snmpVersion") == "v3" def test_should_contain_sec_level_cmdline_argument(self, snmpv3_params): kwargs = snmpv3_params.as_agentproxy_args() From c679e56efcaa7805b60cf77143b13a4ccca60616 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Fri, 1 Dec 2023 12:02:41 +0100 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b03a4665..4428768288 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This changelog format was introduced in NAV 5.4.0. Older changelogs can be found in the [HISTORY](HISTORY) file. +## [Unreleased] + +### Fixed + +- Fix non-working SNMPv1 communication ([#2772](https://github.com/Uninett/nav/issues/2772), [#2779](https://github.com/Uninett/nav/issues/2779), [#2780](https://github.com/Uninett/nav/pull/2780)) + ## [5.8.2] - 2023-11-30 ### Fixed