<?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>tech notes &#187; python</title>
	<atom:link href="http://bsd.dischaos.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://bsd.dischaos.com</link>
	<description>just some random notes on BSDs, linux and web development</description>
	<lastBuildDate>Fri, 07 May 2010 10:18:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Graphing Alteon configuration</title>
		<link>http://bsd.dischaos.com/2009/08/31/graphing-alteon-configuration/</link>
		<comments>http://bsd.dischaos.com/2009/08/31/graphing-alteon-configuration/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 22:15:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[other]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=126</guid>
		<description><![CDATA[If you happen to use Nortel&#8217;s Alteon load balancers and need something to help you visualise your configuration here&#8217;s a script that produces graphs of connections and dependencies between groups, virtual IPs, real IPs and services in the Alteon configuration. It&#8217;s not very useful, the code is ugly, but the graphs are cool to look [...]]]></description>
			<content:encoded><![CDATA[<p>If you happen to use Nortel&#8217;s Alteon load balancers and need something to help you visualise your configuration <a href="http://bsd.dischaos.com/files/graph_gen.py">here&#8217;s a script</a> that produces graphs of connections and dependencies between groups, virtual IPs, real IPs and services in the Alteon configuration. It&#8217;s not very useful, the code is ugly, but the graphs are cool to look at <img src='http://bsd.dischaos.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Especially for huge config files with lots of services and VIPs. The script uses two great python libraries &#8211; <a href="http://code.google.com/p/python-graph/">pygraph</a> and <a href="http://www.graphviz.org/Resources.php">graphviz</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/08/31/graphing-alteon-configuration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting all prefixes advertised by an AS</title>
		<link>http://bsd.dischaos.com/2009/07/22/getting-all-prefixes-advertised-by-an-as/</link>
		<comments>http://bsd.dischaos.com/2009/07/22/getting-all-prefixes-advertised-by-an-as/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 21:33:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[other]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[as]]></category>
		<category><![CDATA[ripe]]></category>
		<category><![CDATA[whois]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=116</guid>
		<description><![CDATA[This simple script displays all prefixes advertised by an AS. It uses RIPE&#8217;s looking glass to get their local BGP table and parses it for the given AS number.
For example, to get all the other networks advertised by the AS dischaos.com is in, first I need to get Layered tech&#8217;s AS number:
whois -h www.ris.ripe.net 216.32.74.94

% [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bsd.dischaos.com/files/getprefixes.py">This simple script</a> displays all prefixes advertised by an AS. It uses RIPE&#8217;s looking glass to get their local BGP table and parses it for the given AS number.</p>
<p>For example, to get all the other networks advertised by the AS dischaos.com is in, first I need to get Layered tech&#8217;s AS number:</p>
<p>whois -h www.ris.ripe.net 216.32.74.94</p>
<blockquote><p>
% This is RIPE NCC&#8217;s Routing Information Service<br />
% whois gateway to collected BGP Routing Tables<br />
% IPv4 or IPv6 address to origin prefix match<br />
%<br />
% For more information visit http://www.ripe.net/ris/riswhois.html</p>
<p>route:        216.0.0.0/8<br />
origin:       AS3303<br />
descr:        SWISSCOM Swisscom (Switzerland) Ltd<br />
lastupd-frst: 2009-06-08 11:31Z  192.65.185.243@rrc04<br />
lastupd-last: 2009-06-08 11:31Z  192.65.185.243@rrc04<br />
seen-at:      rrc04<br />
num-rispeers: 1<br />
source:       RISWHOIS</p>
<p>route:        216.32.0.0/14<br />
origin:       AS3561<br />
descr:        SAVVIS &#8211; Savvis<br />
lastupd-frst: 2009-06-08 12:56Z  198.32.160.22@rrc11<br />
lastupd-last: 2009-07-22 12:06Z  195.69.145.49@rrc03<br />
seen-at:      rrc00,rrc01,rrc03,rrc04,rrc06,rrc07,rrc10,rrc11,rrc12,rrc13,rrc15,rrc16<br />
num-rispeers: 86<br />
source:       RISWHOIS</p>
<p>route:        216.32.64.0/19<br />
origin:       AS22576<br />
descr:        LAYER3-ASN &#8211; Layered Technologies, Inc.<br />
lastupd-frst: 2009-06-08 12:56Z  198.32.160.22@rrc11<br />
lastupd-last: 2009-07-22 14:55Z  193.232.244.147@rrc13<br />
seen-at:      rrc00,rrc01,rrc03,rrc04,rrc06,rrc07,rrc10,rrc11,rrc12,rrc13,rrc15,rrc16<br />
num-rispeers: 85<br />
source:       RISWHOIS</p>
</blockquote>
<p>Their AS number is 22576. Now lets see what other networks they advertise:</p>
<blockquote><p>
$ ./getprefixes.py 22576<br />
networks advertised by AS22576:<br />
64.92.160.0/20<br />
72.21.32.0/19<br />
72.36.128.0/17<br />
72.232.0.0/17<br />
72.232.128.0/19<br />
72.232.160.0/21<br />
72.232.168.0/22<br />
72.232.172.0/23<br />
72.232.174.0/23<br />
72.232.176.0/20<br />
72.232.192.0/18<br />
72.233.0.0/19<br />
72.233.28.0/22<br />
72.233.32.0/19<br />
72.233.64.0/18<br />
72.233.64.0/20<br />
72.233.80.0/23<br />
72.233.82.0/23<br />
72.233.84.0/23<br />
72.233.86.0/23<br />
72.233.88.0/21<br />
72.233.96.0/22<br />
72.233.100.0/22<br />
72.233.104.0/21<br />
72.233.112.0/21<br />
72.233.120.0/21<br />
72.233.127.0/24<br />
208.95.152.0/22<br />
209.67.208.0/20<br />
216.32.64.0/19
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/07/22/getting-all-prefixes-advertised-by-an-as/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nagios plugin template in python</title>
		<link>http://bsd.dischaos.com/2009/04/29/nagios-plugin-template-in-python/</link>
		<comments>http://bsd.dischaos.com/2009/04/29/nagios-plugin-template-in-python/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 08:49:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[bsd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://bsd.dischaos.com/?p=95</guid>
		<description><![CDATA[A template for nagios plugins I use:

#!/usr/bin/env python
import sys, getopt
nagios_codes = &#123;&#8216;OK&#8217;: 0, 
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#8216;WARNING&#8217;: 1, 
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#8216;CRITICAL&#8217;: 2,
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#8216;UNKNOWN&#8217;: 3,
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#8216;DEPENDENT&#8217;: 4&#125;
def usage&#40;&#41;:
&#160; &#160; &#34;&#34;&#34; returns [...]]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://bsd.dischaos.com/files/nagios_plugin.py">template for nagios plugins</a> I use:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">#!/usr/bin/env python</span></p>
<p><span class="kw1">import</span> <span class="kw3">sys</span>, <span class="kw3">getopt</span></p>
<p>nagios_codes = <span class="br0">&#123;</span><span class="st0">&#8216;OK&#8217;</span>: <span class="nu0">0</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;WARNING&#8217;</span>: <span class="nu0">1</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;CRITICAL&#8217;</span>: <span class="nu0">2</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;UNKNOWN&#8217;</span>: <span class="nu0">3</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;DEPENDENT&#8217;</span>: <span class="nu0">4</span><span class="br0">&#125;</span></p>
<p><span class="kw1">def</span> usage<span class="br0">&#40;</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="st0">&quot; returns nagios status UNKNOWN with <br />
&nbsp; &nbsp; &nbsp; &nbsp; a one line usage description<br />
&nbsp; &nbsp; &nbsp; &nbsp; usage() calls nagios_return()<br />
&nbsp; &nbsp; &quot;</span><span class="st0">&quot;&quot;</span><br />
&nbsp; &nbsp; nagios_return<span class="br0">&#40;</span><span class="st0">&#8216;UNKNOWN&#8217;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;usage: {0} -h host&quot;</span>.<span class="me1">format</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></p>
<p><span class="kw1">def</span> nagios_return<span class="br0">&#40;</span><span class="kw3">code</span>, response<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="st0">&quot; prints the response message<br />
&nbsp; &nbsp; &nbsp; &nbsp; and exits the script with one<br />
&nbsp; &nbsp; &nbsp; &nbsp; of the defined exit codes<br />
&nbsp; &nbsp; &nbsp; &nbsp; DOES NOT RETURN <br />
&nbsp; &nbsp; &quot;</span><span class="st0">&quot;&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">print</span> <span class="kw3">code</span> + <span class="st0">&quot;: &quot;</span> + response<br />
&nbsp; &nbsp; <span class="kw3">sys</span>.<span class="me1">exit</span><span class="br0">&#40;</span>nagios_codes<span class="br0">&#91;</span><span class="kw3">code</span><span class="br0">&#93;</span><span class="br0">&#41;</span></p>
<p><span class="kw1">def</span> check_condition<span class="br0">&#40;</span>host<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="st0">&quot; a dummy check<br />
&nbsp; &nbsp; &nbsp; &nbsp; doesn&#8217;t really check anything <br />
&nbsp; &nbsp; &quot;</span><span class="st0">&quot;&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#123;</span><span class="st0">&quot;code&quot;</span>: <span class="st0">&quot;OK&quot;</span>, <span class="st0">&quot;message&quot;</span>: host + <span class="st0">&quot; ok&quot;</span><span class="br0">&#125;</span></p>
<p><span class="kw1">def</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&quot;&quot;</span><span class="st0">&quot; example options processing<br />
&nbsp; &nbsp; &nbsp; &nbsp; here we&#8217;re expecting 1 option &quot;</span>-h<span class="st0">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; with a parameter<br />
&nbsp; &nbsp; &quot;</span><span class="st0">&quot;&quot;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="kw2">len</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#41;</span> &lt; <span class="nu0">2</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; usage<span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">try</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; opts, args = <span class="kw3">getopt</span>.<span class="kw3">getopt</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">1</span>:<span class="br0">&#93;</span>, <span class="st0">&quot;h:&quot;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">except</span> <span class="kw3">getopt</span>.<span class="me1">GetoptError</span>, err:<br />
&nbsp; &nbsp; &nbsp; &nbsp; usage<span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">for</span> o, value <span class="kw1">in</span> opts:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> o == <span class="st0">&quot;-h&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; host = value<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; usage<span class="br0">&#40;</span><span class="br0">&#41;</span></p>
<p>&nbsp; &nbsp; result = check_condition<span class="br0">&#40;</span>host<span class="br0">&#41;</span><br />
&nbsp; &nbsp; nagios_return<span class="br0">&#40;</span>result<span class="br0">&#91;</span><span class="st0">&#8216;code&#8217;</span><span class="br0">&#93;</span>, result<span class="br0">&#91;</span><span class="st0">&#8216;message&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span></p>
<p><span class="kw1">if</span> __name__ == <span class="st0">&quot;__main__&quot;</span>:<br />
&nbsp; &nbsp; main<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bsd.dischaos.com/2009/04/29/nagios-plugin-template-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
