[SNMP4J] Updating registered managed objects (adding rows to MIB table)

Frank Fock fock at agentpp.com
Wed Feb 27 00:41:10 CET 2013


Marek,m,

Any operation on the model is immediately visible (add, remove, and update).
No deregister/register is needed/feasable.

Best regards,
Frank


Am 27.02.2013 00:13, schrieb Marek Hajduczenia:
> Frank,
>
> I must have missed it. Sorry about that.
>
> This solves the problem of adding rows to a registered table. I assume
> similarly one could also remove rows (removeRow function). However, when
> such updates are done on an already registered table, the state of the table
> is updated automatically (newly added rows become accessible immediately
> when added) or I need to deregister the table and register it again ?
>
> Marek
>
> -----Original Message-----
> From: Frank Fock [mailto:fock at agentpp.com]
> Sent: Tuesday, 26 February, 2013 11:02 PM
> To: Marek Hajduczenia
> Cc: snmp4j at agentpp.org
> Subject: Re: [SNMP4J] Updating registered managed objects (adding rows to
> MIB table)
>
> Marek,
>
> "Can I just use addRow on the MOMutableTableModel type?"
> Yes, that's what I wrote.
>
> Best regards,
> Frank
>
> Am 26.02.2013 23:58, schrieb Marek Hajduczenia:
>> Frank,
>>
>> Here is the code snippet for the main class (snmpAgentClientMain.java):
>> http://snipt.org/zfhab7. The agent code starts in line 110, MIB table is
>> constructed in lines 129 (using MOTableBuilder class) and createMibTable
>> function defined in snmpAgentClientMain class. The MOTableBuilder.java
> class
>> is snipped at http://snipt.org/zfhac3 and it is used to build the table
>> structure in a more organized fashion.
>>
>> Looking through the code of the MOTableBuilder class, and seeing how it is
>> used in snmpAgentClientMain class (line
>> server.registerManagedObject(builder.build());), I am  not cure how to add
>> more row values to the table that was constructed using either the
>> MOTableBuilder wrapper or using just functions defined in snmp4j library.
> At
>> some point of time, MOTable has to be created (its structure defined), row
>> values are added (I assume it is done using addRow function from snmp4j
>> class), and then registered with the agent (server.registerManagedObject()
>> function). Once it is registered, is there any way to just add rows with
>> values to the previously registered MIB table? Can I just use addRow on
> the
>> MOMutableTableModel type?
>>
>> Marek
>>
>> -----Original Message-----
>> From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org] On
>> Behalf Of Frank Fock
>> Sent: Tuesday, 26 February, 2013 10:00 PM
>> To: snmp4j at agentpp.org
>> Subject: Re: [SNMP4J] Updating registered managed objects (adding rows to
>> MIB table)
>>
>>
>> Hi Marek,
>>
>> I do not know a "addRowValue" command and what is a "builder"?
>> I meant to use the
>> http://www.snmp4j.org/agent/doc/org/snmp4j/agent/mo/MOTable.html#addRow(R)
>> method to add a row.
>> A table definition (MIB specification) never has any rows.
>>
>> Best regards,
>> Frank
>>
>> Am 26.02.2013 18:39, schrieb Marek Hajduczenia:
>>> Hi Frank,
>>>
>>>     
>>>
>>> thanks for the quick feedback. I must have not been really clear in my
>>> explanation and I apologize for that. What I want to achieve is not to
> add
>>> new rows into the table definition, but add new entries (new rows using
>>> addRowValue command) into the table.
>>>
>>>     
>>>
>>> In other words, how do I add row values (addRowValue) to builder after
>>> having executed
>>>
>>>     
>>>
>>> server.registerManagedObject(builder.build());
>>>
>>>     
>>>
>>> ?
>>>
>>>     
>>>
>>> When I try to add row values using builder.addRowValue and then register
>> the
>>> MO again, I get exception (quite expected, it is registered already)
>>>
>>>     
>>>
>>> Thanks again
>>>
>>>     
>>>
>>> Marek
>>>
>>>     
>>>
>>>> Hi,
>>>> The answer is very simple: Just add rows to the table (i.e. its table
>>>> model).
>>>> You can do this while the table itself is registered (operation is
>>>> thread safe).
>>>> Best regards,
>>>> Frank
>>>     
>>>
>>>
>>> Subject: Updating registered managed objects (adding rows to MIB table)
>>>
>>>     
>>>
>>> Dear all,
>>>
>>>     
>>>
>>> I am writing a small SNMP related project for my course. The task is to
>>> create an SNMP agent that will monitor a local selected folder and list
>> all
>>> files stored in this folder in a MIB. I have already MIB designed, agent
>>> working fine on the initial pass, i.e., it creates a MIB table, populates
>>> initial values (files found at first pass through the folder) and then
>>> registers MIB with the agent.
>>>
>>>     
>>>
>>> The code snippet building the table structure is shown below:
>>>
>>>     
>>>
>>> MOTableBuilder builder = new MOTableBuilder(oidNewRoot);
>>>
>>>                                                    
>>>
>>> // MIB structure
>>>
>>>                                    
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_INTEGER32,MOAccessImpl.ACCESS_READ
>>> _ONLY);
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_OCTET_STRING,MOAccessImpl.ACCESS_R
>>> EAD_ONLY);
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_O
>>> NLY);
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_OCTET_STRING,MOAccessImpl.ACCESS_R
>>> EAD_ONLY);
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_INTEGER32,MOAccessImpl.ACCESS_READ
>>> _ONLY);
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_INTEGER32,MOAccessImpl.ACCESS_READ
>>> _ONLY);
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_OCTET_STRING,MOAccessImpl.ACCESS_R
>>> EAD_ONLY);
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_OCTET_STRING,MOAccessImpl.ACCESS_R
>>> EAD_ONLY);
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_INTEGER32,MOAccessImpl.ACCESS_READ
>>> _ONLY);
>>>
>>>
> builder.addColumnType(SMIConstants.SYNTAX_INTEGER,MOAccessImpl.ACCESS_READ_W
>>> RITE);
>>>
>>>     
>>>
>>> The code snippet adding a row is shown below (it is repeated in a loop to
>>> add all found files):
>>>
>>>     
>>>
>>> builder.addRowValue(new Integer32(index));
>>>
>>> index++;
>>>
>>> builder.addRowValue(new OctetString(fileName.getName()));
>>>
>>> builder.addRowValue(new Integer32(3));
>>>
>>> builder.addRowValue(new OctetString(fileName.getPath()));
>>>
>>> builder.addRowValue(new Integer32((int)fileName.length()));
>>>
>>> builder.addRowValue(new Integer32(323));
>>>
>>> builder.addRowValue(new OctetString("Artista"));
>>>
>>> builder.addRowValue(new OctetString("Album"));
>>>
>>> builder.addRowValue(new Integer32(1980));
>>>
>>> builder.addRowValue(new Integer32(4));
>>>
>>>     
>>>
>>> Finally, I register the new MIB with the agent:
>>>
>>>     
>>>
>>> server.registerManagedObject(builder.build());
>>>
>>>     
>>>
>>> After that, I run agent on a loop, every 5 seconds checking whether a new
>>> file was added to the folder. When that happens, I can detect a new file
>>> added and create list of such files. However, I do not know (could not
>> find
>>> any information) on how to add row to already registered MIB. One thought
>>> was on reusing previously constructed table and just deregister it, then
>> add
>>> new rows as needed and the register again but it seems like a very crude
>>> solution to me. Is there any way to do that better? if so, I would
>>> appreciate any pointers.
>>>
>>>     
>>>
>>> Thank you in advance
>>>
>>>     
>>>
>>> Marek
>>>
>>>     
>>>
>>> _______________________________________________
>>> SNMP4J mailing list
>>> SNMP4J at agentpp.org
>>> http://lists.agentpp.org/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