ServiceMix SNMP

The ServiceMix SNMP component provides support for receiving SNMP events via the enterprise service bus by using the SNMP4J library.

Availability

Note that this component is only available in releases >= 3.3.

Installation

Installing the servicemix-snmp component can be done in several ways:

  • drop the installer zip in an hotdeploy directory monitored by ServiceMix
  • using ant tasks

Note that when using ant tasks, the component is not started, you will have to start it manually using ant tasks or a console.

Creation

You can use Maven to create a service unit.

mvn archetype:create \
    -DarchetypeGroupId=org.apache.servicemix.tooling \
    -DarchetypeArtifactId=servicemix-snmp-service-unit \
    -DgroupId=com.mycompany.myproduct \
    -DartifactId=mycomponent.artifact

Endpoints

Polling (consumer) endpoint
<snmp:poller service="test:mySNMPService"
             endpoint="pollerEndpoint"
             targetService="test:myProcessor"
             period="10000"
             address="udp:192.168.2.122/161"
             oids="classpath:myOIDList.txt" />
Trap consumer endpoint
<snmp:trap-consumer service="test:mySNMPService"
             endpoint="trapConsumerEndpoint"
             targetService="test:myProcessor"
             address="udp:192.168.2.122/162" />

Consumer Endpoint (Polling)

Message Exchange Pattern

The poller endpoint will only generate InOnly exchanges.

The following table shows the additional configuration possibilities of the endpoint other than the configuration of the default PollingEndpoint class.

Poller endpoint attributes
Name Type Description Default
oids OIDList sets the resource containing all OIDs to poll null (must be spec'd)
address String the address to use for snmp connection null (must be spec'd)
marshaler class org.apache.servicemix.snmp.marshaler.SnmpMarshalerSupport DefaultSnmpMarshaler
retries int the retries for requesting the values via snmp 2
timeout long the timeout in millis for a request to be answered 1500
snmpVersion int the snmp version to use (see SnmpConstants) 0 (v1)
snmpCommunity String the snmp community "public"

 
 

The "oids" list

You can specify here a comma separated list of OIDs or just reference to a resource containing a list of OIDs separated by line feeds.

Using a file inside class path
<snmp:poller service="test:mySNMPService"
             endpoint="pollerEndpoint"
             targetService="test:myProcessor"
             period="10000"
             address="udp:192.168.2.122/161"
             oids="classpath:myOIDList.txt" />
Specifying OIDs directly
<snmp:poller service="test:mySNMPService"
             endpoint="pollerEndpoint"
             targetService="test:myProcessor"
             period="10000"
             address="udp:192.168.2.122/161"
             oids="1.3.6.1.2.1.1.3.0 , 1.3.6.1.2.1.25.3.2.1.5.1 , 1.3.6.1.2.1.25.3.5.1.1.1 , 1.3.6.1.2.1.43.5.1.1.11.1" />

The address

The address has to be specified in the following way:

 
Template: <protocol>:<ip-address>/<port>

Example:  udp:192.168.2.122/161

Poller endpoint attributes
Name Description
protocol the protocol to use (udp / tcp)
ip-address the ip address of the device to poll from
port the port number

 
 

Trap Consumer Endpoint

The trap consumer endpoint waits for incoming SNMP messages.

Poller endpoint attributes
Name Type Description Default
address String the address to use for snmp connection null (must be spec'd)
marshaler class org.apache.servicemix.snmp.marshaler.SnmpMarshalerSupport DefaultSnmpMarshaler

 
 

Provider Endpoint (Sending)

Availability

There is no sender endpoint yet.

For all xbean file endpoint configuration take a look at Xml schemas

Marshalers

You can write your own marshalers for conversion between snmp and normalized message.
To do this you simply need to implement the org.apache.servicemix.snmp.marshaler.SnmpMarshalerSupport interface or by creating a subclass of the DefaultSnmpMarshaler if you do not want to start from scratch.

The SnmpMarshalerSupport interface

For providing your own marshaler you only need to implement a single method:

convertToJBI(...)

This method is responsible for translating a received snmp response into a jbi compliant normalized message ready to be sent to the bus.

After finishing your marshaler you can simply configure your endpoints to use it:

Marshaler example
<snmp:poller service="test:mySNMPService"
             endpoint="pollerEndpoint"
             targetService="test:myProcessor"
             period="10000"
             address="udp:192.168.2.122/161"
             oids="classpath:myOIDList.txt">

    <property name="marshaler">
        <bean class="com.mycompany.MySNMPMarshaler" />
    </property>

</snmp:poller>

How does the DefaultSnmpMarshaler work?

Given the situation, that I provide a file like this:

myOIDList.txt
1.3.6.1.2.1.1.3.0
1.3.6.1.2.1.25.3.2.1.5.1
1.3.6.1.2.1.25.3.5.1.1.1
1.3.6.1.2.1.43.5.1.1.11.1

The result will be the following:

Result of DefaultSnmpMarshaler
<?xml version="1.0" encoding="UTF-8"?>
<snmp>
  <entry>
    <oid>1.3.6.1.2.1.1.3.0</oid>
    <value>6 days, 21:14:28.00</value>
  </entry>
  <entry>
    <oid>1.3.6.1.2.1.25.3.2.1.5.1</oid>
    <value>2</value>
  </entry>
  <entry>
    <oid>1.3.6.1.2.1.25.3.5.1.1.1</oid>
    <value>3</value>
  </entry>
  <entry>
    <oid>1.3.6.1.2.1.43.5.1.1.11.1</oid>
    <value>6</value>
  </entry>
  <entry>
    <oid>1.3.6.1.2.1.1.1.0</oid>
    <value>My Very Special Printer Of Brand Unknown</value>
  </entry>
</snmp>

As you maybe recognized there is one more result than requested....1.3.6.1.2.1.1.1.0.
This one is filled in by the device automatically in this special case. So it may absolutely happen, that you receive more than you requested...be prepared.