<?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>jeremykendall.net &#187; att</title>
	<atom:link href="http://www.jeremykendall.net/tag/att/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeremykendall.net</link>
	<description>{web developer, entrepreneur }</description>
	<lastBuildDate>Fri, 23 Jul 2010 19:18:30 +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>DIY Network Monitoring and Logging with Perl</title>
		<link>http://www.jeremykendall.net/2009/10/27/network-monitoring-and-logging-with-perl/</link>
		<comments>http://www.jeremykendall.net/2009/10/27/network-monitoring-and-logging-with-perl/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 04:12:17 +0000</pubDate>
		<dc:creator>Jeremy Kendall</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[att]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.jeremykendall.net/?p=223</guid>
		<description><![CDATA[The Problem
I&#8217;ve been having trouble with my AT&#038;T DSL installation here at the new place.  My internet connection will come and go, seemingly at random, and for random amounts of time.  I tweeted about it once already, hoping that sharing my frustration with the world might make me feel a little better.  [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The Problem</strong></p>
<p>I&#8217;ve been having trouble with my AT&#038;T DSL installation here at the new place.  My internet connection will come and go, seemingly at random, and for random amounts of time.  I <a href="http://twitter.com/JeremyKendall/status/5193232511">tweeted about it</a> once already, hoping that sharing my frustration with the world might make me feel a little better.  Nope.  Didn&#8217;t work.</p>
<p>I&#8217;ve had this problem before with AT&#038;T, when I got DSL installed at my last place.  Things were rough for a while, and then somehow they seemed to straighten out on their own.  I&#8217;m not crossing my fingers that I&#8217;ll have such luck again.</p>
<p><strong>What&#8217;s Really Going On?</strong></p>
<p>I decided to try and log the bounces so that I could get a better feel for what was going on.  I couldn&#8217;t find exactly what I wanted online (and I couldn&#8217;t always get online), so I whipped up a <a href="http://en.wikipedia.org/wiki/Perl">Perl</a> script to keep an eye on my connection for me.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Test AT&amp;T DSL connectivity. If network is down, log to file</span>
<span style="color: #666666; font-style: italic;"># Will use log info as ammo when I call tech support.</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Log<span style="color: #339933;">::</span><span style="color: #006600;">Handler</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">Ping</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Sys<span style="color: #339933;">::</span><span style="color: #006600;">HostIP</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$log</span> <span style="color: #339933;">=</span> Log<span style="color: #339933;">::</span><span style="color: #006600;">Handler</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">add</span><span style="color: #009900;">&#40;</span>
    file <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>
        filename <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;/var/log/testNetwork.log&quot;</span><span style="color: #339933;">,</span>
        mode     <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;append&quot;</span><span style="color: #339933;">,</span>
        maxlevel <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;info&quot;</span><span style="color: #339933;">,</span>
        minlevel <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;warning&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ipAddress</span>          <span style="color: #339933;">=</span> Sys<span style="color: #339933;">::</span><span style="color: #006600;">HostIP</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">ip</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$matchHomeNetworkIp</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ipAddress</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/^192\.168\.10\.\d{1,3}$/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #0000ff;">$matchHomeNetworkIp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Current IP $ipAddress does not appear to be on your home network. Exiting&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$router</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;192.168.10.1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$modem</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;192.168.1.254&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$host</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;www.yahoo.com&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$p</span> <span style="color: #339933;">=</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">Ping</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;icmp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #0000ff;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">ping</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$router</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">warning</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Router $router is unreachable. Exiting.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #0000ff;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">ping</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$modem</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">warning</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Modem $modem is unreachable. Exiting.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">ping</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$host</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">info</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$host is reachable&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">warning</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$host is NOT reachable&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Code Review</strong></p>
<p>While the code is simple, there are a couple of things to note.  First, you&#8217;ll notice I&#8217;ve baked my router&#8217;s IP range into a <a href="http://en.wikipedia.org/wiki/Regular_expressions">regex</a> that will tell me if I can even get that far.  If not, there&#8217;s no point in checking anything else, so I exit.</p>
<p>Next I fire up <a href="http://search.cpan.org/~smpeters/Net-Ping-2.36/lib/Net/Ping.pm">Net::Ping</a>.  While there are six different options for Net::Ping->new(), the only one that worked for me was icmp.  Icmp requires root privileges to run, so keep that in mind. </p>
<p>Next I <a href="http://en.wikipedia.org/wiki/Ping">ping</a> important parts of the home network.  I want to be sure that my wireless router and the DSL modem are both online before I try and ping an external site.</p>
<p>If everything looks good on the inside, I&#8217;ll ping an external site and see if I get anything back.  You&#8217;ll notice that I&#8217;ve added a second parameter to ping this time.  That&#8217;s the number of seconds I&#8217;ll wait for a response before failing (of course, it is possible that Yahoo! won&#8217;t respond to a ping request here and there, making it appear as if the network is down, but I&#8217;m not so worried about a false positive or two).</p>
<p><strong>Implementation</strong></p>
<p>Now that I&#8217;ve got this nifty script to tell me about the health of my network, I need a way to run it on a regular basis.  It&#8217;s important to run it as root because of the icmp ping.  <a href="http://en.wikipedia.org/wiki/Cron">Cron</a> was the obvious solution, as it&#8217;s purpose is to run commands on a predetermined schedule. As long as I add the script to root&#8217;s cron file, it&#8217;ll run with root permissions.  Sweet!</p>
<p>Adding my script to the root cron file was as easy as issuing</p>

<div class="wp_syntax"><div class="code"><pre class="code" style="font-family:monospace;">sudo crontab -e</pre></div></div>

<p> and adding the following line:</p>

<div class="wp_syntax"><div class="code"><pre class="code" style="font-family:monospace;">*/1 * * * * perl /home/jkendall/dev/perl/util/testNetwork.pl</pre></div></div>

<p>With my cron file in place, my script fires off every minute.  As long as I&#8217;m on my home network, I&#8217;ll get a log entry telling me whether or not the network is up.</p>
<p><strong>Keeping an Eye on the Results</strong></p>
<p>Now that my script is actually doing something, I need to be able to parse the results.  A quick</p>

<div class="wp_syntax"><div class="code"><pre class="code" style="font-family:monospace;">tail -f /var/log/testNetwork.log</pre></div></div>

<p> allows me to keep track of the results as they come in.  I&#8217;m also using grep to pull all of the &#8220;NOT reachable&#8221; lines out of the log file with</p>

<div class="wp_syntax"><div class="code"><pre class="code" style="font-family:monospace;">grep -n --color &quot;NOT reachable&quot; /var/log/testNetwork.log</pre></div></div>

<p>  I could always just open the log file and read through it from top to bottom, but what fun is that?  A decent tool to parse the fail log is going to be necessary, but I haven&#8217;t whipped it up yet. </p>
<p><strong>Teh Suck</strong></p>
<p>As I&#8217;ve been writing this blog post, I&#8217;ve been running this script in the background.  Here are the results of an hour or so of logging (all times are CDT):</p>

<div class="wp_syntax"><div class="code"><pre class="code" style="font-family:monospace;">Oct 27 21:03:33 [INFO] www.yahoo.com is reachable
Oct 27 21:04:03 [WARNING] Router 192.168.10.1 is unreachable. Exiting.
Oct 27 21:05:02 [INFO] www.yahoo.com is reachable
Oct 27 21:06:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:07:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:08:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:09:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:10:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:11:02 [INFO] www.yahoo.com is reachable
Oct 27 21:12:01 [INFO] www.yahoo.com is reachable
Oct 27 21:13:01 [INFO] www.yahoo.com is reachable
Oct 27 21:14:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:15:32 [INFO] www.yahoo.com is reachable
Oct 27 21:16:01 [INFO] www.yahoo.com is reachable
Oct 27 21:17:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:18:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:19:11 [INFO] www.yahoo.com is reachable
Oct 27 21:20:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:21:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:22:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:23:03 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:24:01 [INFO] www.yahoo.com is reachable
Oct 27 21:25:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:26:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:27:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:28:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:29:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:30:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:31:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:32:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:33:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:34:21 [INFO] www.yahoo.com is reachable
Oct 27 21:35:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:36:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:37:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:38:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:39:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:40:12 [INFO] www.yahoo.com is reachable
Oct 27 21:41:01 [INFO] www.yahoo.com is reachable
Oct 27 21:42:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:43:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:44:31 [INFO] www.yahoo.com is reachable
Oct 27 21:45:01 [INFO] www.yahoo.com is reachable
Oct 27 21:46:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:47:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:48:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:49:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:50:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:51:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:52:42 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:53:41 [WARNING] www.yahoo.com is NOT reachable
Oct 27 21:54:01 [INFO] www.yahoo.com is reachable</pre></div></div>

<p>Weak sauce, man.  Weak sauce.</p>
<p><strong>Wrapping Up</strong></p>
<p>Having this script handy doesn&#8217;t make the <a href="http://failblog.org/">fail</a> any better, but at least I know a little more about what&#8217;s happening.  I&#8217;d like to think it&#8217;ll give me some leverage when I try to get this worked out with AT&#038;T, but who knows.  I&#8217;ll let you know how it goes.</p>
<p>[<strong>Update</strong>: post title change to better reflect content]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremykendall.net/2009/10/27/network-monitoring-and-logging-with-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
