ServiceMix SNMP

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

Maven Archetype

You can use Maven servicemix-snmp-service-unit archetype to create a SNMP service unit:

mvn archetype:create \
  -DarchetypeGroupId=org.apache.servicemix.tooling \
  -DarchetypeArtifactId=servicemix-snmp-service-unit \
  -DarchetypeVersion=2010.01 \
  -DgroupId=your.group.id \
  -DartifactId=your.artifact.id \
  -Dversion=your-version

Once you've customized the service unit, simply install the SU:

mvn install

Remember that to be deployable in ServiceMix, the ServiceUnit has to be embedded in a Service Assembly: only the Service Assembly zip file can be deployed in ServiceMix.
To add your SU in a SA, you need to define it in the dependency sets:

<dependency>
  <groupId>your.group.id</groupId>
  <artifactId>your.artifact.id</artifactId>
  <version>your-version</version>
</dependency>

Endpoints Configuration

Poller Endpoint (Consumer)

The SNMP Poller endpoint periodically poll a SNMP server to get event and generate messages sent to the NMR.

The SNMP Poller endpoint will only generate InOnly exchanges.

Poller (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" />

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"

Trap Consumer Endpoint

The SNMP Trap Consumer endpoint waits for incoming SNMP messages.

Trap consumer endpoint
<snmp:trap-consumer service="test:mySNMPService"
             endpoint="trapConsumerEndpoint"
             targetService="test:myProcessor"
             address="udp:192.168.2.122/162" />

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

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

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.

  • No labels