C# SNMP 代理 - 表示 MIB 中的复杂类型

C# SNMP agent - representing complex types in MIB

我正在用 C# 编写我的第一个 SNMP 代理,我想通过 SNMP GET 请求公开一些系统事件信息。

在 C# 端,所有系统事件都由一个简单的 class:

表示
public class MySystemEvent  
{  
    public int Id { get;set; }
    public string Message { get; set; }
    public DateTime Occurred { get; set; }
}

我想将每个特定事件(由事件 ID 确定)作为 MIB 中的单独节点公开,但我不完全确定如何创建与 class 以上。我知道我可以使用 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 定义了以下树:

我想添加的是与 "events" 节点具有相同结构的多个其他事件,例如在我想要的第一个特定事件之后:

如何在不为每个特定事件添加单独的 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.

我最终按照@LexLi 建议的方式解决了这个问题,方法是创建一个 table 事件。这样,行条目的定义只需要一次 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 }