首页 > 解决方案 > 无法在模拟 SNMP4J 代理中注册 OID

问题描述

我正在尝试模拟 SNMP 代理以进行测试。我遇到的问题是我无法注册模拟代理需要生成的一些 OID。具体来说: 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 这些 OID 用于UPS。

我尝试将 0 附加到 OID 的末尾,这确实消除了异常,但不适用于我的情况,因为我正在模拟一个真实的系统,所以它需要匹配它。我需要注册的所有其他 OID 都可以正常工作。

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);
        }
    }

在默认上下文中注册 MO [MOScalar],范围为 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] 未能注册 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]

标签: javasnmpsnmp4j

解决方案


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


推荐阅读