[SNMP4J] Help for setting up OIDs that change values

Frank Fock fock at agentpp.com
Fri Sep 11 09:03:51 CEST 2015


Hi Andrew,

Updating tables with the lookup event listener could be tricky.
The reason for that is, that you cannot predict how the
command sender (SNMP manager in old words) asks for
the OIDs. The first OID in the request might point to the
second row in the table and the second OID in the request
to the 7th row and so on.

The lookup event facilitates that by firing the event for each
VB in the request separately.

Back to your question: Yes, you can use the lower bound to
optimize your lookup, but the lower bound is only the lower
bound. To find the affected cells you will have to use the
methods/algorithms provided by DefaultMOTable.
Generally it is also recommended to update the whole row
at once because the requested typically tries to retrieve
more than one column of a table.

Maybe the BufferedMOTableModel (SNMP4J-AgentX) is easier
to handle than using the lookup evednt listener. There you
only override two methods "fetchRow..." which update the
one or more rows and you are done.

Best regards,
Frank

Am 10.09.2015 um 00:43 schrieb Andrew Samuels:
> Hi,
>
> So I got much further and now registering the object and a listener 
> for it.
>
> @Override
> protected void registerManagedObjects() {
> // TODO Auto-generated method stub
> System.out.println("registerManagedObjects called\n");
> try
> {
> DefaultMOTable thisTestObj = MOCreator.createModuleTable();
> System.out.println("Original Managed object is '"+thisTestObj+"'\n");
> server.addLookupListener(new SNMPLookupListener("table object"), 
> thisTestObj);
> server.register(thisTestObj,null);
> }
>     catch (DuplicateRegistrationException ex) {
>         ex.printStackTrace();
>       }
> }
>
> The table is an example I found and works as expected.
>
> The listener also fires when I run a snmpwalk and I can pull out which 
> OIDs are being called, so the listener code section which is relevant is
>
> public void lookupEvent(MOServerLookupEvent arg0)
> {
> System.out.print("lookup name '"+this.lookupName+"' lookup event 
> here!\n");
> System.out.print("lookup name '"+this.lookupName+"' lower bound is 
> '"+arg0.getQuery().getLowerBound()+"'\n");
> System.out.print("lookup name '"+this.lookupName+"' upper bound is 
> '"+arg0.getQuery().getUpperBound()+"'\n");
> System.out.print("lookup name '"+this.lookupName+"' lower bound string 
> is '"+arg0.getQuery().getLowerBound()+"'\n");
>
> DefaultMOTable thisManagedObject = (DefaultMOTable)arg0.getLookupResult();
> System.out.print("lookup name '"+this.lookupName+"' managedobject is 
> '"+thisManagedObject+"'\n");
>
> MOMutableTableModel thisModel = (MOMutableTableModel) 
> thisManagedObject.getModel();
> System.out.print("lookup name '"+this.lookupName+"' thisModel is 
> '"+thisModel+"'\n");
>
> MOMutableTableRow l_row = 
> (MOMutableTableRow)thisManagedObject.getModel().getRow(new OID("2"));
>
> l_row.setValue(2, new Counter64(System.currentTimeMillis());
> }
>
>
> So at the moment I pull out row 2 and set the value for the 2nd entry 
> to the current time. This works and I can see the new value in each walk.
>
> My question is this,
>
> Based on the OID in the lower bound value when lookupevent triggers, 
> can I update the row/entry based on the OID of the lower bound value 
> so I can update it directly ? rather than pulling the 2nd row from 
> model and then 2nd entry ?  or again have I missed something ? or 
> perhaps could be how my model is created ?
>
> Andrew.
>
>
>
>
>
>
>
>
> On Wed, Sep 9, 2015 at 3:01 PM, Frank Fock <fock at agentpp.com 
> <mailto:fock at agentpp.com>> wrote:
>
>     Hi Andrew,
>     The first thing to fix is using .0 as suffix for scalar managed
>     objects (you name those "OIDs" which is not fully appropriate).
>     The lookup mechanism of SNMP4J-Agent relies on this SNMP standard
>     requirement.
>     The most easiest way to instrument a scalar managed object is to
>     overwrite its setValue method.
>     I probably can add more pointers if you have tried the above.
>
>     Best regards,
>     Frank
>
>     > Am 09.09.2015 um 15:04 schrieb Andrew Samuels
>     <drewsamuels13 at gmail.com <mailto:drewsamuels13 at gmail.com>>:
>     >
>     > All,
>     >
>     > I have been looking at using SNMP4J for a while and finally
>     started to get
>     > to grips with it, however setting up OIDs that can return
>     changing values
>     > is proving more challenging than I anticipated and I am looking for
>     > pointers. I have read the instrumentation guide and pulled
>     various pieces
>     > of code together from searching.
>     >
>     > So far I have the basics working, various examples show these
>     >
>     > // Set up a new agent
>     > this.myAgent = new SNMPAgent("udp:10.0.0.5/161
>     <http://10.0.0.5/161>");
>     >
>     > // Start the agent
>     > this.myAgent.start();
>     > // Remove all the default MIBs so I can see any
>     additions/changes I am
>     > making more easily.
>     > myAgent.unregisterManagedObject(myAgent.getSnmpv2MIB());
>     > myAgent.unregisterManagedObject(myAgent.getSnmp4jLogMIB());
>     > myAgent.unregisterManagedObject(myAgent.getSnmpCommunityMIB());
>     > myAgent.unregisterManagedObject(myAgent.getSnmp4jConfigMIB());
>     > myAgent.unregisterManagedObject(myAgent.getSnmpFrameworkMIB());
>     > myAgent.unregisterManagedObject(myAgent.getSnmpNotificationMIB());
>     > myAgent.unregisterManagedObject(myAgent.getUsmMIB());
>     > myAgent.unregisterManagedObject(myAgent.getVacmMIB());
>     > myAgent.unregisterManagedObject(myAgent.getSnmpProxyMIB());
>     > myAgent.unregisterManagedObject(myAgent.getSnmpTargetMIB());
>     >
>     > //Add a simple OID with string
>     >
>     > OID mo1= new OID("1.3.6.1.2.1.1.1");
>     > myAgent.registerManagedObject(MOCreator.createReadOnly(mo1,"this
>     is my
>     > test"));
>     >
>     > If I start the agent and then do a walk
>     >
>     > snmpwalk -v 2c -c public 10.0.0.5 .1
>     > iso.3.6.1.2.1.1.1 = STRING: "this is my test"
>     > iso.3.6.1.2.1.1.1 = No more variables left in this MIB View (It
>     is past the
>     > end of the MIB tree)
>     >
>     > I get back what I expected and everything is good, so I know the
>     agent
>     > starts, community is working etc.
>     >
>     > The next step I unfortunately do not seem to be able to get
>     working at all.
>     >
>     > Lets say I have a class call Kitchen and an instance of the
>     class called
>     > ThisKitchen. It has the following return methods
>     >
>     > getStaffOnDuty() - returns string
>     > getSpoonCount() - returns int
>     > getKnifeCount() - returns int
>     > getForkCount() - returns int
>     >
>     > These values can be updated in the ThisKitchen instance with
>     comparable set
>     > calls ,so setStaffOnDuty, setSpoonCount etc
>     >
>     > I have tried using a MOServerLookupListener and MOTable and also the
>     > class UpdatableManagedObject,
>     > however the MOTable I obviously do not yet understand fully and the
>     > UpdateableManagedObject always returns null for the oid I set up.
>     >
>     > A simple oid structure (fake prefix) I am looking for would be
>     >
>     > 1.8.8.8.1 = staffonduty - string
>     > 1.8.8.8.2 = spooncount - int
>     > 1.8.8.8.3 = knifecount - int
>     > 1.8.8.8.4 = forkcount - int
>     >
>     > Can any one provide some pointers, not looking for complete code
>     (although
>     > very welcome), but some basic framework pointers that aligns
>     with what I am
>     > trying to do ? as I believe my current approach is missing some
>     > fundamentals for OIDs that change values and how the structures
>     work.
>     >
>     >
>     > Andrew.
>     > _______________________________________________
>     > SNMP4J mailing list
>     > SNMP4J at agentpp.org <mailto:SNMP4J at agentpp.org>
>     > https://oosnmp.net/mailman/listinfo/snmp4j
>
>

-- 
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231




More information about the SNMP4J mailing list