Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reponse to multi-variable get has duplicated values #152

Open
wfaulk opened this issue Nov 22, 2024 · 3 comments
Open

reponse to multi-variable get has duplicated values #152

wfaulk opened this issue Nov 22, 2024 · 3 comments
Labels
bug Something isn't working priority:low Low priority items. triage New issues that need to be sorted out.

Comments

@wfaulk
Copy link

wfaulk commented Nov 22, 2024

Expected behavior

I issued a get_cmd() with multiple variables in the same MIB table. I expect to get back multiple responses, each with the appropriate value.

Actual behavior

If a get_cmd() is issued with multiple requested variables in the same MIB table, the value of one of the elements of the table is duplicated to all of the other elements of the table.

Detailed steps

Testing against the simulation service, here's the result of a command-line snmpget command:

% snmpget -v 2c -c public demo.pysnmp.com IF-MIB::ifInOctets.1 IF-MIB::ifInOctets.2 IF-MIB::ifSpeed.1 IF-MIB::ifSpeed.2 IF-MIB::ifOutOctets.1 IF-MIB::ifOutOctets.2 IF-MIB::ifOutUcastPkts.1 IF-MIB::ifOutUcastPkts.2 IF-MIB::ifDescr.1 IF-MIB::ifDescr.2
IF-MIB::ifInOctets.1 = Counter32: 25611194
IF-MIB::ifInOctets.2 = Counter32: 2570427550
IF-MIB::ifSpeed.1 = Gauge32: 4294967295
IF-MIB::ifSpeed.2 = Gauge32: 2755359744
IF-MIB::ifOutOctets.1 = Counter32: 25611194
IF-MIB::ifOutOctets.2 = Counter32: 3256639591
IF-MIB::ifOutUcastPkts.1 = Counter32: 135187
IF-MIB::ifOutUcastPkts.2 = Counter32: 14916803
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0

Using the pysnmp script included below:

% ./demo.py
IF-MIB::ifInOctets.1 = 2570504176
IF-MIB::ifInOctets.2 = 2570504176
IF-MIB::ifSpeed.1 = 2755359744
IF-MIB::ifSpeed.2 = 2755359744
IF-MIB::ifOutOctets.1 = 3256802074
IF-MIB::ifOutOctets.2 = 3256802074
IF-MIB::ifOutUcastPkts.1 = 14917406
IF-MIB::ifOutUcastPkts.2 = 14917406
IF-MIB::ifDescr.1 = eth0
IF-MIB::ifDescr.2 = eth0

A network packet capture shows that the request and response over the network is correct.

Enabling debug logging in the script didn't seem to reveal anything useful to me.

Python package information

7.1.13

Operating system information

macOS 13.7.1

Python information

Python 3.13.0

(Optional) Contents of your test script

#!/usr/bin/env python3

import asyncio

from pysnmp.hlapi.v3arch.asyncio import *

async def main():
    se = SnmpEngine()
    comm = CommunityData('public')
    target = await UdpTransportTarget.create(('demo.pysnmp.com', 161))
    context = ContextData()

    netiftable = [ ObjectIdentity('IF-MIB', 'ifInOctets', 1),
                   ObjectIdentity('IF-MIB', 'ifInOctets', 2),
                   ObjectIdentity('IF-MIB', 'ifSpeed', 1),
                   ObjectIdentity('IF-MIB', 'ifSpeed', 2),
                   ObjectIdentity('IF-MIB', 'ifOutOctets', 1),
                   ObjectIdentity('IF-MIB', 'ifOutOctets', 2),
                   ObjectIdentity('IF-MIB', 'ifOutUcastPkts', 1),
                   ObjectIdentity('IF-MIB', 'ifOutUcastPkts', 2),
                   ObjectIdentity('IF-MIB', 'ifDescr', 1),
                   ObjectIdentity('IF-MIB', 'ifDescr', 2) ]
    _, _, _, objects = await get_cmd(se, comm, target, context,
               *[ObjectType(x) for x in netiftable])
    for item in objects:
        print(item)

asyncio.run(main())

Relevant log output

No response

@wfaulk wfaulk added bug Something isn't working triage New issues that need to be sorted out. labels Nov 22, 2024
@lextudio-support lextudio-support added the priority:low Low priority items. label Nov 22, 2024
@lextudio-support
Copy link

New issues are marked as low priority by default. Becoming our commercial customers, and then your reports are handled with higher priority after triage.

@wfaulk
Copy link
Author

wfaulk commented Nov 22, 2024

I've also discovered that this same problem exists even if you query the variables in different calls, unless the calls use distinct SnmpEngine() values.

And if you query the same variable multiple times with the same SnmpEngine(), any record you tried to keep of the old value is overwritten with the new one.

Here's an example of this:

#!/usr/bin/env python3

import asyncio

from pysnmp.hlapi.v3arch.asyncio import *

async def main():
    se = SnmpEngine()
    comm = CommunityData('public')
    target = await UdpTransportTarget.create(('demo.pysnmp.com', 161))
    context = ContextData()

    answers = []

    _, _, _, objects = await get_cmd(se, comm, target, context,
                   ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 2)))
    for item in objects:
        print(item)
        answers.append(item)

    await asyncio.sleep(15)

    _, _, _, objects = await get_cmd(se, comm, target, context,
                   ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 2)))
    for item in objects:
        print(item)
        answers.append(item)

    print(answers[0])
    print(answers[1])

asyncio.run(main())

And the output of this looks like:

% ./demo2.py
IF-MIB::ifInOctets.2 = 2586939406
IF-MIB::ifInOctets.2 = 2586952536
IF-MIB::ifInOctets.2 = 2586952536
IF-MIB::ifInOctets.2 = 2586952536

@ojnas
Copy link

ojnas commented Nov 24, 2024

Walk operations (walk_cmd and bulk_walk_cmd) are broken in the same way. Same value for all rows of a table in the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:low Low priority items. triage New issues that need to be sorted out.
Projects
None yet
Development

No branches or pull requests

3 participants