2

I'm configure community and try to use setValue in pysnmp but it not to work:

...

config.addV1System(snmpEngine, 'read-area', 'public')
config.addV1System(snmpEngine, 'write-area', 'private')
config.addVacmUser(snmpEngine, 2, 'read-area', 'noAuthNoPriv', (1, 3, 6, 5))
config.addVacmUser(snmpEngine, 2, 'write-area', 'noAuthNoPriv', (1, 3, 6, 5, 1, 0), (1, 3, 6, 5, 1, 0))

...

class MyStaticMibScalarInstance1(MibScalarInstance):
    def getValue(self, name, idx):
        return self.getSyntax().clone('111')
    def setValue(self, value, name, idx):
        print("111 %s %s %s\n".format(value, name, idx))

mibBuilder.exportSymbols('__MY_MIB', MibScalar((1, 3, 6, 5, 1), v2c.OctetString()), MyStaticMibScalarInstance1((1, 3, 6, 5, 1), (0,), v2c.OctetString()))

...

Test case:

$ snmpwalk -v 2c -c public 127.0.0.1 1.3.6.5
    iso.3.6.5.1.0 = STRING: "111"
    iso.3.6.5.2.0 = No more variables left in this MIB View (It is past the end of the MIB tree)

$ snmpset -v 2c -c private 127.0.0.1 1.3.6.5.1.0 s test
    Error in packet. Reason: notWritable (That object does not support modification)
    Failed object: iso.3.6.5.1.0

How i can to enable private community and make setValue to work?

1 Answers1

1

Besides VACM setup (which works on per-user/community basis), you also need to indicate that the managed object is writable in principle:

mibBuilder.exportSymbols(
    '__MY_MIB',
    MibScalar((1, 3, 6, 5, 1), v2c.OctetString()).setMaxAccess('readwrite'),
    MyStaticMibScalarInstance1((1, 3, 6, 5, 1), (0,), v2c.OctetString())
)

Alternatively:

class ManagedObject(MibScalar):
    maxAccess = 'readwrite'

mibBuilder.exportSymbols(
    '__MY_MIB',
    ManagedObject((1, 3, 6, 5, 1), v2c.OctetString()),
    MyStaticMibScalarInstance1((1, 3, 6, 5, 1), (0,), v2c.OctetString())
)
Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21