在 pysnmp 中使用 setValue
Using setValue in pysnmp
我正在配置社区并尝试在 pysnmp 中使用 setValue 但它不起作用:
...
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()))
...
测试用例:
$ 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
我怎样才能启用私有社区并使 setValue 起作用?
除了VACM设置(工作在per-user/community基础上),你还需要指明管理对象原则上是可写的:
mibBuilder.exportSymbols(
'__MY_MIB',
MibScalar((1, 3, 6, 5, 1), v2c.OctetString()).setMaxAccess('readwrite'),
MyStaticMibScalarInstance1((1, 3, 6, 5, 1), (0,), v2c.OctetString())
)
或者:
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())
)
我正在配置社区并尝试在 pysnmp 中使用 setValue 但它不起作用:
...
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()))
...
测试用例:
$ 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
我怎样才能启用私有社区并使 setValue 起作用?
除了VACM设置(工作在per-user/community基础上),你还需要指明管理对象原则上是可写的:
mibBuilder.exportSymbols(
'__MY_MIB',
MibScalar((1, 3, 6, 5, 1), v2c.OctetString()).setMaxAccess('readwrite'),
MyStaticMibScalarInstance1((1, 3, 6, 5, 1), (0,), v2c.OctetString())
)
或者:
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())
)