Issues with SampleAgent applications supplied with snmp4j-agent-2.7.4


i am trying to run the SampleAgent application that is supplied with snmp4j-agent-2.7.4 ( my goal is to create/add rows into snmp4jDemoEntry table and then to get the values using SNMPB tool (or any other browser). so i have add the following entries into file so that the application creates rows while it is starting.

my properties entries are:
snmp4j.agent.cfg.value.{i}11 - for this i am gettingan exception that it is not able to cast integer32 to counter32.

with the above values i see an exception “org.snmp4j.smi.Integer32 cannot be cast to org.snmp4j.smi.Counter32”. it is not able to cast to counter32. i tried with “{i}” and “{u}” as well but no luck.
please let me know if the above values are wrong.

To be more clear on the requirement,
we need to build an snmp agent which on get/getNext gives the values from another application which keeps collecting the data periodically. or in other words all of my tables are read only. no way user can create/add rows. this agent connects to an internal application and queries the values as per the VarBindings. earlier we used AdventNet wher we customized getvalue API of MOs to actually get the data from our internal application rather than Agents internal storage. Now we are planning to migrate to SNMP4J (Java API) and understanding the flow and code to get the similar behavior where Get/GetNext will fetch the data from the internal application. please guide me on what SNMP4J interfaces and APIs i should overwrite/customize to reach our goal.

The SMI syntax Counter32, and Counter64 are not supported as type for properties-file loading, because Counters should always start at 0 when a SNMP entity is rebooted.

Anyway, for your use case using properties to load the data seems to be inappropriate. Simply use the createRow and addRow methods of the DefaultMOTable class.
AgenPro can generate the corresponding code.

Additional documentation on common instrumentation approaches for SNMP4J-Agent based agents can be found in:

Hope this helps.

So if i want to test SampleAgent application (supplied with the library) to get/walk entries of snmp4jDemoEntry table, should i change the example code given and implement/instrument the code? or is there any other way to preload some test data without adding instrument? i thought the sampleagent can be run as is and test.
Also as i mentioned in my question, our target agent does not create rows instead on Get/Walk request it should be able to reply back with the data (which is collected and given by an internal application). to get this do i need to implement my own objects write from MOFactory, MOServer, TableModels, MOTables and all? I know that we cannot compare 2 libraries, but with the current vendor, we achieved this by overwriting the get() methods of corresponding handler to create a row and fill in with the data from internal application instead of actually getting from agents internal table. i am looking for inputs to get a similar behavior.
Thanks for sharing the doc, i am going through it

You do not need to write your own objects and AgenPro can generate all the necessary initialisation code for a MIB module from the MIB specification (SMIv2).

In addition, you can use AgenPro to generate test data (i.e., row content) and let AgenPro generate that initialisation code.

But of course you can use the default implementations of MOFactory, MOServer, MOMutableTableModel, MOTable, etc. to setup a table (search for the same class name, but with “Default” prefix). The documentation and the JavaDoc will guide you.

Hi ,
Thanks for the suggestion. Sorry for writing a long post but my requirement is like that.
I was able to generate the code using AgenPro with my MIB file. My understanding is , AgentPro only generates the corresponding java file containing the classes for all the scalar/tabular MOs and uses the moFactory to generate the table Models, tables and columns. Using this java file we need to write our agent code using AgentConfigManager (the way we have in SampleAgent example) where we register the moFactory, moServer and MIBs.
now, if we use the DefaultMOFactory (as in the SampleAgent example) then our agent code will use all the default implementations like DefaultMOMutabletableModel, DefaultMoServer, DefaultMoMutableTable. here with these default implementations, an SNMP GET/WALK request, i see the flow land into DefaultMOTableModel.getRow(OID) where it will look up into the rows collection. Here is my concern where i will not have rows in the collection at anytime. instead i need to create a row object and fill up with my own internal data and return it without even adding into the collection. To get this i understand that i need to overwrite all the corresponding APIs by having my own classes which are extended from the default implementations .like MyDefaultMoFactory extends DefaultMoFactory which creates a table model of my own (MyDefaultMOMutableTableModel extends DefaultMoMutableTableModel where i will overwrite getrow() to add my logic).
please correct/suggest if my understanding is wrong or if i am completely deviating from the implementation and design.

Also, in Agentpro guide i see a property “moFactory” which Specifies a non-default MOFactory to be used for the MIB module. does it help me in any way to solve my issue? i tried adding this property in AgentPro project by setting the value to “moFactory=MyDefaultMoFactory” but it is not being honored.

Basically, you may create your own classes, but you do not need to.

To use the existing classes, use MOServerLookupListener listener which can be registered at the DefaultMOFactory to detect when a ManagedObject (in your case DefaultMOTable) is being accessed by the agent logic. You can then update the table’s content using createRow, addRow, and removeRow, clear on its DefaultMOMutableTableModel.

Hope this helps.

Thanks for pointing me to the MOServerLookupListener class. I used this logic implemented queryEvent where i am adding a row in to the table. I used the same Snmp4jDemoMib and the SampleAgent application (distributed with the source code). i have few doubts in this. i dont see a getter/setter APIs to all the index type of entries (for Example, snmp4jDemoEntryIndex1 in snmp4jDemoEntry MO) because of which i could not assign/initialize values for snmp4jDemoEntryIndex1. I see the index OID used to create a row is different from snmp4jDemoEntryIndex1. am i missing something in this? if i want to initialize snmp4jDemoEntryIndex1 and use same as my instance what can be done?

FYI, this is how i have implemented:
public void queryEvent(MOServerLookupEvent event) {
// TODO Auto-generated method stub
if ((event.getLookupResult() == this.snmp4jDemoEntry)){
Variable[] values = {//new Integer32(21) // commented the first 2 as there are no APIs to initialize
//,new OctetString(“index22”)
new Integer32(21)
,new OctetString(“col22”)
,new Counter32(0)
,new TimeTicks()
,new Integer32(25)
,new Integer32(26)
,new Integer32(27)};
Snmp4jDemoEntryRow row = new Snmp4jDemoEntryRow(new OID(“1”), values);
snmp4jDemoEntry.addRow(row );
and my SNMP walk output is:
-----SNMP query started-----

1: snmp4jDemoEntryCol1.1 21
2: snmp4jDemoEntryCol2.1 col22
3: snmp4jDemoEntryCol3.1 0
4: snmp4jDemoEntryCol4.1 0:00:00.00
5: snmp4jDemoEntryCol5.1 25
6: snmp4jDemoEntryCol6.1 26
-----SNMP query finished-----

in table view format:

please guide if i am missing anything

Those Index „columns“ are defined as not-accessible in SMI. Therefore they do not exists as columns in the MOTable and therefore AgenPro did not generate getter/setter for them.
Instead the value of both index columns is encoded as OID in the index sub-identifier, which you specified as

Which is obviously not correct (you may recognize the error in the quoted table view too).

Thanks for the suggested, i used MOServerLookupListener class queryEvent and was able to create rows before the actual Get request is processed.