2

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.

FooF
  • 4,323
  • 2
  • 31
  • 47
  • You are using pysnmp for sending SET commands (not serving them)? Have you successfully tried SNMP set on the same OID using different SNMP manager software (for example the commands from the open source netsnmp)? What I am after is, are you absolutely sure the OID is writeable on the SNMP agent? – FooF Jun 05 '15 at 09:59
  • Thanks for your answer, yes I use another manager software and I can succesfully perform set commands on the same oid than I tried in my python example. The oid is writeable – Martin Raymond Jun 05 '15 at 10:19
  • But my purpose is to use the pysnmp library – Martin Raymond Jun 05 '15 at 12:34
  • Of course. The point of trying another management software was just to clarify where the problem is; as the object is settable using another SNMP manager software the problem more strongly seems to be with the `pysnmp` client code. I am not personally familiar with pysnmp, but I am thinking that maybe you could try capturing the network packets using both pysnmp and the other software, and compare the results. This could provide hint about what is happening differently. – FooF Jun 05 '15 at 12:42
  • 1
    Thanks for your suggestion, I did what you suggested and I found the problem. When you perform a set command, the community value is set to private, so I just add to change the community to `private` in python. The exception 'genError' I got when I did that earlier was due to the format of the `value` variable, nothing related to snmp. Thanks for your help ! – Martin Raymond Jun 05 '15 at 13:10
  • Nice to hear you managed to solve your problem. You could answer your own question, noting how you (found and) solved the problem (and what other things might be worth checking). This could be useful for others facing a similar problem who end up here for example via internet search. You can even accept your own answer (if better answers come along, you can always tag another answer acceptable if it answers the problem more thoroughly). – FooF Jun 08 '15 at 02:30

0 Answers0