我在C#中编写了我的第一个SNMP代理,我希望通过SNMP GET请求公开一些系统事件信息。
在C#方面,所有系统事件都由一个简单的类表示:
public class MySystemEvent
{
public int Id { get;set; }
public string Message { get; set; }
public DateTime Occurred { get; set; }
}
我想将这些特定事件(由事件ID确定)作为MIB中的单独节点公开,但我不完全确定如何创建与上述类对应的自定义ASN.1复杂类型。我知道我可以使用SEQUENCE来表示这些,但不确定我是否正确使用它们。
到目前为止我做了什么:
enterprise OBJECT IDENTIFIER ::= { private 1 }
penNode OBJECT IDENTIFIER ::= { enterprise <PEN> }
customSystemNode OBJECT IDENTIFIER ::= { penNode 1 }
events OBJECT IDENTIFIER ::= { customSystemNode 1 }
Event ::= SEQUENCE {
id Integer32,
message DisplayString,
occurred DateAndTime
}
firstSpecificEvent OBJECT-TYPE
SYNTAX Event
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"First specific event."
INDEX { eventId }
::= { events 1 }
eventId OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Event Id."
::= { firstSpecificEvent 1 }
eventMessage OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Event message."
::= { firstSpecificEvent 2 }
eventOccurred OBJECT-TYPE
SYNTAX DateAndTime
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Event occurred."
::= { firstSpecificEvent 3 }
上面的MIB定义了以下树:
我要添加的是多个其他事件,其结构与&#34;事件&#34;相同。例如节点在我想要的第一个特定事件之后:
如何为每个特定事件添加单独的eventId,eventMessage和eventOccurred OBECT-TYPE定义? 是否可以定义一个允许以下内容的CustomEventComplexType?
firstSpecificEvent OBJECT-TYPE
SYNTAX CustomEventComplexType
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"First specific event."
::= { events 1 }
secondSpecificEvent OBJECT-TYPE
SYNTAX CustomEventComplexType
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Second specific event."
::= { events 2 }
thirdSpecificEvent OBJECT-TYPE
SYNTAX CustomEventComplexType
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Third specific event."
::= { events 3 }
etc.
答案 0 :(得分:1)
我最终通过创建一个事件表来解决这个问题,就像@LexLi建议的那样。这样,对于行条目的定义,只需要一次OBJECT-TYPE定义。
enterprise OBJECT IDENTIFIER ::= { private 1 }
penNode OBJECT IDENTIFIER ::= { enterprise <PEN> }
customSystemNode OBJECT IDENTIFIER ::= { penNode 1 }
Event ::= SEQUENCE {
id Integer32,
message DisplayString,
occurred DateAndTime
}
eventTable OBJECT-TYPE
SYNTAX SEQUENCE OF Event
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Table containing event information."
::= { customSystemNode 1 }
eventTableRowEntry OBJECT-TYPE
SYNTAX Event
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"A row entry in the event table."
INDEX { eventId }
::= { eventTable 1 }
eventId OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Event id."
::= { eventTableRowEntry 1 }
eventMessage OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Event message."
::= { eventTableRowEntry 2 }
eventOccurred OBJECT-TYPE
SYNTAX DateAndTime
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Event occurred timestamp."
::= { eventTableRowEntry 3 }