0

According to the documentation the setCmd varBinds reference is a sequence of managed objects. However, I have tried to pass a list [(oid0, value0), (oid1, value1)] or a tuple ((oid0, value0), (oid1, value1)) or a set set([(oid0, value0), (oid1, value1)]) and all of them fail with the error "too many values to unpack". I need to be able send a single set request with multiple varbinds.I can successfully send each managed object, e.g., (oid0, value0) as a separate setCmd. Any ideas how I can do this?

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
scriptOmate
  • 57
  • 1
  • 2
  • 7
  • I found an extremely inconvenient way to do this. I basically had to produce a string of managed objects and use eval() on it. That is the set command looks like this: – scriptOmate Nov 12 '12 at 23:20
  • # abc = [(oid0, value0), (oid1, value1), (oid2, value2)] mo_str = '' for each in abc: mo_str = str(each) + ',' errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().setCmd( self.authData, cmdgen.UdpTransportTarget((host_addr, 161)), eval(mo_str[:-1]) ) This is extremely inconvenient programatically. – scriptOmate Nov 12 '12 at 23:34
  • Use net-snmp and a shell call, `pysnmp` has a rather convoluted API for what should be simple things – Mike Pennington Nov 13 '12 at 13:21

2 Answers2

1

As shown on the examples page, passing a variable number of (oid, value) tuples to the setCmd() is a way to add multiple var-binds to request message.

The following code will build and send SNMP SET message with three var-binds:

cmdGen.setCmd(
    cmdgen.CommunityData('public'),
    cmdgen.UdpTransportTarget(('localhost', 161)),
    ('1.3.6.1.2.1.1.2.0', rfc1902.ObjectName('1.3.6.1.4.1.20408.1.1')),
    ('1.3.6.1.2.1.1.2.0', '1.3.6.1.4.1.20408.1.1'),
    ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('new system name'))
)
Pooh
  • 244
  • 1
  • 2
  • I know what the example says, but as I stated, there is no way to provide give a variable in that form. The example is great for fixed values as above, but try to do it with setting a variable as the multiple varbinds. It doesn't work. – scriptOmate Nov 15 '12 at 03:55
1

Try asterisk

abc = ((oid0, value0), (oid1, value1), (oid2, value2))
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().setCmd(
    self.authData, cmdgen.UdpTransportTarget((host_addr, 161)), *abc)
Petr
  • 11
  • 1