问题
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());
}
}
While starting the agent I am getting DuplicateRegistrationException. Please guide me how to register oids. Please provide directions.
回答1:
Indeed, as Seth says, that choice of OIDs appears to be invalid.
Say you have an object with OID 1.3.6.1.4.1.1234.1.104.
Either:
- 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.
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.
回答2:
From: http://oosnmp.net/pipermail/snmp4j/2014-September/005416.html
SMI forbids the registration of an OID below another OID (instance within instance). Otherwise, the lexicographic ordering of objects in an agent could not be implemented without ambiguities.
So I believe this OID registration method is not possible. You should try using OID without using strict substrings like this. Or try to reverse the order of the registrations.
来源:https://stackoverflow.com/questions/23734012/registering-oids-with-snmp-agent