[SNMP4J] Receiving SNMP response from the server

Vishal Sahu vishal at intelligrape.com
Fri May 21 13:04:18 CEST 2010


Hi,

I am new to SNMP. In my project i  have a requirement to send a snmp message
if there is any exception on the server machine .
Eg:- email sending failed

I have implemented the code for sending a INFORM to the server if there is
any exception.




        OctetString securityName = new OctetString("MD5DES")
        Address targetAddress = GenericAddress.parse(<some-url>);
        TransportMapping transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        USM usm = new USM(SecurityProtocols.getInstance(), new
OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport.listen();


        OctetString octetStringMD5DESUserPrivPassword = new
OctetString("MD5DESUserPrivPassword")

        UsmUser usmUser = new UsmUser(securityName, null, null, PrivDES.ID,
octetStringMD5DESUserPrivPassword)
        snmp.getUSM().addUser(securityName,usmUser);

        UserTarget target = new UserTarget()
        target.setAddress(targetAddress)
        target.setRetries(1)
        target.setTimeout(5000)
        target.setVersion(SnmpConstants.version3)
        target.setSecurityName(securityName)

        PDU pdu = new ScopedPDU();
        pdu.add(new VariableBinding(new OID('1.3.6.1.2.1.2.1')))
        pdu.setType(PDU.INFORM);

        ResponseEvent response = snmp.send(pdu, target)
        response.getResponse()



The code sends the message & receives the response.
Response is :-  REPORT[reqestID=1839467505, errorStatus=0, errorIndex=0,
VBS[1.3.6.1.6.3.15.1.1.3.0 = 39]]


Now i want to do 2 things:-

1. How to check on snmp server that the request has been received & if
received then what is the request.
2. I want to receive the response(or any string) fron SNMP server. How to do
that.


Any help would be appreciated.


Thanks & Regards
Vishal



More information about the SNMP4J mailing list