lextudio / pysnmp

Python SNMP library
https://www.pysnmp.com/pysnmp/
BSD 2-Clause "Simplified" License
77 stars 19 forks source link

Use bulk to get multi-mib_Objects with nonRepeaters, but got duplicate values. #111

Closed Leo05168 closed 6 days ago

Leo05168 commented 1 week ago

Expected behavior

$ snmpbulkget -v2c -c public -C n1 -C r2 demo.pysnmp.com 1.3.6.1.2.1.1.4 1.3.6.1.2.1.1.9.1.1 1.3.6.1.2.1.1.9.1.3
iso.3.6.1.2.1.1.4.0 = STRING: "admin@example.com"
iso.3.6.1.2.1.1.9.1.1.1 = INTEGER: 1
iso.3.6.1.2.1.1.9.1.1.2 = INTEGER: 2
iso.3.6.1.2.1.1.9.1.3.1 = STRING: "Test1"
iso.3.6.1.2.1.1.9.1.3.2 = STRING: "Test2"

Actual behavior

$ python3 test_v2c_bulk.py 
SNMPv2-MIB::sysContact.0 = admin@example.com
SNMPv2-MIB::sysORIndex.1 = 1
SNMPv2-MIB::sysORIndex.2 = 2
SNMPv2-MIB::sysContact.0 = admin@example.com
SNMPv2-MIB::sysORDescr.1 = Test1
SNMPv2-MIB::sysORDescr.2 = Test2

Detailed steps

This may not be a bug.

  1. Use this example test_v2c_bulk.py to fine-tune the code as follows. https://github.com/lextudio/pysnmp/blob/main/tests/hlapi/asyncio/manager/cmdgen/test_v2c_bulk.py
  2. Compare the results with snmpbulkget command.
  3. The value of "sysContact" appears repeatedly from test_v2c_bulk.py.
  4. Do users need to delete duplicate parts, right?

Python package information

pysnmp 7.0.3

Operating system information

Debian

Python information

python 3.12.5

(Optional) Contents of your test script

import asyncio

from pysnmp.hlapi.asyncio import Slim
from pysnmp.hlapi.v3arch.asyncio import *

async def test_v2c_bulk(mib_Objects):

    with Slim() as slim:
        errorIndication, errorStatus, errorIndex, varBinds = await slim.bulk(
            "public",
            "demo.pysnmp.com",
            161,
            1,
            2,
            *mib_Objects,
        )

        for varBind in varBinds:
            for x in varBind:
                print(x.prettyPrint())

mib_Objects = [
    ObjectType(ObjectIdentity("SNMPv2-MIB", "sysContact")),
    ObjectType(ObjectIdentity("SNMPv2-MIB", "sysORIndex")),
    ObjectType(ObjectIdentity("SNMPv2-MIB", "sysORDescr")),
]
asyncio.run(test_v2c_bulk(mib_Objects))

Relevant log output

No response

lextm commented 1 week ago

Confirmed that this is a bug in bulk, but it needs more time to fix as we have to reimplement bulkWalkCmd accordingly, which takes much longer and extensive testing.

lextm commented 6 days ago

Reimplemented walkCmd/bulkWalkCmd, and also changed nextCmd/bulkCmd to match.

This should break many apps but resolve the issue you reported. Anyway Ilya didn't design the original asyncio API very well, so this is unavoidable.

Shipped in release 7.1.1.