com.jpragma.snmp
Class SnmpAgent

java.lang.Object
  extended by com.jpragma.snmp.SnmpAgent
All Implemented Interfaces:
java.lang.Runnable

public class SnmpAgent
extends java.lang.Object
implements java.lang.Runnable

Snmp agent listens to snmp requests (get, getnext, set), invokes appropriate handler and returns snmp response. Default port is 161. Typical usage:

  1. Create instance of SnmpAgent
  2. Optionally set default properties (listening port, snmp communities)
  3. Set handled oid prefixes
  4. Create an instance of Mib2System, set its properties and bind to snmp agent
  5. Create mib entries, specifying oids and corresponding handlers
  6. Optionally create proxy to another snmp agent (instance of SnmpClient)
  7. Start the agent

It is strongly recommended to set up the agent using Spring framework. Examples of both standard and annotated spring configurations are included in documentation.

Author:
Isaac Levin

Constructor Summary
SnmpAgent()
           
 
Method Summary
 java.lang.String[] getHandledOidPrefixes()
           
 int getListeningPort()
           
 Mib2System getMib2System()
           
 java.lang.String getReadOnlyComunity()
           
 java.lang.String getReadWriteComunity()
           
 void run()
           
 void setHandledOidPrefixes(java.lang.String[] handledOidPrefixes)
          Sets the list of OID prefixes served by this agent.
 void setListeningPort(int listeningPort)
          Sets the port this agent is listening to.
 void setMib2System(Mib2System mib2System)
          Sets the object containing properties to serve mib2 system (1.3.6.1.2.1) subtree.
 void setMibEntries(java.util.Set mibEntrySet)
          Sets the list MIB entries served by this agent.
 void setProxySnmpClient(SnmpClient proxySnmpClient)
           
 void setReadOnlyComunity(java.lang.String readOnlyComunity)
          Sets read-only community.
 void setReadWriteComunity(java.lang.String readWriteComunity)
          Sets read-write community.
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnmpAgent

public SnmpAgent()
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

setMibEntries

public void setMibEntries(java.util.Set mibEntrySet)
Sets the list MIB entries served by this agent. Each entry contains OID, Object and its property from which the response should be constructed, and type of the variable to be returned.

Parameters:
mibEntrySet - mib entries

getListeningPort

public int getListeningPort()
Returns:
the port this agent is listening to

setListeningPort

public void setListeningPort(int listeningPort)
Sets the port this agent is listening to. Port 161 is used by default.

Parameters:
listeningPort - listening port

getReadOnlyComunity

public java.lang.String getReadOnlyComunity()
Returns:
read-only community

setReadOnlyComunity

public void setReadOnlyComunity(java.lang.String readOnlyComunity)
Sets read-only community. In SNMPv1 read-only community is used as a password to serve snmpget and snmpgetnext requests.

Parameters:
readOnlyComunity - read-only community

getReadWriteComunity

public java.lang.String getReadWriteComunity()
Returns:
read-write community

setReadWriteComunity

public void setReadWriteComunity(java.lang.String readWriteComunity)
Sets read-write community. In SNMPv1 read-write community is used as a password to serve snmpset requests.

Parameters:
readWriteComunity - read-write community

getMib2System

public Mib2System getMib2System()
Returns:
the object containing properties to serve mib2 system (1.3.6.1.2.1) subtree

setMib2System

public void setMib2System(Mib2System mib2System)
Sets the object containing properties to serve mib2 system (1.3.6.1.2.1) subtree.

Parameters:
mib2System - object describing system properties

getHandledOidPrefixes

public java.lang.String[] getHandledOidPrefixes()
Returns:
OID prefixes served by this agent.

setHandledOidPrefixes

public void setHandledOidPrefixes(java.lang.String[] handledOidPrefixes)
Sets the list of OID prefixes served by this agent.

Parameters:
handledOidPrefixes - array of oid prefixes e.g. ["1.3.6.1.2.1","1.3.6.1.4.1.28824"]

setProxySnmpClient

public void setProxySnmpClient(SnmpClient proxySnmpClient)

start

public void start()

stop

public void stop()