Search code examples
pythonpython-3.xsnmppysnmp

pysnmp appending suffix to object identity


I'm trying to utlize the setCmd() method in pysnmp to set a variable. I'm having issues setting a specific object identify because it seems that pysnmp appends a ".0" to the object identity I want to set. Why is this happening?

The output I get is:

noSuchName at 1.3.6.1.4.1.2682.1.2.3.4.0

The content of the script is:

errorIndication, errorStatus, errorIndex, varBinds = next(
    setCmd(SnmpEngine(),
           CommunityData('dps_public', mpModel=0),
           UdpTransportTarget(('192.168.1.100', 161)),
           ContextData(),
           ObjectType(ObjectIdentity('1.3.6.1.4.1.2682.1.2.3.4'),
                      Integer(2)))
)

if errorIndication:
    print(errorIndication)
elif errorStatus:
    print('%s at %s' % (errorStatus.prettyPrint(),
                        errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
    for varBind in varBinds:
        print(' = '.join([x.prettyPrint() for x in varBind]))

Solution

  • I suspect you are getting this modified OID from your SNMP agent (which would be a violation of the protocol, I think). To the best of my knowledge, pysnmp should not mess with the OIDs that way.

    To verify you could either try your script against SNMP agent at demo.pysnmp.com and/or enable pysnmp debugging and see what's coming in PDU from the SNMP agent you are querying.

    from pysnmp import debug
    
    debug.setLogger(debug.Debug('msgproc'))
    
    ...