The ServiceMix SNMP component provides support for receiving SNMP events via the enterprise service bus by using the SNMP4J library.
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.
|
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. |
<snmp:poller service="test:mySNMPService" endpoint="pollerEndpoint" targetService="test:myProcessor" period="10000" address="udp:192.168.2.122/161" oids="classpath:myOIDList.txt" /> |
|
The SNMP Trap Consumer endpoint waits for incoming SNMP messages.
<snmp:trap-consumer service="test:mySNMPService" endpoint="trapConsumerEndpoint" targetService="test:myProcessor" address="udp:192.168.2.122/162" /> |
|
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.
<snmp:poller service="test:mySNMPService" endpoint="pollerEndpoint" targetService="test:myProcessor" period="10000" address="udp:192.168.2.122/161" oids="classpath:myOIDList.txt" /> |
<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 has to be specified in the following way:
Template: <protocol>:<ip-address>/<port> Example: udp:192.168.2.122/161 |
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.
For providing your own marshaler you only need to implement a single method:
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:
<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> |
Given the situation, that I provide a file like this:
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:
<?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.