听起来你在正确的轨道上。为了将一个表定义为另一个表的子表,您只需通过父索引加上子索引对其进行索引(例如,父索引0.1.8.23.7.2.42
在哪里,子索引在哪里)。2
42
例如,您可以定义这样的父级:
parentTable OBJECT-TYPE
SYNTAX SEQUENCE OF parentEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Parent table"
::= { example 1 }
parentEntry OBJECT-TYPE
SYNTAX ParentEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Entry in Parent table"
INDEX { parentIndex }
::= { parentTable 1 }
ParentEntry ::= SEQUENCE {
parentIndex Unsigned32,
-- other columns in the table
}
-- define the columns in the parent table
子表定义为:
childTable OBJECT-TYPE
SYNTAX SEQUENCE OF childEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Child table"
::= { example 2 }
childEntry OBJECT-TYPE
SYNTAX ChildEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Entry in Child table"
INDEX { parentIndex,
childIndex }
::= { childTable 1 }
ChildEntry ::= SEQUENCE {
childIndex Unsigned32,
-- other columns in the table
}
-- define the columns in the child table
请注意,没有必要在 ChildEntry 序列中列出 parentIndex,因为它已经在 MIB 的其他地方声明。
这种方法效果很好,它甚至可以毫无问题地响应 snmp walks。
一旦你有了一个你认为准确定义了你想要的结构的 MIB,smilint
如果你在 linux 机器上或者安装了 cygwin,你可以使用它来验证它,或者你可以在线验证它。
更新
这种模式也适用于更深的嵌套。
孙表可以定义为:
grandChildTable OBJECT-TYPE
SYNTAX SEQUENCE OF grandChildEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Grandchild table"
::= { example 3 }
grandChildEntry OBJECT-TYPE
SYNTAX GrandChildEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Entry in Grandchild table"
INDEX { parentIndex,
childIndex,
grandChildIndex }
::= { grandChildTable 1 }
grandChildEntry ::= SEQUENCE {
grandChildIndex Unsigned32,
-- other columns in the table
}
-- define the columns in the grandChild table
嵌套深度的唯一限制是最大 OID 长度(我相信它是 127):列的基本 OID 长度加上表的索引数必须小于最大 OID 长度。
另一个需要注意的是,在每个级别上都可以有多个兄弟姐妹。
第二个孩子可以定义为:
secondchildTable OBJECT-TYPE
SYNTAX SEQUENCE OF secondchildEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Second child table"
::= { example 4 }
secondchildEntry OBJECT-TYPE
SYNTAX SecondchildEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION "Entry in Second child table"
INDEX { parentIndex,
secondchildIndex }
::= { secondchildTable 1 }
SecondchildEntry ::= SEQUENCE {
secondchildIndex Unsigned32,
-- other columns in the table
}
-- define the columns in the second child table