<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ashish's Tech Blog &#187; SNMP4J</title>
	<atom:link href="http://www.ashishpaliwal.com/blog/tag/snmp4j/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ashishpaliwal.com/blog</link>
	<description>From Programmer, For Programmers</description>
	<lastBuildDate>Tue, 17 Aug 2010 12:04:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Implementing Trap Sender using SNMP4J</title>
		<link>http://www.ashishpaliwal.com/blog/2008/10/implementing-trap-sender-using-snmp4j/</link>
		<comments>http://www.ashishpaliwal.com/blog/2008/10/implementing-trap-sender-using-snmp4j/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 06:56:06 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Application Programming]]></category>
		<category><![CDATA[Network Programming]]></category>
		<category><![CDATA[Apache MINA]]></category>
		<category><![CDATA[SMP]]></category>
		<category><![CDATA[SNMP4J]]></category>
		<category><![CDATA[Trap Sender]]></category>

		<guid isPermaLink="false">http://www.ashishpaliwal.com/blog/?p=176</guid>
		<description><![CDATA[In this post, we shall implement a Trap Sender using SNMP4J. We may choose to use Apache MINA for sending Traps or can resort to using DatagramSocket class directly. This shall be the logical flow of the implementation Get the encoded Trap Data Send the Trap  Lets look at the first component, on getting the [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, we shall implement a Trap Sender using SNMP4J. We may choose to use Apache MINA for sending Traps or can resort to using DatagramSocket class directly.</p>
<p>This shall be the logical flow of the implementation</p>
<ul>
<li>Get the encoded Trap Data</li>
<li>Send the Trap </li>
</ul>
<div>Lets look at the first component, on getting the encoded Trap data</div>
<p> </p>
<div><a href="http://www.ashishpaliwal.com/blog/wp-content/uploads/2008/10/trapdata.png"><img class="aligncenter size-full wp-image-178" title="trapdata" src="http://www.ashishpaliwal.com/blog/wp-content/uploads/2008/10/trapdata.png" alt="" width="500" height="224" /></a></div>
<p>The code snippet above shows a simple way of creating and encoding a Trap PDU. Essentially, we create an instance of PDU class and sets the type as Trap. This is important, else SNMP4J shall throw an exception. Thereafter, we can set the trap parameters. Here, we have hardcoded the parameters, there can be custom implementations that can take these from config files or from UI. After setting the parameters, we just call the encode function passing the Output stream and collect the byte array to be sent.</p>
<div>Sending part is even simpler     </p>
<div><a href="http://www.ashishpaliwal.com/blog/wp-content/uploads/2008/10/sendtrap.png"><img class="aligncenter size-full wp-image-179" title="sendtrap" src="http://www.ashishpaliwal.com/blog/wp-content/uploads/2008/10/sendtrap.png" alt="" width="500" height="83" /></a></div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6961884887741817";
/* 468x15LinkUnit */
google_ad_slot = "4400881690";
google_ad_width = 468;
google_ad_height = 15;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></p>
<p>The send code is preety straight forward. Here we have used Datagram Socket, we can use Apache MINA UDP Client implementation to send the trap as well.</p>
<div>References</div>
<div>
<ul>
<li><a href="http://www.snmp4j.org/">http://www.snmp4j.org/</a></li>
<li><a href="http://www.ashishpaliwal.com/blog/2008/10/implementing-udp-client-using-apache-mina/">Implementing UDP Client using Apache MINA</a> </li>
</ul>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.ashishpaliwal.com/blog/2008/10/implementing-trap-sender-using-snmp4j/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Implementing SNMP4J Decoder for Apache MINA</title>
		<link>http://www.ashishpaliwal.com/blog/2008/10/implementing-snmp4j-decoder-for-apache-mina/</link>
		<comments>http://www.ashishpaliwal.com/blog/2008/10/implementing-snmp4j-decoder-for-apache-mina/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 14:01:40 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Apache MINA]]></category>
		<category><![CDATA[Application Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Network Management]]></category>
		<category><![CDATA[SNMP]]></category>
		<category><![CDATA[SNMP4J]]></category>

		<guid isPermaLink="false">http://www.ashishpaliwal.com/blog/?p=10</guid>
		<description><![CDATA[Recently started evaluating Apache MINA. So thought about building a Trap Receiver using Apache MINA. Refer to one of my posting on What is Apache MINA? Design In this post we shall concentrate on just writing the ProtocolDecoder The code snippet using SNMP4J library is public class SNMP4JCodec extends ProtocolDecoderAdapter { static Logger logger = LoggerFactory.getLogger(SNMP4JCodec.class); [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Recently started evaluating Apache MINA. So thought about building a Trap Receiver using Apache MINA. Refer to one of my posting on <a href="http://www.ashishpaliwal.com/blog/2008/09/11/what-is-apache-mina/">What is Apache MINA?</a></p>
<div><span><strong>Design</strong></span></div>
<div><a href="http://3.bp.blogspot.com/_1X9TSfIQfXM/SMkET4LY59I/AAAAAAAAAC8/CbVNzkPENvo/s1600-h/snmp4jcodec.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5244727980593833938" class="aligncenter" src="http://3.bp.blogspot.com/_1X9TSfIQfXM/SMkET4LY59I/AAAAAAAAAC8/CbVNzkPENvo/s320/snmp4jcodec.JPG" border="0" alt="" /></a></div>
<div>In this post we shall concentrate on just writing the ProtocolDecoder</div>
<div>The code snippet using SNMP4J library is</div>
<div>
<pre class="brush: java">
public class SNMP4JCodec extends ProtocolDecoderAdapter {

 static Logger logger = LoggerFactory.getLogger(SNMP4JCodec.class);

 public void decode(IoSession ioSession, IoBuffer ioBuffer,
                    ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
     ByteBuffer pduBuffer = ioBuffer.buf();
     // Decode the bytes using SNMP4J API&#039;s
     PDU pdu = new PDU();
     try {
         BERInputStream berStream = new BERInputStream(pduBuffer);
         BER.MutableByte mutableByte = new BER.MutableByte();
         int length = BER.decodeHeader(berStream, mutableByte);
         int startPos = (int)berStream.getPosition();

         if (mutableByte.getValue() != BER.SEQUENCE) {
           String txt = &quot;SNMPv2c PDU must start with a SEQUENCE&quot;;
           throw new IOException(txt);
         }
         Integer32 version = new Integer32();
         version.decodeBER(berStream);

         // decode community string
         OctetString securityName = new OctetString();
         securityName.decodeBER(berStream);

         // decode the remaining PDU
         pdu.decodeBER(berStream);
         logger.debug(&quot;PDU - &quot;+pdu);
     } catch (Exception ex) {
         ex.printStackTrace();
     }
     protocolDecoderOutput.write(pdu);
 }
}
</pre>
<p>The code converts ByteBuffer into an SNMP PDU using SNMP4J  library. Similarly, we can use Adventnet or joesnmp to convert the byte stream into SNMP PDU's</p>
<p>NOTE: Custome Error handling need to be implemented, as per the strategy</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ashishpaliwal.com/blog/2008/10/implementing-snmp4j-decoder-for-apache-mina/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
