[SNMP4J] How to remove rows in snmpTargetAddrTable from within the agent?

Martin Carlsson martin.carlsson at transmode.se
Thu Jan 19 14:37:35 CET 2006


Hi!

The restart-methood would work fine (if somewhat brutal :-)).

My original attempt looked very much like what Frank proposes.
I tried this and while the row disappears from the table you get
duplicate traps if adding and removing the same trap receiver a few
times. Also traps are still sent to a receiver even if it has been
removed.

The problem here seems to be that for the benefit of the
NotificationOriginatorImpl class SnmpTargetMIB keeps a list of targets
in snmpTargetAddrTagIndex. See getTargetAddrRowsForTag() in
SnmpTargetMIB.

Now, this index is updated when a row is created but I can't seem to
find how/if it is updated when the row is removed. I suppose it should
be if the row is removed via a RowStatus operation.

Perhaps something like this would do the trick when removing a row from
within the agent?

  public MOTableRow removeTargetAddress(OctetString name) {
    OID index = MOTableIndex.createSubIndex(name, true);
    SnmpTargetAddrEntryRow row = (SnmpTargetAddrEntryRow)
snmpTargetAddrEntryModel.removeRow(index);
  
    Variable tagList = row.getValue(idxSnmpTargetAddrTagList);
    if (tagList != null) {
        Set tags = SnmpTagList.getTags((OctetString)tagList);
        // trigger new indexing of target addrs
        row.updateIndex(tags /* tags to remove */, new HashSet() /*
empty set; no new tags */); 
    }
     
    return row;
  }

The tag will still be present in the tag HashTable but with an empty
address list. Seems to work for me. 

All the best,
/M

> Murali,
> 
> The following method adds the desired functionality to 
> SnmpTargetMIB.java:
> 
>   public MOTableRow removeTargetAddress(OctetString name) {
>     OID index = MOTableIndex.createSubIndex(name, true);
>     return snmpTargetAddrEntryModel.removeRow(index);
>   }
> 
> Best regards,
> Frank
> 
> Muralidharan Narayanan wrote:
> 
> >Martin,
> >
> >This was an issue I faced as well. I was also interested in 
> configuring 
> >the SNMP managers (trap receivers) from the agent I had 
> implemented. I 
> >was able to add IP addresses of trap receivers but unable to remove 
> >them from the internal SNMPAgent library. Frank (author) also 
> >acknowledged in past email about the inability to remove 
> trap receivers from the configurable agent.
> >However, he has promised to include in first beta release of 
> SNMPAgent 
> >library methods for removing trap receivers as well. I guess 
> we have to 
> >hold tight until then.
> >The work around I have used till beta release is available is to 
> >restart the agent and that way the new refreshed list of 
> trap receivers 
> >will be used. I know this restarting procedure may not work for many 
> >cases. If you have other workarounds that work for now, 
> please let me know.
> >
> >Frank can add more to this, if any, to help us here.
> >
> >Murali
> 



More information about the SNMP4J mailing list