SNMPSet using Python

  • 0
  • 1
  • Problem
  • Updated 4 years ago
  • Solved
I'm having trouble setting an interface alias on a K-10 using Python's pysnmp set command.

interfaceName = '1.3.6.1.2.1.31.1.1.1.1.12001'  #mib for specific interface name
interfaceAlias = '1.3.6.1.2.1.31.1.1.1.18.12001'  #mib for specific interface alias

My snmp get command works just fine:

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
    cmdgen.UsmUserData(user,auth,priv),
    cmdgen.UdpTransportTarget(('10.18.152.51', 161)),
    interfaceName,
    interfaceAlias)

However, when I try to run the following code the compiler complains about the last line:

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
    cmdgen.UsmUserData (user,auth,priv),
    cmdgen.UdpTransportTarget (('10.18.152.51', 161)),
    ((interfaceAlias, 'testsetalias')))

Here is the error I'm getting:

Traceback (most recent call last):  File "getStub.py", line 28, in <module>
    ((interfaceAlias, 'testsetalias')))
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 399, in setCmd
    authData, transportTarget, varBinds, (__cbFun, appReturn)
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 307, in setCmd
    self.mibViewController, name + oid
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/mibvar.py", line 58, in oidToMibName
    (oid, mibNode.name)
pysnmp.smi.error.NoSuchObjectError: NoSuchObjectError({'str': 'No MIB info for (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 12001) (closest parent (1, 3, 6, 1, 2, 1))'})

Any help would be much appreciated.
Photo of Garrett Oswald

Garrett Oswald

  • 104 Points 100 badge 2x thumb

Posted 4 years ago

  • 0
  • 1
Photo of Dave Hammers

Dave Hammers, Dir SW Engineering

  • 3,802 Points 3k badge 2x thumb
Official Response
I used http://pysnmp.sourceforge.net/examples/current/v3arch/oneliner/manager/cmdgen/set-v1-multiple-values... as a reference.

Add this if you don't already have it:

from pysnmp.proto import rfc1902

Try changing your last line from:
((interfaceAlias, 'testsetalias')))
to
(interfaceAlias, rfc1902.OctetString('testsetalias')))