Alex:
I am new to SNMP agent world too. So, my solution might not be the best, but it works for me.

The remove a community string, I have method which I posted in my previous email:

   / private void removeOneCommunity(SnmpCommunityMIB communityMIB,
   MOTableRow aRow)
   {
   /

       / MOMutableTableModel comEntryModel =
(MOMutableTableModel)communityMIB.getSnmpCommunityEntry().getModel();
       communityMIB.getSnmpCommunityEntry().removeRow(aRow.getIndex());
       comEntryModel.freeRow(aRow);
       /

   / }/

The community row is an input parameter for this method. To get a particular row, you can loop through the snmpCommunityEntry table: / MOMutableTableModel comEntryModel = (MOMutableTableModel)communityMIB.getSnmpCommunityEntry().getModel();
       MOTableRow aRow;

// Replace public2public if you create community row with something else. String myCommunityStringIndex = "public2public"; //OID// o = new OctetString(myCommunityStringIndex ).toSubIndex(true);

for (Iterator<MOTableRow> it = comEntryModel.iterator(); it.hasNext();)
       {
           aRow = it.next();
           if (aRow.getIndex().equals(o))
           {
// This is the community row you are looking for. found = true;
                   .....
           }
       }/
The string myCommunityStringIndex is the row index you put in when you create that row. Following code section is the sample code from TestAgent::addCommunities() which uses "public2public" for community string "public":
   MOTableRow row =
       communityMIB.getSnmpCommunityEntry().createRow(
         new OctetString("public2public").toSubIndex(true), com2sec);

Hope this information helps.

To add a community string, following sample code in TestAgent::addCommunities().

Vivi

Alexander Fooks wrote:
Hello, Vivi,

Sorry for direct request for your help. I think you may help me.
I'm looking for solution to add private community to my SNMP agent
(agent itself and subagent-forwarder).
Also I want to delete "public" community.
Could you advise me how to do this? I'm working with SNMP version 2c.


Thank you in advance.

Best Regards

Alex Fooks


-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of [email protected]
Sent: Tuesday, December 30, 2008 12:42 PM
To: [email protected]
Subject: SNMP4J Digest, Vol 59, Issue 18

Send SNMP4J mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.agentpp.org/mailman/listinfo/snmp4j
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of SNMP4J digest..."


Today's Topics:

   1. Re: How to Remove an SNMP Community String. (Vivi Zhang)


----------------------------------------------------------------------

Message: 1
Date: Mon, 29 Dec 2008 09:22:11 -0600
From: Vivi Zhang <[email protected]>
Subject: Re: [SNMP4J] How to Remove an SNMP Community String.
To: Frank Fock <[email protected]>
Cc: SNMP4J <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Frank:

Thank you very much for your help. As you suggested, the problem is around the coexistenceInfo within SnmpCommunityMIB, indeed.

I did set the coexistence provider at the CommandProcessor. The createRow adds a cummunity row entry to coexistenceInfo map.

The statement "communityMIB.getSnmpCommunityEntry().removeRow(aRow.getIndex());" removes a community row from Community entry table. But this statement does not remove the row from coexistenceInfo which is used by CommandProcessor to check the security name. Currently, I added a statement "comEntryModel.freeRow(aRow);" immediately after preivous statement, and this stmt helps. private void removeOneCommunity(SnmpCommunityMIB communityMIB, MOTableRow aRow)
    {
MOMutableTableModel comEntryModel = (MOMutableTableModel)communityMIB.getSnmpCommunityEntry().getModel();
        communityMIB.getSnmpCommunityEntry().removeRow(aRow.getIndex());
        comEntryModel.freeRow(aRow);
    }

The SnmpCommunityEntryRowFactory.freeRow() is invoked which removes the community string from coexistenceInfo.

Is this preferred way to remove a community string?
Thanks again.

Vivi

Frank Fock wrote:
Hi Vivi,

I assume that you did not set the coexistence provider
at the CommandProcessor to your instance of the
SnmpCommunityMIB class.

The CommandProcessor then uses the SNMPv1/v2c community
as security name directly without mapping it to a
security name using the SNMP-COMMUNITY-MIB mapping.
Since you have an equal security name in your VACM
configuration, the request goes through.

For further questions read RFC 3414 and 3415.

Regards,
Frank

Vivi Zhang wrote:
Let me resend the email.

The previous email content was in an attachment. It did not show up in SNMP4j email archives.


========================================================================
=====================
Hi,

I would really appreciate any help to find a way to remove an SNMP community string .
I am using SNMP4j 1.9.3c, and SNMP4j agent 1.2.1d.

I have no problem to add more community string to a running SNMP agent. But, when I have not been successfully remove a community
string.
Following is a section of code which initializes community mib and other mibs.

       vacmMIB = new VacmMIB(new MOServer[] { server });
       snmpTargetMIB = new SnmpTargetMIB(dispatcher);
       snmpNotificationMIB = new SnmpNotificationMIB();
     *  snmpCommunityMIB = new SnmpCommunityMIB(snmpTargetMIB);*
       this.getServer().addContext(DEFAULTCONTEXT);
       initConfigMIB();
       notificationOriginator = new
NotificationOriginatorImpl(session,
vacmMIB,
snmpv2MIB.getSysUpTime(), snmpTargetMIB, snmpNotificationMIB);
       snmpv2MIB.setNotificationOriginator(notificationOriginator);

Following is a section of code which add a community string to community MIB

       Variable[] com2sec = new Variable[] {
new OctetString(aCommunity), SECNAMEV1V2, getContextEngineID(), DEFAULTCONTEXT,
               new OctetString(), // transport tag
               new Integer32(StorageType.nonVolatile), // storage
type
               new Integer32(RowStatus.active) // row status
       };

MOTableRow row = communityMIB.getSnmpCommunityEntry().createRow(index,


com2sec);
       communityMIB.getSnmpCommunityEntry().addRow(row);

To remove all community strings, I tried following code:
MOMutableTableModel comEntryModel = (MOMutableTableModel)communityMIB.getSnmpCommunityEntry().getModel();
  comEntryModel .clear();

After this call, I expect all community rows are gone, and all SNMP queries should fail. But this does not happen.

I also try to remove an individual community string using API call
communityMIB.getSnmpCommunityEntry().removeRow(index); where index is

a valid OID for a community string.
In both cases, the row is removed, but the event did not fired since moTableModelListeners == null.
public synchronized MOTableRow removeRow(OID index) {
   *MOTableRow row = (MOTableRow) rows.remove(index);*
   if ((row != null) && (moTableModelListeners != null)) {
     MOTableModelEvent event =
        new MOTableModelEvent(this, MOTableModelEvent.ROW_REMOVED,
row);
     fireTableModelChanged(event);
   }
   return row;
 }

After the calls, I am still able to query the snmp agent with "removed" community string.

Wonder if it is expected behavior. Or I need config the TableModelListeners for SnmpCommunityEntry table.
Please advise.

Vivi
_______________________________________________
SNMP4J mailing list
[email protected]
http://lists.agentpp.org/mailman/listinfo/snmp4j



------------------------------

_______________________________________________
SNMP4J mailing list
[email protected]
http://lists.agentpp.org/mailman/listinfo/snmp4j


End of SNMP4J Digest, Vol 59, Issue 18
**************************************



_______________________________________________
SNMP4J mailing list
[email protected]
http://lists.agentpp.org/mailman/listinfo/snmp4j

Reply via email to