向snmp代理注册OID [英] registering OIDs with snmp agent
问题描述
我正在尝试使用snmp4j模拟SNMP代理. 我正在尝试向代理注册MO. 下面是代码片段:
I am trying to simulate SNMP agent using snmp4j. I am trying to register MOs to the agent. Below is code snippet:
static final OID mo1= new OID("1.3.6.1.4.1.1234.1.104");
static final OID mo2= new OID("1.3.6.1.4.1.1234.1.104.1");
static final OID mo3= new OID("1.3.6.1.4.1.1234.1.104.1.1");
agent.registerManagedObject(MOCreator.createReadOnly(mo1,"m1"));
agent.registerManagedObject(MOCreator.createReadOnly(mo2,"m2"));
agent.registerManagedObject(MOCreator.createReadOnly(mo3,"m3"));
public class MOCreator {
public static MOScalar createReadOnly(OID oid,Object value ){
return new MOScalar(oid,
MOAccessImpl.ACCESS_READ_ONLY,
getVariable(value));
}
private static Variable getVariable(Object value) {
System.out.println("Value : "+value.toString());
OctetString octetString = new OctetString((String)value);
if(value instanceof String) {
return octetString;
}
throw new IllegalArgumentException("Unmanaged Type: " + value.getClass());
}
}
启动代理时,我收到DuplicateRegistrationException. 请指导我如何注册oid. 请提供指示.
While starting the agent I am getting DuplicateRegistrationException. Please guide me how to register oids. Please provide directions.
推荐答案
实际上,正如塞思所说,选择OID似乎是无效的.
Indeed, as Seth says, that choice of OIDs appears to be invalid.
假设您有一个OID为1.3.6.1.4.1.1234.1.104
的对象.
Say you have an object with OID 1.3.6.1.4.1.1234.1.104
.
要么:
- 它是一个标量,在这种情况下,它的值是
1.3.6.1.4.1.1234.1.104.0
或 - 这是一个表,在这种情况下,它的值是
1.3.6.1.4.1.1234.1.104.<N>
(但您无需注册这些单独的行).
- It's a scalar, in which case its value is at
1.3.6.1.4.1.1234.1.104.0
, or - It's a table, in which case it has values
1.3.6.1.4.1.1234.1.104.<N>
(but you don't register these individual rows).
它可能是一个对象组而不是一个对象(例如文件夹),但是您也不注册其中任何一个.
It may alternatively be an object group rather than an object, like a folder, but then you don't register one of those either.
您不能在标量下包含标量(或表),因此您无法在代理中注册它们.
You can't have scalars (or tables) under scalars, so you can't register them with the agent.
我不知道您的MIB是什么样子,想要保存什么样的数据以及如何组织它,就无法提出具体建议,但是似乎您在这里遇到了MIB设计问题.确保在MIB上运行smilint
以验证正确性.
I can't make a specific suggestion without knowing what your MIB looks like and what sort of data you want to hold and how you want to organise it, but it seems like you have a MIB design problem here. Be sure to run smilint
over your MIBs to verify correctness.
这篇关于向snmp代理注册OID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!