java - 无法在模拟 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]
解决方案
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
推荐阅读
- python - 我有一个带有时间索引的表。我只想从中选择一些不连续的日子我这样做了但没有工作
- ssl - 如何在 ESP8266 中验证 MQTT 连接的指纹?
- windows - Microsoft ASAN,使用 ASAN 编译 com dll 并注册它会产生错误
- node.js - $geoNear 需要 2d 或 2dsphere 索引,但是没有找到这个问题 getData api in node.js +monodb
- python - glob() 中的多个数组
- ios - Performant outline around UIImage edges
- java - 从不同类型的方法参数中提取特定字段的值
- webserver - Openlitespeed is serving files with no suffix as download instead of view
- postgresql - Dump PostgreSQL Database from Docker through SSH
- python - Split a string according to the sentence phrases contained in a list in Python