我是python和SNMP(以及pysnmp)的新手。经过两周的学习,我写了一段python代码,试图发送一个陷阱消息。 NotificationType是由代码创建的:
notification = NotificationType(ObjectIdentity('MY_MIB_FILE','myAlarmCleared'),
instanceIndex=(0,),
objects={
('MY_MIB_FILE', 'myAlarmId'):
Integer32(111),
('MY_MIB_FILE', 'mySystemDN'):
self.DisplayString(''), # currently a null string
('MY_MIB_FILE', 'myAlarmNotificationSource'):
ObjectIdentifier(
(1, 3, 6, 1, 4)), # some dummy value
('MY_MIB_FILE', 'myNotiSequenceNum'):
Integer32(222),
('MY_MIB_FILE', 'myAlarmManagedObjectInstance'):
self.DisplayString('SubNetwork=nw1,ManagedElement=my-1'),
('MY_MIB_FILE', 'myAlarmType'):
self.AlarmType(3),
('MY_MIB_FILE', 'myAlarmProbableCause'):
self.ProbableCause(307),
('MY_MIB_FILE', 'myAlarmSpecificProblem'):
self.DisplayString('test alarm'),
('MY_MIB_FILE', 'myAlarmPerceivedSeverity'):
self.AlarmSeverity(6),
('MY_MIB_FILE', 'myAlarmTime'):
self.DateAndTime(OctetString(self.get_current_date_and_time())),
('MY_MIB_FILE', 'myAlarmAdditionalText'):
self.DisplayString('alarm testing'),
('MY_MIB_FILE', 'myAlarmName'):
self.DisplayString('system_testing_alarm'),
('MY_MIB_FILE', 'myAlarmServiceUser'):
self.DisplayString('Dapeng Jiao'),
('MY_MIB_FILE', 'myAlarmServiceProvider'):
self.DisplayString('Unknown Service Provider'),
('MY_MIB_FILE', 'myAlarmSecurityAlarmDetector'):
self.DisplayString('Unknown Alarm Detector'),
('MY_MIB_FILE', 'myAlarmADMC'):
Integer(1)
}
)
当我执行此代码时,我得到以下smirerror:
^{pr2}$pysnmp似乎不喜欢为语法定义为的变量添加后缀.0:
Integer32().subtype(subtypeSpec=ValueRangeConstraint(1, 2147483647))).setMaxAccess("readwrite")
这是pysnmp的错误吗? 或者我不应该加上后缀.0?(至少在从instanceIndex中删除“0”之后,代码才能执行并成功发送陷阱消息。 但有人告诉我
A scalar variable has single instance and is identified by suffix .0 . The object identifier (OID) with .0 suffix indicates a scalar variable (i.e., single instance) (eg, analogous/category of a “table” with only one column) Each of the varbinds in the notification is scalar for this alarm notification.
看来.0是必须的,对吧?还是我们之间有些误会?在
提前谢谢。在
比尔, -大鹏角
该变量的原始MIB定义是:
myAlarmCleared NOTIFICATION-TYPE
OBJECTS {
myAlarmId,
cesSystemDN,
myAlarmNotificationSource,
cesNotiSequenceNum,
myAlarmManagedObjectInstance,
myAlarmType,
myAlarmProbableCause,
myAlarmSpecificProblem,
myAlarmPerceivedSeverity,
myAlarmTime,
myAlarmAdditionalText,
myAlarmName,
myAlarmServiceUser,
myAlarmServiceProvider,
myAlarmSecurityAlarmDetector,
myAlarmADMC
}
STATUS current
DESCRIPTION
"This notification is generated when an alarm is cleared."
::= { myAlarmNotifications 3 }
myAlarmTime OBJECT-TYPE
SYNTAX DateAndTime
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"This variable is the time of this Alarm object."
::= { myAlarmEntry 9 }
myAlarmEntry OBJECT-TYPE
SYNTAX myAlarmEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"A row containing one alarm."
INDEX { myAlarmId }
::= { myAlarmTable 1 }
转换后的python格式为:
myAlarmCleared = NotificationType((1, 3, 6, 1, 4, 1, xxxx, x, xx, x, xxx, x, 6, 3)).setObjects(*(
("MY-MIB-FILE", "myAlarmTime"), ("MY-MIB-FILE", "myAlarmName"),
("MY-MIB-FILE", "myAlarmServiceUser"), ("MY-MIB-FILE", "myAlarmSpecificProblem"),
("MY-MIB-FILE", "cesSystemDN"), ("MY-MIB-FILE", "myAlarmProbableCause"),
("MY-MIB-FILE", "myAlarmType"), ("MY-MIB-FILE", "myAlarmAdditionalText"),
("MY-MIB-FILE", "myAlarmNotificationSource"), ("MY-MIB-FILE", "myAlarmId"),
("MY-MIB-FILE", "myAlarmManagedObjectInstance"), ("MY-MIB-FILE", "myAlarmADMC"),
("MY-MIB-FILE", "myAlarmSecurityAlarmDetector"),
("MY-MIB-FILE", "myAlarmPerceivedSeverity"), ("MY-MIB-FILE", "cesNotiSequenceNum"),
("MY-MIB-FILE", "myAlarmServiceProvider"),))
myAlarmEntry = MibTableRow((1, 3, 6, 1, 4, 1, xxxx, x, xx, x, xxx, x, x, x, 1)).setIndexNames((0, "MY-MIB-FILE", "myAlarmId"))
if mibBuilder.loadTexts: myAlarmEntry.setDescription("A row containing one alarm.")
myAlarmTime = MibTableColumn((1, 3, 6, 1, 4, 1, xxxx, x, xx, x, xxx, x, x, 1, 1, 9), DateAndTime()).setMaxAccess("readonly")
if mibBuilder.loadTexts: myAlarmTime.setDescription("This variable is the time of this Alarm object.")
日期和时间是从SNMPv2 TC导入的。在
对此有一个更新: 即使是异常也显示问题是由“myAlarmTime”引起的
但调试之后,似乎真正的问题是'myAlarmId'语法定义。因为该变量是唯一用整数32定义的变量,其范围为(12147483647)
^{pr2}$在我将其值范围更改为(02147483647)之后 实例索引=(0) 开始工作。在
但我不应该改变对吗? 那么这个问题的根本原因是什么呢? Pysnmp错误? 还是我们对SNMP和MIB文件的误解?在
顺便说一句:后缀.0可以很好地与基于Java的SNMP连接使用。但由于公司的订单和许可证问题,我们需要重新实现它,而且我们认为python应该足够好来实现这一点。在
附加更多与此警报事件相关的MIB定义
比尔, -大鹏角
相关问题 更多 >
编程相关推荐