Skip to content

Commit

Permalink
Build SNMP command line args for SNMPv3
Browse files Browse the repository at this point in the history
This reworks the SNMP command line builder to include SNMPv3 parameters
as needed.
  • Loading branch information
lunkwill42 committed Nov 1, 2023
1 parent 5a515f2 commit 597f90c
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions python/nav/Snmp/pynetsnmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,25 @@ def _build_cmdline(self):
else:
host = 'udp6:[%s]' % self.host if address.version() == 6 else self.host

return (
'-v' + self.version,
'-c',
self.community,
'-r',
str(self.retries),
'-t',
str(self.timeout),
'%s:%s' % (host, self.port),
params = [f"-v{self.version}"]

if self.version in ("1", "2c"):
params.extend(["-c", self.community])
elif self.version == "3":
params.extend(["-l", self.sec_level.value, "-u", self.sec_name])
if self.auth_protocol:
params.extend(["-a", self.auth_protocol.value])
if self.auth_password:
params.extend(["-A", self.auth_password])
if self.priv_protocol:
params.extend(["-x", self.priv_protocol.value])
if self.priv_password:
params.extend(["-X", self.priv_password])

params.extend(
["-r", str(self.retries), "-t", str(self.timeout), f"{host}:{self.port}"]
)
return tuple(params)

def __del__(self):
self.handle.close()
Expand Down

0 comments on commit 597f90c

Please sign in to comment.