Yes, we are going to implement a SNMP trap receiver in less than 30 minutes. If you have been following my post on Apache MINA, this would be a natural extension to it. In this article, we shall bring together all our components to build the system.
Please read through these articles. You can find all these posts on Apache MINA
- What is Apache MINA
- Apache MINA based Server Application Architecture
- Implementing UDP Server using Apache MINA
- Implementing SNMP4J Decoder for Apache MINA
To execute the code, you need following jars
I am assuming that you have read my previous posts and jumping straight to the implementations. The high level architecture is explained in the post Apache MINA based Server Application Architecture
Let’s understand the flow here and see what all we need to do to process a trap
- Receive the trap over UDP
- Decode the Trap
- Dump the Trap
Lets see how each of the these maps to the code we have already written
It’s a now simple to understand that we have reused all the components to create the Server. Let me not write too much, and jump straight to the code J
The Server Code
The only change that we did to the UDP Server code was to add a Protocol Codec. At line 36, we added our custom ProtocolCodecFiler. The SNMPCodecFactory return the instance of our SNMP4J codec. There is not much code and this construct is fairly simple, and explained very well in MINA’s documentation. From the main method, we just need to call the method initialize() and our trap receiver starts.