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

Frank Fock fock at agentpp.com
Sat Jan 21 00:05:28 CET 2006


Hi Martin,

Good point! I simply forgot the tag cache! Here is a solution for
removing a target address completely (similar to your solution):

  public MOTableRow removeTargetAddress(OctetString name) {
    OID index = MOTableIndex.createSubIndex(name, true);
    MOTableRow removedRow = snmpTargetAddrEntryModel.removeRow(index);
    if (removedRow != null) {
      removeRowFromTargetAddrTagIndex(removedRow);
    }
    return removedRow;
  }

  protected void removeRowFromTargetAddrTagIndex(MOTableRow victim) {
    OctetString tagList =
        (OctetString) victim.getValue(idxSnmpTargetAddrTagList);
    Set tags = SnmpTagList.getTags(tagList);
    if ((tags != null) && (this.snmpTargetAddrTagIndex != null)) {
      for (Iterator it = tags.iterator(); it.hasNext(); ) {
        Object item = it.next();
        List indexRows = (List) this.snmpTargetAddrTagIndex.get(item);
        if (indexRows != null) {
          indexRows.remove(victim);
          if (indexRows.isEmpty()) {
            this.snmpTargetAddrTagIndex.remove(item);
          }
        }
      }
    }
  }


Best regards,
Frank

Martin Carlsson wrote:

>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
>>>      
>>>
>_______________________________________________
>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