Writing SNMP Manager using SNMP4J



Hello,

I am writing a SNMP Manager that is supposed to do the following:
(1) Send snmp commands to snmp-agents, and handle thier response.
(2) Receive snmp traps from snmp-agents.

I am using SNMP4J software package for writing the snmp manager.

I would like to use a SINGLE Snmp object (SNMP4J object) , both
for sending a snmp command and for receiving snmp traps.

So far, I have written two separate programs:

****************
*** Program 1:
****************
** The first program only listens for Snmp trap-PDUs.
** Its main code is as follows:

// configure Snmp object
UdpAddress address = new UdpAddress("127.0.0.1/1990");
TransportMapping transport = new DefaultUdpTransportMapping(address);
Snmp snmp = new Snmp(transport);
transport.listen();

// handle received traps here
CommandResponder trapPrinter = new CommandResponder() {
public synchronized void processPdu(CommandResponderEvent e) {
PDU command = e.getPdu();
if (command != null) {
System.out.println(command.toString());
}
}
};
snmp.addCommandResponder(trapPrinter);



****************
*** Program 2:
****************
** The second program sends GET PDUs, and its main code is as follows:

// configure Snmp object
UdpAddress targetAddress = new UdpAddress("127.0.0.1/1985");
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(10000); // was 1000 !!!
target.setVersion(SnmpConstants.version1);
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();

// prepare the PDU for sending
PDU command = new PDU();
command.setType(PDU.GET);
command.add(new VariableBinding(new
OID("1.3.6.1.4.1.1331.11.5.1.0")));

// now send the PDU
ResponseEvent responseEvent = snmp.send(pdu, target);
if (responseEvent != null)
{
// response has arrived. handle it
}
else
System.out.println("null response received...");


*******************************************************************

I would like to unite these two programs into one, however, I cannot
seem to
properly allocate one Snmp object to handle both the sending and
receiving of PDUs.

I run two threads: thread-1 that does the listening for snmp traps,
and thread-2 which in charge of sending get/set PDUs.

I allocate the Snmp object in one place as follows:

TransportMapping transport = new DefaultUdpTransportMapping(new
UdpAddress("127.0.0.1/1990"));
Snmp snmp = new Snmp(transport);
snmp.listen();

and I transfer it to both threads to be used there.
However, thread-2 sometimes fails to send PDUs using snmp.send(...);


What am I doing wrong?
Can anyone guide me as for how I should allocate the Snmp object so
it is good for both sending PDUs, and for receving traps?

Thanks,
Tsiyona

.



Relevant Pages

  • Re: How do I get the port on a switch that a PC is connected to.
    ... With SNMP there are two distinct concepts. ... "the command tcpConnLocalPort" - you ... If the switch maintains this information, you are in luck and you can ... The advantage of this method is you can directly get the port of the ...
    (comp.protocols.snmp)
  • Re: SNMP in rails
    ... net/snmp library for ruby and get and set methods of ... I'm guessing that the first snmpset command is used to reset port status ... The second command snmpget is used to read port reset status. ... I am using snmp library of ruby but need to pass the snmpset php ...
    (comp.lang.ruby)
  • Re: SNMP with PB 4.2 - test sample not being built ?
    ... Because if I add it there my platform nk.bin will not be ... >Basically what you're missing is snmp_snmptestmib showing ... >other SNMP components? ... Did also a command like ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Doubt regarding adding a row in table using SNMPv2
    ... without the intervention of a manager. ... It seems like your understanding of what an SNMP agent does ... If an "SNMP agent" is doing things that are not in response ...
    (comp.protocols.snmp)
  • Re: Question regarding SNMP GET Response PDU
    ... This all depends on which version of the SNMP protocol you're using. ... If you are using an SNMP toolkit which has a smart manager API, ... which he will receive a succesful response containing these two values. ... It can be either noSuchInstance or noSuchObject - refer to ...
    (comp.protocols.snmp)