But with contexts introduced, my AgentConfigSetup.properties file is not even parsing. It is throwing following exception
Caused by: java.lang.NumberFormatException: For input string: “ctx”
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at org.snmp4j.util.SimpleOIDTextFormat.parseOID(SimpleOIDTextFormat.java:127)
at org.snmp4j.util.SimpleOIDTextFormat.parse(SimpleOIDTextFormat.java:150)
The “.ctx” must be written before “.oid” or “.index”. But even then, you cannot create contexts using the properties file. Contexts must be added programmatically and the MIB objects need to be registered to contexts of the DefaultMOServer programmatically.
You can then initialise the (context specific) MIB objects using the properties file.
I found this piece of code in PropertyMOInput. This says that the “.ctx” must be written before “.oid ” or “.index ”. This matches the documentation also.
As you mentioned I have already added contexts in code while creating the MOServer and MOTable.
I am getting FOllowing error now:
Caused by: java.io.IOException: null
at org.snmp4j.agent.io.prop.PropertyMOInput.readContext(PropertyMOInput.java:358)
at org.snmp4j.agent.io.MOServerPersistence.loadData(MOServerPersistence.java:110)
at org.snmp4j.agent.AgentConfigManager.configure(AgentConfigManager.java:674)
This is being thrown from PropertyMOInput.readContext() method.
Inside the MOServerPersistence class, when it reaches the “// load contexts” section, and does the following loop
for (int i = 0; i < contextSequence.getSize(); i++) {
Context context = input.readContext();
The state value already changes to 3. How to load the contexts then? What Am I missing for context loading?
I think there was a bug in the PropertyMOInput class. The state++; in the third case (STATE_CTX_SEQ) needs to be removed:
public Sequence readSequence() throws IOException {
switch (state) {
case STATE_ALL_CTX_DATA_SEQ: {
state++;
oids = scanOIDs(properties, null);
return new Sequence(oids.numElements);
}
case STATE_ALL_CTX_DATA:
if (data != null && !oids.iterator.hasNext()) {
state++;
// fall through
} else {
DataInfo<IndexedVariables> indexedVariablesDataInfo = new DataInfo<IndexedVariables>(oids.curContext);
data = indexedVariablesDataInfo;
scanDataIndexVariables(properties, oids.curOID.getOID(), indexedVariablesDataInfo);
return new Sequence(data.size());
}
case STATE_CTX_SEQ: {
state++; // <==== Remove this line to fix the IOException!
return new Sequence(contexts.numContexts);
}
}
return null;
}
But unfortunately it seems that the context data loading has not been completely implemented in SNMP4J-Aent yet. I am working on it to fix it ASAP…
Thanks Frank. Is it possible to to tell me what are the changes you identified context data loading in SNMP4J-Agent, I can implement those separately and continue and when your fix patch arrives, will adopt that.
Also, is it possible to tell a timeline when can you provide a fix?
I have devised an workaround for this. I am running a separate java process with default context for each context (supposed to be) on different port. A proxy forwarder forwards the request to corresponding java process/port.
I am working on it. It will take some more days, I guess. But the state++ in the above code snippet was not the source of the problem, but missing code for the context specific data loading:
case STATE_CTX_SEQ: {
state++; // This line was correct but an additional case statement is needed!
return new Sequence(contexts.numContexts);
}