Skip to content

Commit

Permalink
Merge pull request #2748 from Uninett/feature/snmpv3-navoidverify
Browse files Browse the repository at this point in the history
Make `navoidverify` and `naventity` commands SNMPv3 compatible
  • Loading branch information
lunkwill42 authored Nov 20, 2023
2 parents 1303115 + 6f11f95 commit f8ba9aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
17 changes: 4 additions & 13 deletions bin/naventity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
20 changes: 5 additions & 15 deletions bin/navoidverify
Original file line number Diff line number Diff line change
Expand Up @@ -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).
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f8ba9aa

Please sign in to comment.