[SNMP4J] Agent Notification Example
Prusi, Jesse R
jesse.r.prusi at lmco.com
Wed Apr 5 23:27:57 CEST 2006
My problem was that I was using SNMP4J-Agent v1.0-alpha1. I switched to
v1.0-alpha2 in which the BaseAgent class includes a
notificationOriginator (not local to the init() method). I can now use
the following code in the TestAgent class:
notificationOriginator.notify(new OctetString(),
SnmpConstants.coldStart,
new VariableBinding[0]);
Thanks,
Jesse
-----Original Message-----
From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org] On
Behalf Of Prusi, Jesse R
Sent: Wednesday, April 05, 2006 10:44 AM
To: Frank Fock
Cc: snmp4j at agentpp.org
Subject: RE: [SNMP4J] Agent Notification Example
Frank,
Here is what I did to send a trap from the TestAgent class:
1) I set the NotificationOriginator in the finishInit() method of
BaseAgent.
protected void finishInit(VacmMIB vacmMIB, SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB,
NotificationOriginator notificationOriginator)
{
agent.addMOServer(server);
addViews(vacmMIB);
addNotificationTargets(targetMIB, notificationMIB);
agent.setNotificationOriginator(notificationOriginator); // ADDED
agent.setVacm(vacmMIB);
dispatcher.addCommandResponder(agent);
notificationOriginator.notify(new OctetString(),
SnmpConstants.coldStart,
new VariableBinding[0]);
}
2) I added a simple method in TestAgent to send a trap
// ADDED
public void sendTrap(){
agent.notify(new OctetString(),
SnmpConstants.coldStart,
new VariableBinding[0]);
}
3) I called the sendTrap() method from main() in TestAgent
testAgent1.run();
testAgent1.sendTrap(); // ADDED
Is this a good approach? Is there an easier way to send traps from
TestAgent without having to modifiy BaseAgent?
Thanks,
Jesse
-----Original Message-----
From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org] On
Behalf Of Prusi, Jesse R
Sent: Tuesday, April 04, 2006 4:56 PM
To: Frank Fock
Cc: snmp4j at agentpp.org
Subject: RE: [SNMP4J] Agent Notification Example
The NotificationOriginator in the BaseAgent is local to the init()
method. I think it would make sense to call setNotificationOriginator()
from the init() method of BaseAgent. This would allow you to call
agent.notify() from a class that extends BaseAgent. Or is there another
way to do this that I'm not seeing?
Thanks,
Jesse
-----Original Message-----
From: Frank Fock [mailto:fock at agentpp.com]
Sent: Tuesday, April 04, 2006 4:47 PM
To: Prusi, Jesse R
Cc: snmp4j at agentpp.org
Subject: Re: [SNMP4J] Agent Notification Example
Jesse,
Creating a single NotificationOriginator(Impl) is enough.
The BaseAgent already has one. To send a notification call for example:
notificationOriginator.notify(new OctetString(),
SnmpConstants.coldStart,
new VariableBinding[0]);
Best regards,
Frank
Prusi, Jesse R wrote:
> Can someone please give an example for sending notifications from an
> agent? Does a new NotificationOriginator need to be created for each
> notification message?
>
> Thanks,
> Jesse
> _______________________________________________
> 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
_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j
_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j
More information about the SNMP4J
mailing list