我一直在使用此处找到的示例开发自己的 SNMP 代理:http: //www.net-snmp.org/dev/agent/example_8c_source.html
我想更好地组织我的树结构以使其更有意义,这反过来又使使用客户端命令更容易。
我正在使用传统的旧 C API 来实现这一点,这就是示例链接中使用的内容。
我有一棵要实现的树
我的 MIB:
MIB-NAME-HERE DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, Integer32, enterprises,
NOTIFICATION-TYPE FROM SNMPv2-SMI
OBJECT-GROUP, NOTIFICATION-GROUP FROM SNMPv2-CONF
;
myProduct MODULE-IDENTITY
LAST-UPDATED "201505200000Z"
ORGANIZATION "www.example.com"
CONTACT-INFO
"email: support@example.com"
DESCRIPTION
"MIB Example."
REVISION "201505200000Z"
DESCRIPTION
"version 1.0"
::= { enterprises 54321 }
--
-- top level structure
--
IPConfig OBJECT IDENTIFIER ::= { myProduct 1 }
Services OBJECT IDENTIFIER ::= { myProduct 3 }
IPConfigValuesGroup OBJECT-GROUP
OBJECTS { ObjectA,
ObjectB,
ObjectC
}
STATUS current
DESCRIPTION
"Group of all blahblah variables."
::= { myProduct 4 } <----**How would this affect a client request?**
--
-- Values
--
ObjectA OBJECT-TYPE
SYNTAX OCTET STRING (SIZE(1..4096))
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Test Example"
::= { IPConfig 1 }
ObjectB OBJECT-TYPE
SYNTAX OCTET STRING (SIZE(1..4096))
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Test Example"
::= { IPConfig 2 }
--MORE STUFF...
.... END
我希望能够将相关对象组合在一起,以便用户可以执行
snmpset -v 2c -c communityNameHere -m MIB-NAME-HERE.txt 10.20.30.40 1.3.6.1.4.1.54321.x.1.3 s "I am a string"
访问 IPConfig 组下的 ObjectC。
问题:如何在我的“子代理”中实现子树?
This is an excerpt from the link shown above.
/*
* This array defines the OID of the top of the mib tree that we're
* registering underneath.
* Note that this needs to be the correct size for the OID being
* registered, so that the length of the OID can be calculated.
* The format given here is the simplest way to achieve this.
*/
oid example_variables_oid[] = { 1, 3, 6, 1, 4, 1, 54321, x};
我是否必须声明另一个数组以包含服务 OID?
oid example_variables_oid[] = { 1, 3, 6, 1, 4, 1, 54321, x, 3};
或者对于每个子树,他们是否需要一个 example.c*-type* 文件?
问题:这个 MIB 能实现我想要的吗?需要做哪些不同的事情?我已经阅读了 OBJECT-GROUPS、SEQUENCE、O'Reily 的书以及 RFC。我仍在努力掌握一切。