2017-06-05 142 views
0

我正在尝试创建SNMP4j代理,并且发现很难正确理解此过程。我成功创建了一个可以使用snmpwalk从命令行查询的代理。我遇到的困难是理解我是如何更新存储在我实现的MIB中的值的。如何正确更新SNMP4j代理MIB值

下图显示了相关的代码我用来创建的MIB(我实现了主机资源-MIB)

 agent = new Agent("0.0.0.0/" + port); 
     agent.start(); 
     agent.unregisterManagedObject(agent.getSnmpv2MIB()); 
     modules = new Modules(DefaultMOFactory.getInstance()); 
     HrSWRunEntryRow thisRow = modules.getHostResourcesMib().getHrSWRunEntry() 
       .createRow(oidHrSWRunEntry); 

     final OID ashEnterpriseMIB = new OID(".1.3.6.1.4.1.49266.0"); 

     thisRow.setHrSWRunIndex(new Integer32(1)); 
     thisRow.setHrSWRunName(new OctetString("RunnableAgent")); 
     thisRow.setHrSWRunID(ashEnterpriseMIB); 
     thisRow.setHrSWRunPath(new OctetString("All is good in the world")); // Max 128 characters 
     thisRow.setHrSWRunParameters(new OctetString("Everything is working")); // Max 128 characters 
     thisRow.setHrSWRunType(new Integer32(HrSWRunTypeEnum.application)); 
     thisRow.setHrSWRunStatus(new Integer32(HrSWRunStatusEnum.running)); 

     modules.getHostResourcesMib().getHrSWRunEntry().addRow(thisRow); 

     agent.registerManagedObject(modules.getHostResourcesMib()); 

这似乎足以建立一个可运行的代理。我不明白的是我如何改变存储在MIB中的值(例如,我如何改变HrSWRunStatus的值)。似乎有一些kludge方式,但他们似乎不符合图书馆的写作方式。

我所遇到多次提到利用/覆盖的方法

  • 准备
  • 提交
  • 撤消
  • 清理

但是找不到在哪里,这是做任何的例子。任何帮助将受到感谢。

回答

0

protected void registerManagedObjects()中,您需要为您的HrSWRunStatus做一些类似new MOMutableColumn(columnId, SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_WRITE, null);的操作。看看SNMP4J-agent源的TestAgent.java示例。