4 Replies Latest reply on Sep 7, 2010 7:20 AM by 843798

    How to work with snmp agent


      I have generated the java codes for my MIB, using mibgen. Then I wanted to create stand alone snmp agent and for it I used
      manual at page: [http://docs.sun.com/app/docs/doc/806-6633/6jfih895m?l=all&a=view|http://docs.sun.com/app/docs/doc/806-6633/6jfih895m?l=all&a=view]
      First I tried html adaptor, and it worked.
      But the main point of my work is to write agent which is able to answer standard snmp commands, as:
      snmpget -v 2c -c public localhost name.0

      So my code for stand alone snmp agent is:
      public class Agent {
           static SnmpAdaptorServer snmpAdaptor = null;
           private static int nbTraps = -1;
           public static void main(String args[]) {
           try {
                     // The agent is started on a non standard SNMP port: 8085
                     int port = 161;
                     port = 1161; // 8085;
                     snmpAdaptor = new SnmpAdaptorServer(port);
                     // Start the adaptor
                     // Send a coldStart SNMP Trap
                     snmpAdaptor.setTrapPort(new Integer(port + 1));
                     snmpAdaptor.snmpV1Trap(0, 0, null);
                     // Create the MIB you want in the agent (ours is MIB-II subset)
                     MODEM_MIB mib2 = new MODEM_MIB();
                     // Initialize the MIB so it creates the associated MBeans
                     System.out.println("Initialization of mib");
                     // Bind the MIB to the SNMP adaptor
                } catch (Exception e) {
      This code is without error, therefore I can run it in console. But I don't know whether there is not neccessary to add some code (as settings of IP addres, community, and so on).

      I use net-snmp master on my machine, and I want to bind this java agent to it. Then I could write command:
      snmpget -v 2c -c public localhost name.0

      and the stand alone agent will give response.

      Is it something neccessary to add to the agent code? How can I find, whether agent responsed to a request?

      I am a newbie in this scope, and I am sorry for my English :)

      Thank you very much for advice.


      Edited by: srnka on Sep 2, 2010 5:16 AM
        • 1. Re: How to work with snmp agent

          What you need to do is to fill in the getters & setters of the skeletons generated by mibgen, so that they access (get & set) the real data.
          If your mib contains tables, then you also need to populate these tables by instantiating table entries and adding them to the tables.
          What mibgen generates is just a glue between the SNMP protocol and a bean-like representation of the mib structure. In other words: it generates an empty MIB. Your job is to fill the generated MIB with the real data that you want the agent to return.

          I'm not sure you will be able to bind your agent to the net-snmp master, unless the net-snmp master supports pure SNMP sub agents.
          JDMK does only support SNMP, and does not support snmpdx. To answer this question you will have to look at the net-snmp documentation.

          Hope this helps,

          -- daniel
          • 2. Re: How to work with snmp agent
            Hi Daniel,

            thank you for your response, I will fill the getters and setters of my MIB variables.

            But how can I try this agent? Which command should I use to try whether is it working?

            Thank you
            • 3. Re: How to work with snmp agent

              From your code it looks as if you are binding your agent to port 1161
                             port = 1161; // 8085;
                             snmpAdaptor = new SnmpAdaptorServer(port);
              In that case you can just use the net snmp client commands (snmpget/snmpwalk) to query your agent - just make sure to specify that the requests should be sent to the port the agent is listening on (1161 here).

              hope this helps,

              -- daniel
              • 4. Re: How to work with snmp agent

                thank you for response and help.

                I have solved this problem. The agent responses to snmpget, snmpset requests.

                Only what was necessary, was to set the snmpd.conf in net-snmp to support proxy agent:

                proxy -c public -v 2c  localhost:1161  [oid of subtree agent is working with]
                Restart snmp daemon, start agent, check whether it is waiting on port (*netcat -a |grep 1161*). Something like:
                udp        0      0 *:8086                  *:*   
                There shouldn't be any unix socket on this port!

                The command:
                 snmpget -v 2c -c public localhost [some-oid.0]
                should work in snmp version 2c

                Maybe this will help somebody.