所以我正在尝试让陷阱在我们的项目中工作。我们正在使用自定义 mib 并且已经可以运行它,也可以发送没有额外数据的陷阱,使用以下代码和从 MIB 中的陷阱中删除的 OBJECT 属性可以正常工作:
def sendEventTrap(self, event):
if(doPrintTraps):
print "Sending trap"
ntfOrg = ntforg.NotificationOriginator(self._snmpContext)
errorIndication = ntfOrg.sendNotification(
self._snmpEngine,
'trap',
('PROJECT-MIB', 'eventTrap'),
())
现在我正在尝试添加一个简单的 Integer32 附加对象,如下所示
def sendEventTrap(self, event):
if(doPrintTraps):
print "Sending trap"
ntfOrg = ntforg.NotificationOriginator(self._snmpContext)
errorIndication = ntfOrg.sendNotification(
self._snmpEngine,
'trap',
('PROJECT-MIB', 'eventTrap'),
[((1, 3, 6, 1, 4, 1, 999999, 3, 1, 0) , v2c.Integer32(1337))])
但是,即使根据以下日志,它确实找到正确的 OID 并将其与正确关联的 Integer32 类型匹配,此操作也会失败:http://pastebin.com/hJ9LAiAg
这是MIB的相关部分:
eventNotifications OBJECT IDENTIFIER ::= { xxx 4 }
eventTrap NOTIFICATION-TYPE
OBJECTS { direction }
STATUS current
DESCRIPTION ""
::= {eventNotifications 1}
注意:出于隐私原因,某些函数名称已更改。我在这里不知所措,非常感谢有关哪里出了问题的意见。
我终于开始工作了。实际上有两个问题。
- 此功能似乎在 4.2.5 中被破坏,我当前的代码仍然失败并出现关键错误。在 4.3.2 上它运行良好。
- 上面的代码缺少作为参数
instanceIndex=(0,)
,在发送已托管的对象时,不必手动将其作为 varBind 包含在内。
以下内容适用于问题MIB中的声明:
ntfOrg = ntforg.NotificationOriginator(self._snmpContext)
errorIndication = ntfOrg.sendNotification(
self._snmpEngine,
'trap',
('PROJECT-MIB', 'eventTrap'),
instanceIndex=(0,))