<?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>logIt &#187; perl</title>
	<atom:link href="https://lakm.us/logit/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>https://lakm.us/logit</link>
	<description>Log Around The Clock</description>
	<lastBuildDate>Sat, 06 Jun 2015 14:17:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Running Raddle (2): snmpd &amp; Replay Custom Private Enterprise MIB</title>
		<link>https://lakm.us/logit/2011/08/running-raddle-2-snmpd-replay-custom-private-enterprise-mib/</link>
		<comments>https://lakm.us/logit/2011/08/running-raddle-2-snmpd-replay-custom-private-enterprise-mib/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 03:13:44 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[General Linux]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[emulator]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[snmp]]></category>

		<guid isPermaLink="false">http://lakm.us/logit/?p=217</guid>
		<description><![CDATA[Net-SNMP wiki gives tutorial on extending snmpd using Perl. In basic run of Raddle (previous post) this involves r1.pl called by r1.conf fed to snmpd. Private enterprise MIB i.e. Microchip&#8217;s in this example can be replayed without really ever captured the real device&#8217;s SNMP data. This is necessary when the actual device is yet existed; normal [...]]]></description>
				<content:encoded><![CDATA[<p>Net-SNMP wiki gives tutorial on 	<a href="http://www.net-snmp.org/wiki/index.php/Tut:Extending_snmpd_using_perl">extending <code>snmpd</code> using Perl</a>. In basic run of Raddle (<a href="./215/running-raddle-in-rhel/">previous post</a>) this involves <code>r1.pl</code> called by <code>r1.conf</code> fed to <code>snmpd</code>. Private enterprise MIB i.e. <a href="http://read.pudn.com/downloads133/sourcecode/embed/567121/TCPIP%20Demo%20App/mchip.mib__.htm" target="_blank">Microchip&#8217;s </a>in this example can be replayed without really ever captured the real device&#8217;s SNMP data. This is necessary when the actual device is yet existed; normal situation when developing.  There are two simple ways of replaying this artificial SNMP data over which either way requires correct OID.</p>
<p>First put the <code>Microchip.TXT</code> (the MIB file) under <code>/usr/share/snmp/mibs</code> to easily exchange OID canonical form and name vice versa while making dummy. In this case I&#8217;ve modify the MIB to have some additional object i.e. <code>name</code>:<br />
<code>$ snmptranslate -m +Microchip -On Microchip::name<br />
.1.3.6.1.4.1.17095.1.1</code><br />
so we can then use this correct OID for our dummy.</p>
<p>How?</p>
<ol>
<li>use <code>SetMIBValue()</code> in <code>r1.pl</code>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$agent</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">SetMIBValue</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">'.1.3.6.1.4.1.17095.1.1'</span><span style="color: #339933;">,</span> ASN_OCTET_STR<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Microchip&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$agent</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">SetMIBValue</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">'.1.3.6.1.4.1.17095.3.13'</span><span style="color: #339933;">,</span> ASN_INTEGER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">82</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>Feed <code>r1.snmp </code>for playing as in

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$agent</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">ParseDataFile</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">'/usr/local/etc/snmp-emulator/r1.snmp'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span></pre></div></div>

<p>with the content of</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.1.3.6.1.4.1.17095.1.1 = STRING: Microchip
.1.3.6.1.4.1.17095.3.13 = INTEGER: <span style="color: #000000;">82</span></pre></div></div>

</li>
</ol>
<p>In all above two examples we can only <code>GET</code> for Raddle to return an answer for each OID. <code>GETNEXT</code> as in bulk <code>snmpwalk</code> won&#8217;t give output because they are not sequenced.</p>
<p>A sample of sequenced data inside a real <code>snmpwalk</code> dump is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ snmpwalk <span style="color: #660033;">-v</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-c</span> public <span style="color: #660033;">-On</span> localhost
&nbsp;
.1.3.6.1.2.1.1.1.0 = STRING: Linux xp-racy 2.6.38-<span style="color: #000000;">10</span>-generic <span style="color: #666666; font-style: italic;">#46~lucid1-Ubuntu SMP Wed Jul 6 18:40:11 UTC 2011 i686</span>
.1.3.6.1.2.1.1.2.0 = OID: .1.3.6.1.4.1.8072.3.2.10
.1.3.6.1.2.1.1.3.0 = Timeticks: <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">496371</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1</span>:<span style="color: #000000;">22</span>:<span style="color: #000000;">43.71</span>
.1.3.6.1.2.1.1.4.0 = STRING: Root  <span style="color: #7a0874; font-weight: bold;">&#40;</span>configure <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>snmp<span style="color: #000000; font-weight: bold;">/</span>snmpd.local.conf<span style="color: #7a0874; font-weight: bold;">&#41;</span>
.1.3.6.1.2.1.1.5.0 = STRING:
.1.3.6.1.2.1.1.6.0 = STRING: Unknown <span style="color: #7a0874; font-weight: bold;">&#40;</span>configure <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>snmp<span style="color: #000000; font-weight: bold;">/</span>snmpd.local.conf<span style="color: #7a0874; font-weight: bold;">&#41;</span>
.1.3.6.1.2.1.1.8.0 = Timeticks: <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">0</span>:00:<span style="color: #000000;">00.00</span>
.1.3.6.1.2.1.1.9.1.2.1 = OID: .1.3.6.1.6.3.10.3.1.1
.1.3.6.1.2.1.1.9.1.2.2 = OID: .1.3.6.1.6.3.11.3.1.1</pre></div></div>

<p>thus, we can only</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ snmpget <span style="color: #660033;">-m</span> +Microchip <span style="color: #660033;">-v</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-c</span> public localhost Microchip::control.13
Microchip::control.13 = INTEGER: <span style="color: #000000;">82</span></pre></div></div>

<p>or from other system with no Microchip MIB use</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ snmpget <span style="color: #660033;">-v</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-c</span> public 192.168.40.105 .1.3.6.1.4.1.17095.3.13
SNMPv2-SMI::enterprises.17095.3.13 = INTEGER: <span style="color: #000000;">82</span></pre></div></div>

<p>The tree below may visually explains sequenced data for <code>GETNEXT</code> where our Microchip is branched at <code>private.enterprises.microchip</code> :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ snmptranslate <span style="color: #660033;">-m</span> +Microchip <span style="color: #660033;">-Tp</span>
&nbsp;
+--iso<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   <span style="color: #000000; font-weight: bold;">|</span>
   +--org<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
      <span style="color: #000000; font-weight: bold;">|</span>
      +--dod<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
         <span style="color: #000000; font-weight: bold;">|</span>
         +--internet<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">|</span>
            +--directory<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">|</span>
            +--mgmt<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>
            <span style="color: #000000; font-weight: bold;">|</span>  +--mib-<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">|</span>     <span style="color: #000000; font-weight: bold;">|</span>
            <span style="color: #000000; font-weight: bold;">|</span>     +--system<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">|</span>     <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>
...
            +--private<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>
...
            <span style="color: #000000; font-weight: bold;">|</span>  +--enterprises<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">|</span>     <span style="color: #000000; font-weight: bold;">|</span>
...
            <span style="color: #000000; font-weight: bold;">|</span>     +--microchip<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">17095</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">|</span>        <span style="color: #000000; font-weight: bold;">|</span>
            <span style="color: #000000; font-weight: bold;">|</span>        +--product<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">|</span>        <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span></pre></div></div>

<p>How <code>GET</code> and <code>GETNEXT</code> appeared in SNMP can be viewed by running snmpd in debug mode with this options:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ snmpd <span style="color: #660033;">-m</span> +Microchip <span style="color: #660033;">-f</span> <span style="color: #660033;">-L</span> <span style="color: #660033;">-V</span> <span style="color: #660033;">-C</span> <span style="color: #660033;">-I</span> vacm_vars <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>snmp-emulator<span style="color: #000000; font-weight: bold;">/</span>r1.conf
NET-SNMP version 5.3.1
Connection from UDP: <span style="color: #7a0874; font-weight: bold;">&#91;</span>127.0.0.1<span style="color: #7a0874; font-weight: bold;">&#93;</span>:<span style="color: #000000;">32770</span>
Received SNMP packet<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> from UDP: <span style="color: #7a0874; font-weight: bold;">&#91;</span>127.0.0.1<span style="color: #7a0874; font-weight: bold;">&#93;</span>:<span style="color: #000000;">32770</span>
  GET message
    <span style="color: #660033;">--</span> control.13</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>https://lakm.us/logit/2011/08/running-raddle-2-snmpd-replay-custom-private-enterprise-mib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running Raddle in RHEL</title>
		<link>https://lakm.us/logit/2011/08/running-raddle-in-rhel/</link>
		<comments>https://lakm.us/logit/2011/08/running-raddle-in-rhel/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 07:43:05 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[General Linux]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[emulator]]></category>
		<category><![CDATA[install-deinstall]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[red hat]]></category>
		<category><![CDATA[snmp]]></category>

		<guid isPermaLink="false">http://lakm.us/logit/?p=215</guid>
		<description><![CDATA[Raddle is a great SNMP player written in Perl. I say player to this emulator application, meaning that I can append or dump snmpwalk output from a device and then replay that from Raddle. Installing it can be both simple and tedious tasks. I used Red Hat Enterprise Linux 5.2 inside a virtual machine (VirtualBox) [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://raddle.sourceforge.net/" target="_blank">Raddle</a> is a great SNMP player written in Perl. I say player to this emulator application, meaning that I can append or dump <code>snmpwalk</code> output from a device and then replay that from Raddle. Installing it can be both simple and tedious tasks. I used Red Hat Enterprise Linux 5.2 inside  a virtual machine (VirtualBox) to make it compact without interfering my own host <code>snmpd</code> setting.</p>
<p>net-SNMP packages are required for Raddle to work on top of primarily <code>snmpd</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #c20cb9; font-weight: bold;">install</span> net-snmp net-snmp-utils</pre></div></div>

<p>Prior to installation some rpm packages must be downloaded separately as my local repo (created from original RHEL CD images) may not contain them. They are installed as follow:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rpm <span style="color: #660033;">-i</span> perl-Carp-Clan-<span style="color: #000000;">6.00</span>-1.el4.rf.noarch.rpm
rpm <span style="color: #660033;">-i</span> perl-Bit-Vector-<span style="color: #000000;">6.4</span>-2.el5.rf.i386.rpm
rpm <span style="color: #660033;">-i</span> perl-Crypt-DES-<span style="color: #000000;">2.05</span>-3.2.el5.rf.i386.rpm
rpm <span style="color: #660033;">-i</span> perl-Digest-SHA1-<span style="color: #000000;">2.11</span>-1.el5.rf.i386.rpm
rpm <span style="color: #660033;">-i</span> perl-Digest-HMAC-<span style="color: #000000;">1.01</span>-2.2.el5.rf.noarch.rpm
rpm <span style="color: #660033;">-i</span> perl-Socket6-<span style="color: #000000;">0.20</span>-1.el5.rf.i386.rpm
rpm <span style="color: #660033;">-i</span> perl-Net-SNMP-5.2.0-1.2.el5.rf.noarch.rpm
rpm <span style="color: #660033;">-i</span> perl-Date-Pcalc-<span style="color: #000000;">1.2</span>-1.2.el5.rf.noarch.rpm
rpm <span style="color: #660033;">-i</span> perl-Date-Calc-<span style="color: #000000;">5.4</span>-1.el5.rf.i386.rpm</pre></div></div>

<p>continued by installing <code>net-snmp-perl</code> from original repo</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #c20cb9; font-weight: bold;">install</span> net-snmp-perl</pre></div></div>

<p>Uncompressing Raddle and successful <code>make test</code> will mean installation is good and can be finished by <code>make install</code></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> Net-Raddle-<span style="color: #000000;">0.08</span>
<span style="color: #c20cb9; font-weight: bold;">perl</span> Makefile.PL
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<h1>Replaying SNMP Packets</h1>
<p>The idea is to run <code>snmpd</code> which replays a specific prepared-SNMP-packets instead of our own real time system SNMP data (in this case the condition of RHEL 5.2 host). There are three files to do that, let&#8217;s name them <code>r1.*</code>:</p>
<ol>
<li><code>r1.snmp</code><br />
A capture from i.e.<br />
<code>snmpwalk -v 1 -c &lt;community string&gt; -OneU &lt;device&gt; &gt; r1.snmp</code></li>
<li><code>r1.conf</code><br />
<code>snmpd</code> will run this instead of the original OS default:<br />
<code>snmpd -C -I vacm_vars -c /usr/local/etc/snmp-emulator/r1.conf</code></li>
<li><code>r1.pl</code><br />
the perl script where the most basic is to just replay the above <code>r1.snmp</code></li>
</ol>
<p>An official documentation to replay SNMP can be found <a href="http://raddle.sourceforge.net/docs/SNMPAgent.html" target="_blank">here</a>. I got hold back when trying to listen from other host, it turns out that I must remove the localhost section in <code>r1.conf</code> which will make it to use standard port 161 as well</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Listen on port 9501</span>
<span style="color: #666666; font-style: italic;">#agentaddress    udp:localhost:9501,tcp:localhost:9501</span></pre></div></div>

<p>It is also wise to always cut the <code>r1.snmp</code> first to see if the perl works (test with <code>perl -w /usr/local/etc/snmp-emulator/r1.pl</code>) either with warning or clean, meaning no problem with just some of the OIDs found inside the file.</p>
]]></content:encoded>
			<wfw:commentRss>https://lakm.us/logit/2011/08/running-raddle-in-rhel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
