I can run this command from the command line:
snmpwalk -v3 -m +MY-MIB-ROOT -m +MY-MIB -l authPriv -u MYUSER -a SHA -A "XXXXXXXX" -x AES -X "XXXXXXXX" 1.2.3.4 .1.3.6.1.4.1.52330.6.1.2
I am trying to implement the same command in a python script using pysnmp:
import asyncio
from pysnmp.hlapi.v3arch.asyncio import *
from pysnmp.smi import builder, view, compiler
import logging
logging.basicConfig(level=logging.DEBUG)
# snmpwalk -v3 -m +MY-MIB-ROOT -m +MY-MIB -l authPriv -u MYUSER -a SHA -A "XXXXXXXX" -x AES -X "XXXXXXXX" 1.2.3.4 .1.3.6.1.4.1.52330.6.1.2
# Load MIBs
mibBuilder = builder.MibBuilder()
compiler.addMibCompiler(mibBuilder, sources=['file:///usr/share/snmp/mibs'])
mibViewController = view.MibViewController(mibBuilder)
loadedModules = mibBuilder.mibSymbols.keys()
print("loadedModules:", loadedModules)
async def run(varBinds):
snmpEngine = SnmpEngine()
while True:
print("A")
errorIndication, errorStatus, errorIndex, varBindTable = await bulkCmd(
snmpEngine,
UsmUserData(
'MYUSER',
'XXXXXXXX',
'XXXXXXXX',
authProtocol=usmHMACSHAAuthProtocol,
privProtocol=usmAesCfb128Protocol,
),
await UdpTransportTarget.create(('1.2.3.4', 161)),
ContextData(),
0,
50,
*varBinds
)
if errorIndication:
print(errorIndication)
break
elif errorStatus:
print(
f"{errorStatus.prettyPrint()} at {varBinds[int(errorIndex) - 1][0] if errorIndex else '?'}"
)
else:
for varBind in varBindTable:
oid = varBind.__getitem__(0)
print(oid)
varBinds = varBindTable
if isEndOfMib(varBinds):
break
return
asyncio.run(
run([ObjectType(ObjectIdentity('1.3.6.1.4.1.52330.6.1.2'))])
)
I get this error:
Ciphering services not available
I am running the script within a virtual environment on Red Hat Enterprise Linux release 9.4 (Plow)
$ pip list
Package Version
------------------ ---------
certifi 2024.8.30
charset-normalizer 3.3.2
idna 3.10
Jinja2 3.1.4
MarkupSafe 2.1.5
pip 24.2
ply 3.11
pyasn1 0.6.1
pycryptodomex 3.20.0
pysmi 1.5.0
pysnmp 7.1.4
requests 2.32.3
setuptools 53.0.0
urllib3 2.2.3
If anyone else comes across this issue, the latest release makes use of the cryptography package so it worked after I installed that:
pip install cryptography
This was version 43.0.1 at time of writing.
pycryptodomex can be removed