I am trying to perform a basic set command via a SNMP communication with the library pysnmp, My code is the following:
def snmp_set(self, oid, instance, value):
errorIndication, errorStatus, errorIndex, varBinds = self.cmdGen.setCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget((self.ip_address, 161)),
((oid+'.'+instance), rfc1902.Unsigned32(value))
)
# Check for errors and print out results
if errorIndication:
print(errorIndication)
else:
if errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1] or '?'
)
)
else:
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
I get the following as errormessage:
noAccess' at (ObjectName(1.3.6.1.4.1.5835.5.2.6000.1.1.1.1.5.0), Gauge32(1350))
When I try a get command on the same oid and same instance (0), everything works fine and I get the value than I want corresponding to my MIB.
So I don't understand why my set command does not work, I tried all the examples from http://pysnmp.sourceforge.net/, no one worked.
I tried to replace cmdgen.CommunityData('public')
with 'private'
instead of 'public'
, and then I get a 'genError'
error instead of 'noAccess'
.
I also tried to use cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1')
, but then I get a unknownUserName
message. For my get commands, I use cmdgen.CommunityData('public')
and it works fine.