Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking requests that come in through SNMP

Tags:

snmp

snmp4j

So I'm still in the process of learning SNMP, please go easy. I'm using snmp4j, not just the libraries but I've loaded the source code and I'm not against modifying the source if it gets me what I need. I've programmed an agent and a test client. What I want to do is be able to check the requests coming in from the test client and specifically listening for a "set" request to a specific OID.

The current way I'm thinking about doing it is catching the request right after it runs the snmp4j method fireProcessMessage (located in the package org.snmp4j.transport.DefaultUdpTranportMapping) but I don't know how an agent queries its own mib for an oid. Is there a method that the agent uses to get OID values from its mib?

Or Is there a better way to catch a specific SET request? Is it even possible to do what I want? Basically what I want to do is run another process if the client sets a certain OID value to 1(true).

like image 226
Otra Avatar asked Dec 22 '22 10:12

Otra


1 Answers

It can be done by extending the CommandProcessor and implementing RequestHandler

like i have done

public class SNMPRequestProcessor extends CommandProcessor
{

SetHandler setHandler = new SetHandler ();

public SNMPRequestProcessor()
{
    //Your code
}


@Override
protected void processRequest(CommandResponderEvent command, CoexistenceInfo cinfo, RequestHandler handler)
{

    synchronized (command) {
        if (command.getPDU().getType() == PDU.SET) {
            super.processRequest(command, cinfo, setHandler);
        }

        super.processRequest(command, cinfo, handler);
    }

}

/**
 * Handler for process set request which update to the database
 * 
 */

class SetHandler implements RequestHandler
{

    @Override
    public boolean isSupported(int mode)
    {
        return mode == PDU.SET;
    }

    @Override
    public void processPdu(Request request, MOServer server)
    {
                 //your code
    }
}

}
like image 190
Nikhil Avatar answered Jan 14 '23 16:01

Nikhil