From 7f4feb8c705da937a0b1b5d952096e2d3ee166a6 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Fri, 17 Nov 2023 10:49:10 +0100 Subject: [PATCH 1/2] Make navoidverify SNMPv3 compatible This gets the SNMP parameters for the AgentProxy constructor from the new library functions from ipdevpoll, ensuring compatibility with SNMPv3. --- bin/navoidverify | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/bin/navoidverify b/bin/navoidverify index 45a700275e..3268c11a11 100755 --- a/bin/navoidverify +++ b/bin/navoidverify @@ -2,6 +2,7 @@ # -*- testargs: .1.3.6.1.2.1.1.2 -*- # # Copyright (C) 2014 Uninett AS +# Copyright (C) 2023 Sikt # # This file is part of Network Administration Visualized (NAV). # @@ -36,7 +37,7 @@ if platform.system() == "Linux": install() -from nav.ipdevpoll.snmp.common import snmp_parameter_factory, SnmpError +from nav.ipdevpoll.snmp.common import SNMPParameters, SnmpError from nav.models.manage import Netbox, ManagementProfile from nav.ipdevpoll.snmp import snmpprotocol, AgentProxy from nav.oids import OID @@ -124,23 +125,12 @@ _ports = cycle([snmpprotocol.port() for _ in range(50)]) def _create_agentproxy(netbox): - profile = netbox.get_preferred_snmp_management_profile(writeable=False) - if ( - not profile - or not hasattr(profile, "snmp_community") - or not hasattr(profile, "snmp_version") - ): + params = SNMPParameters.factory(netbox) + if not params: return port = next(_ports) - agent = AgentProxy( - netbox.ip, - 161, - community=profile.snmp_community, - snmpVersion='v%s' % profile.snmp_version, - protocol=port.protocol, - snmp_parameters=snmp_parameter_factory(netbox), - ) + agent = AgentProxy(netbox.ip, 161, protocol=port.protocol, snmp_parameters=params) try: agent.open() except SnmpError: From 6f11f95263ea4cf2e146bf3190fcd83c9c1e92e3 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Fri, 17 Nov 2023 10:55:45 +0100 Subject: [PATCH 2/2] Make naventity SNMPv3 compatible This gets the SNMP parameters for the AgentProxy constructor from the new library functions from ipdevpoll, ensuring compatibility with SNMPv3. --- bin/naventity | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/bin/naventity b/bin/naventity index 4ac5036af6..935f8462c1 100755 --- a/bin/naventity +++ b/bin/naventity @@ -33,7 +33,7 @@ from nav.bootstrap import bootstrap_django bootstrap_django(__file__) from nav.util import is_valid_ip -from nav.ipdevpoll.snmp.common import snmp_parameter_factory, SnmpError +from nav.ipdevpoll.snmp.common import snmp_parameter_factory, SnmpError, SNMPParameters from nav.ipdevpoll.snmp import AgentProxy, snmpprotocol from nav.mibs.entity_mib import EntityMib from nav.models.manage import Netbox @@ -172,22 +172,13 @@ def device(devicestring): def _create_agentproxy(netbox, portnumber): - profile = netbox.get_preferred_snmp_management_profile(writeable=False) - if ( - not profile - or not hasattr(profile, "snmp_community") - or not hasattr(profile, "snmp_version") - ): + params = SNMPParameters.factory(netbox) + if not params: return port = snmpprotocol.port() agent = AgentProxy( - netbox.ip, - portnumber, - community=profile.snmp_community, - snmpVersion='v%s' % profile.snmp_version, - protocol=port.protocol, - snmp_parameters=snmp_parameter_factory(netbox), + netbox.ip, portnumber, protocol=port.protocol, snmp_parameters=params ) try: agent.open()