Getting Started
SNMP for Spring can be used directly, integrating with
Spring using XML configuration files or using
JDK 1.5 annotations.
This quick guide shows you examples of each technique.
Downloaded binaries include sample applications.
Stand alone application
- Make sure you are using Java version 1.4 and above.
- Place the spring-snmp jar into your classpath.
- Ensure that any libraries required to satisfy
dependencies are also in the classpath.
- Create an instance of SnmpAgent.
- Assign read-only/read-write communities (used as passwords in SNMP). Defaults are "public"/"public".
- Assign handled OID prefixes. SNMP request with OIDs starting from other prefixes
are forwarded to the next agent in the chain (if such agent is defined).
- If you'd like your agent to report mib2 system properties (OID:
1.3.6.1.2.1),
then create an instance of Mib2System and pass it to SnmpAgent.
- Create a set of MibEntiries. Each entry defines a property of your object
that will be exposed using SNMP.
- If you'd like to forward unknown SNMP request to another agent, then create and configure
an instance of SnmpClient.
- Start the agent.
Please see our sample stand alone application
JvmStatSnmpAgentStandalone.java
exposing POJO
JvmStatStandalone.java.
Spring application (using XML)
- Make sure you are using Java version 1.4 and above.
- Place the spring-snmp jar into your classpath.
- Ensure that any libraries required to satisfy
dependencies are also in the classpath.
- Create spring XML configuration file (e.g. applicationContext.xml)
and configure your beans, SNMP agent, MibEntries, etc. The concept is the same
as in stand alone application. Note that snmpAgent bean should have
init-method="start" in order to start the agent upon context creation.
Please see our sample spring application
JvmStatSnmpAgentSpring.java
configured in applicationContext.xml exposing bean
JvmStatSpring.java.
Spring application (using annotations)
- Make sure you are using Java version 1.5 and above.
- Place the spring-snmp jar into your classpath.
- Ensure that any libraries required to satisfy
dependencies are also in the classpath.
- Annotate your beans using @MibBean and @MibProperty.
- Create spring XML configuration file (e.g. applicationContext.xml)
and define your beans, SNMP agent and MibAnnotationsProcessor,
which inspects all spring bean and automatically creates appropriate MibEntries.
Note that snmpAgent bean should have init-method="start" in order
to start the agent upon context creation.
Please see our sample annotated spring application
JvmStatSnmpAgentSpringAnnotated.java
configured in applicationContextAnnotations.xml exposing bean
JvmStatAnnotated.java.