cancel
Showing results for 
Search instead for 
Did you mean: 

SNMPSet using Python

SNMPSet using Python

Garrett_Oswald
New Contributor
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
((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.

2 REPLIES 2

Dave_Hammers
Extreme Employee
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')))

Works great! Thanks for the help.
GTM-P2G8KFN