简体   繁体   中英

Unable to register OID's in mock SNMP4J agent

I am attempting to mock a SNMP agent for testing purposes. The problem that I am running into is that I am not able to register some of the OIDs that the mock agent needs to produce. Specifically: 1.3.6.1.2.1.33.1.3.3.1.4.1 1.3.6.1.2.1.33.1.3.3.1.4.2 1.3.6.1.2.1.33.1.3.3.1.4.3 These OIDs are for the input current on a UPS.

I have tried appending 0 to the end of the OIDs, which does get rid of the exception, but will not work for my case because I am mocking a real system, so it needs to match that. All of the other OIDs I need to register are working fine.

public class mockAgent extends BaseAgent {

    public mockAgent(CommandProcessor commandProcessor) {
        super(new File("bootCounterFile.txt"), new File("configFile.txt"), commandProcessor);
                new CommandProcessor(new OctetString(MPv3.createLocalEngineID()));
    }


    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    protected void registerManagedObjects() {
        getSnmpv2MIB().unregisterMOs(server, getContext(getSnmpv2MIB()));
        try{
             MOScalar moScalar = null;
             moScalar = new MOScalar(new OID("1.3.6.1.2.1.33.1.3.3.1.4.1"),
                        MOAccessImpl.ACCESS_READ_WRITE, new OctetString("3")); //UPS_INPUT_CURRENT_PHASE_1
              server.register(moScalar, null);
              moScalar = new MOScalar(new OID("1.3.6.1.2.1.33.1.3.3.1.4.2"),
                        MOAccessImpl.ACCESS_READ_WRITE, new OctetString("4")); //UPS_INPUT_CURRENT_PHASE_2
              server.register(moScalar, null);
              moScalar = new MOScalar(new OID("1.3.6.1.2.1.33.1.3.3.1.4.3"),
                        MOAccessImpl.ACCESS_READ_WRITE, new OctetString("5")); //UPS_INPUT_CURRENT_PHASE_3
              server.register(moScalar, null);
        }catch(DuplicateRegistrationException  e){
            System.out.println("failed to register");
            System.out.println(e);
        }
    }

Registered MO [MOScalar] in default context with scope org.snmp4j.agent.mo.MOScalar[oid=1.3.6.1.2.1.33.1.3.3.1.4.1,access=MOAccessImpl{read|write|notify},value=3,volatile=false] failed to register org.snmp4j.agent.DuplicateRegistrationException: org.snmp4j.agent.DefaultMOContextScope[context=null,lowerBound=1.3.6.1.2.1.33.1.3.3.1.4,lowerIncluded=true,upperBound=1.3.6.1.2.1.33.1.3.3.1.5,upperIncluded=false]

If the OIDs in the real system do not end on .0 then those OIDs belong to a SNMP table and not to scalar values. Then you should use the DefaultMOTable to mock those objects instead.

For a read-only (and read-write) generic mocking of SNMP variables, the StaticMOGroup can be used too: https://snmp4j.org/agent/doc/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM