[SNMP4J] Exception in heartbeat MIB when re-starting agent

Frank Fock fock at agentpp.com
Fri Nov 3 00:21:34 CET 2006


Hi Arnoud,

Yes, the heartbeat example MIB implementation fails to save
and restore its state correctly when persistently saved/loaded.

Adding the following code into the inner class
snmp4jAgentHBRefTime will fix the exception:

     //--AgentGen BEGIN=snmp4jAgentHBRefTime::_METHODS
     public void load(MOInput input) throws IOException {
       heartbeatOffset = ((Integer32)input.readVariable()).getValue();
     }

     public void save(MOOutput output) throws IOException {
       output.writeVariable(new Integer32(heartbeatOffset));
     }
     //--AgentGen END

To make the heartbeat example to work correctly after
state restore, some more changes are needed that will
be added to the next version.

Best regards,
Frank

Arnoud Zwemmer wrote:
> Hi Frank, 
>  
> Just downloaded the SNMP4J-Agent code. Looks like a great project,
> compliments. After compiling and running, it worked out-of-the-box,
> except for one thing in the Heartbeat MIB configuration files. Probably
> an easy fix, but wanted to let you know the OOB-behaviour.
>  
> I initially ran the agent without .cfg files (on WinXP, JDK 1.5). When I
> Ctrl-C it, the agent writes the .cfg files, saying:
>  
> 15602 [Thread-0] DEBUG org.snmp4j.agent.io.MOServerPersistence  - Trying
> to write MIB data for all contexts
> 15602 [Thread-0] DEBUG org.snmp4j.agent.io.MOServerPersistence  -
> Writing 43 context independent managed objects
> 15642 [Thread-0] DEBUG org.snmp4j.agent.io.MOServerPersistence  - Trying
> to write MIB data for context ' '
>  
> Now, when re-starting the agent it gives an exception when initializing
> the heartbeat MIB from the config files (see below). Interestingly, this
> exception does _not_ occur when I use a MIB browser to walk the entire
> MIB after the first initialization (before Ctrl-C-ing and restarting
> it).
>  
> The exception is this:
> [...]
> 1312 [main] DEBUG org.snmp4j.agent.io.MOServerPersistence  - Looking up
> object 1.3.6.1.4.1.4976.10.1.1.2.1.2.1.1
> 1312 [main] DEBUG org.snmp4j.agent.io.MOServerPersistence  - Loading
> data for object 1.3.6.1.4.1.4976.10.1.1.2.1.2.1.1
> 1312 [main] DEBUG org.snmp4j.agent.io.MOServerPersistence  - Looking up
> object 1.3.6.1.4.1.4976.10.1.1.42.2.1.1.0
> 1312 [main] DEBUG org.snmp4j.agent.io.MOServerPersistence  - Loading
> data for object 1.3.6.1.4.1.4976.10.1.1.42.2.1.1.0
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
> 
>         at org.snmp4j.smi.OctetString.get(OctetString.java:177)
>         at
> org.snmp4j.agent.mo.snmp.DateAndTime.makeCalendar(DateAndTime.java:137)
>         at
> org.snmp4j.agent.mo.snmp4j.example.Snmp4jHeartbeatMib$Snmp4jAgentHBRefTi
> me.setValue(Snmp4jHeartbeatMib.java:361)
>         at org.snmp4j.agent.mo.MOScalar.load(MOScalar.java:305)
>         at
> org.snmp4j.agent.io.MOServerPersistence.readData(MOServerPersistence.jav
> a:128)
>         at
> org.snmp4j.agent.io.MOServerPersistence.loadData(MOServerPersistence.jav
> a:80)
>         at org.snmp4j.agent.BaseAgent.loadConfig(BaseAgent.java:263)
>         at org.snmp4j.agent.BaseAgent.loadConfig(BaseAgent.java:236)
>         at snmpagent.Main.main(Main.java:41)
>  
> Thanks, 
>  
> Arnoud.
>  
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list