听起来你走在了正确的道路上。为了将一个表定义为另一个表的子表,你只需要使用父表的索引加上子表的索引作为索引(例如: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遍历而没有问题。
一旦您拥有您认为准确定义所需结构的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
p
)加上子节点的索引(c
)”时,它是指xxx.p.c
还是xxx.(p+c)
?这可能听起来像一个新手问题,但...那就是我;)(虽然前者对我来说更有意义,但经验多次证明我的感觉与“MIB感觉”不同) - Matthieuxxx.p.c
,就像你所怀疑的那样。我已经更新了答案中的解释,并包括了一个示例。感谢您提出了一个很好的澄清问题! - lostriebo