Skip to content

Commit

Permalink
Bump the pysnmp version for py3.12 (#18245)
Browse files Browse the repository at this point in the history
* bump pysnmp to fix integration tests for py3.12

* Set ignoreErrors to False from pysnmp's unmakeVarbinds fn

* add changelog

* Refactor to function with comment on reason for posterity

* change to fix changelog

---------

Co-authored-by: zoe ✨ <[email protected]>
  • Loading branch information
Kyle-Neale and zoedt authored Aug 22, 2024
1 parent aaf2432 commit 0cf0d84
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion agent_requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pyopenssl==24.2.1; python_version > '3.0'
pysmi==0.3.4; python_version < '3.0'
pysmi==1.4.4; python_version > '3.0'
pysnmp-mibs==0.1.6
pysnmp==4.4.9
pysnmp==4.4.10
pysocks==1.7.1
python-binary-memcached==0.26.1; sys_platform != 'win32' and python_version < '3.0'
python-binary-memcached==0.31.2; sys_platform != 'win32' and python_version > '3.0'
Expand Down
1 change: 1 addition & 0 deletions snmp/changelog.d/18245.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump pysnmp version to 4.9.10
18 changes: 15 additions & 3 deletions snmp/datadog_checks/snmp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pysnmp.hlapi.asyncore.cmdgen import vbProcessor
from pysnmp.proto import errind
from pysnmp.proto.rfc1905 import endOfMibView
from pysnmp.smi.rfc1902 import ObjectIdentity, ObjectType

from datadog_checks.base.errors import CheckException

Expand All @@ -33,13 +34,12 @@ def snmp_get(config, oids, lookup_mib):
def callback( # type: ignore
snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx
):
var_binds = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookup_mib)
newVarBinds = unmakeVarbinds(snmpEngine, varBinds, lookup_mib)

cbCtx['error'] = errorIndication
cbCtx['var_binds'] = var_binds
cbCtx['var_binds'] = newVarBinds

ctx = {} # type: Dict[str, Any]

var_binds = vbProcessor.makeVarBinds(config._snmp_engine, oids)

cmdgen.GetCommandGenerator().sendVarBinds(
Expand Down Expand Up @@ -160,3 +160,15 @@ def callback( # type: ignore
yield var_binds[0]
else:
return


def unmakeVarbinds(snmpEngine, varBinds, lookupMib=True):
"""Taken from pysnmp's varbinds.py, amended to not ignore the errors that return when resolving the MIB."""
if lookupMib:
mibViewController = vbProcessor.getMibViewController(snmpEngine)
varBinds = [
ObjectType(ObjectIdentity(x[0]), x[1]).resolveWithMib(mibViewController, ignoreErrors=False)
for x in varBinds
]

return varBinds
2 changes: 1 addition & 1 deletion snmp/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ deps = [
"pysmi==0.3.4; python_version < '3.0'",
"pysmi==1.4.4; python_version > '3.0'",
"pysnmp-mibs==0.1.6",
"pysnmp==4.4.9",
"pysnmp==4.4.10",
]

[project.urls]
Expand Down

0 comments on commit 0cf0d84

Please sign in to comment.