registering OIDs with snmp agent

末鹿安然 提交于 2019-12-07 09:56:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!