jeremykendall.net

Dear Piedmont Natural Gas: Updated

My wife and I recently moved to a suburb of Nashville, TN. Through no fault of our own, we had our natural gas service shut off yesterday and the provider, Piedmont Natural Gas, is refusing to restore our service until Tuesday, December 4. Here is my letter of complaint to Piedmont requesting that they make this right.

My wife and I moved to Hermitage, TN in late October 2012. She called to have natural gas service transferred into our name the week of October 22. Yesterday, November 30, our landlord got in touch with us to let us know the previous tenants had received a bill and we needed to touch base with you and take care of the problem. Which we did.

  • Here’s the payment confirmation number: 5752712
  • Here’s the line item from my checking account’s online system: 11/30/2012 Sign Debit* PIEDMONTNG/SPEEDPAY $70.15

But guess what? Our gas got cut off.

And guess what else? You won’t turn it back on until Tuesday, December 4th.

And guess what else? The representative my wife talked to yesterday afternoon told us the gas would not be cut off, that there wasn’t an appointment to have it cut off, and that everything was taken care of.

The best part? The gas was already cut off. Before we called. Before we were able to make payment. Through no fault of our own.

This is absolutely, completely and totally, 100% the fault of your company and your representatives at Piedmont Natural Gas.

It is wholly unacceptable that, after explaining our situation to your representative on the telephone this morning, you refuse to turn our gas back on.

You and I both know you have the ability to send a truck out and have our gas turned back on. You and I both know that you’ve done it for other customers in the past, and that you’ll do it for other customers in the future. I respectfully request that you do it for my wife and I now.

This one is on you. We did our part. Now do yours and make this right today.

Best,

Jeremy Kendall

Piedmont, the ball is in your court.

(I informed Piedmont that I would be making this complaint public here on my blog, and will update this post with both sides of the story as the situation unfolds.)

Update: Poor customer service with a positive result

Yesterday

By yesterday at 10 am CST, I had spoken to Piedmont customer service, sent them an email, written this blog post, and pinged them on both their Twitter account and their Facebook page. I kept an eye on my phone, email, and social networks all day, finally giving up around 5 pm. Finally, at 6:41 pm CST, almost three hours after Piedmont customer service closed for the weekend, I received this reply via Twitter:

Piedmont had six hours to touch base with us and resolve the problem. I pinged them in every possible way, making what I felt was a reasonable request for restoration of services. Rather than jumping on the problem and restoring our service, we were contacted after hours and told that customer service has been “made aware”. Thanks, but I’d already covered that one, and they won’t be open until Monday morning anyhow. Not impressed.

This morning

I didn’t sleep well last night, so I went down for a quick nap this morning. When I woke up, I had a missed call and voicemail from Charlotte, NC. The message was from Piedmont Natural Gas asking for a return call. As it turns out, they called Megan as well. After a day-and-a-half without service, Piedmont has promised to roll a truck and have our service turned back on.

I appreciate the extra effort they’ve taken to reach out to us on a Sunday, but I don’t appreciate having to fight for it. We’ll see if we get a truck this evening or not. I’ll let you know how it goes.

Update: Victory!

Our gas is back on and we’re happy with how this thing turned out. Please see my follow-up post, “Piedmont Natural Gas: Customer service WIN”, for the details.

Goofing Off With Unit Tests

[UPDATE: The library and test have been refactored. See the commit for full details.]

Sometime last year I saw a unit test for the song “Ice Cream Paint Job”.  I thought it was hilarious, and I hate I’ve never been able to find it again.  I liked it so much, in fact, I decided to write my own musical unit integration test.  Behold the MelissaTest, a short, simple test covering the main premise of “Melissa”. Bonus points for me: the test passes.  Enjoy.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

namespace MercyfulFate\Album\Melissa\Track;

use MercyfulFate\KingDiamond;
use MercyfulFate\Priest;
use MercyfulFate\Witch\Melissa as WitchMelissa;
use MercyfulFate\Album\Melissa\Track\Melissa as TrackMelissa;

class MelissaTest extends \PHPUnit_Framework_TestCase
{

    /**
     * @var MercyfulFate\KingDiamond
     */
    protected $king;

    /**
     * @var MercyfulFate\Priest
     */
    protected $priest;

    /**
     * @var MercyfulFate\Witch\Melissa
     */
    protected $witch;

    /**
     * @var MercyfulFate\Album\Melissa\Track\Melissa
     */
    protected $trackMelissa;

    protected function setUp()
    {
        $this->king = new KingDiamond();
        $this->priest = new Priest();
        $this->priest->attach($this->king);
        $this->witch = new WitchMelissa();
        $this->trackMelissa = new TrackMelissa($this->king, $this->witch, $this->priest);
    }

    protected function tearDown()
    {
        $this->trackMelissa = null;
    }

    public function testBurnMelissa()
    {
        $this->assertFalse($this->witch->isBurned());
        $this->assertFalse($this->king->swearsRevenge());

        $this->trackMelissa->priestBurnsWitch();

        $this->assertTrue($this->witch->isBurned());
        $this->assertTrue($this->king->swearsRevenge());
    }

}

Memphis PHP #3 - Presentation Slides and Example Code Included

We had a great time last night at Memphis PHP.  The turnout was great, it was fun meeting new folks and seeing old friends, and the conversations before and after the meeting were worth the drive to East Memphis.

I had a blast presenting “A Brief Introduction to Zend_Form.”  I love presenting, especially when the audience gets into the act, asking tons of good questions and laughing at my horrible jokes.  Thanks to all who showed up and for making Memphis PHP and last night’s event such a great success.

Slides and Example Code

As promised, I’ve posted “A Brief Introduction to Zend_Form” at SlideShare.  Included below are links to the example code on pastebin.

The best way to run the MVC example is to whip up a Zend Framework project and drop Example.php into /application/forms.  If you’re unfamiliar with how to get a Zend Framework project up and running, please see “From Zero to Zend Framework Project in 10 Minutes.”

Thanks to our Sponsors

Many thanks to Dave Barger of LunaWeb for kindly allowing us to use the LunaWeb offices for our meeting place, providing food, soda, and even beer.  Yup.  Free beer.  Not bad for our third event, eh?

Dave shared some information last night about his company, LunaWeb, some upcoming events, and some of their current and upcoming projects.  Here’s a list of the links that he referred to.

For your radars:

Big thanks to G2 Technology for helping us spread the word about Memphis PHP.  They work hard every month to promote our events, and I’m grateful to them for all they do.

Join Us

If you’re local to the Memphis area, visiting Memphis, or close enough to drive in, and you’re not a member of Memphis PHP, we’d love to have you join us.  Head over to MemphisPHP.org and join the group.  You’ll get announcements from the group, info about meetings, and be able to RSVP for events.  I look forward to meeting you at our next event.

Announcing Memphis PHP

It’s my pleasure to announce the formation of Memphis PHP, a PHP user group serving Memphis, TN and the mid-south.  The goal of Memphis PHP is to grow and nurture an active PHP community in the local area.  It’s going to take a lot of work to get Memphis PHP off the ground, but having an active community of PHP developers in Memphis is long overdue.  The hard work will be more than worth it, and I’m going to need your help to accomplish that goal.

My first exposure to the PHP community at large came when I attended ZendCon in 2008.  After getting a taste of what the PHP community had to offer, I was pretty bummed out that we didn’t have anything going in Memphis.  Attending ZendCon in ‘08 led to attending ZendCon in '09, Nashville’s excellent Big LAMP Camp event last November, and I just returned from the tek-X conference in Chicago.

One of my favorite sessions at this year’s tek-X was the Community Roundtable, “an all-star lineup of community members” discussing user groups: what they are, how to start them, and how to keep them going.  It was the Community Roundtable that finally convinced me enough was enough, that it was time to start a user group right here in Memphis, TN.

The Details

  • Memphis PHP will meet on the 4th Thursday of every month at 6:30pm (currently searching for a suitable location).
  • Memphis PHP uses Meetup.com for membership, event and meeting announcements, RSVPs, etc.
  • Our first event will be a road trip to Nashville on June 8th to visit the Nashville PHP user group.
  • Our first official meeting will be on June 24th, location and speaker/agenda TBA.
  • Follow @MemphisPHP on Twitter for community updates and the like.
    • If you’re on Twitter and would like to be added to the memphisPHP-devs list, let me know.
    • Our official hashtag is #memphisPHP.
  • Our general discussion group and mailing list is hosted at Google Groups
  • Employers and recruiters are more than welcome to post opportunities to our discussion list. Please read the guidelines for Posting Employment Opportunities first.

Welcome to Memphis PHP!  I hope you’ll join me in making Memphis PHP a huge success.

Big Thanks

Special thanks go out to the Community Roundtable panel (@DragonBe, @LornaJane, @rdohms, @ramsey, @CaseySoftware) at tek-X for direction and tips, Ben Ramsey of Nashville PHP for his guidance and support, and Chance Garcia for beating me to the punch.

I’d also like to thank Wes Hicks and the team at G2 Technology for offering to help spread the word about Memphis PHP and help find a meeting place.

My Top 5 Favorite Geek T-Shirts (That I Own)

I’m a sucker for t-shirts, have been all my life. My high school sweetheart gave me grief for always wearing t-shirt and jeans. During my college years, credit card companies found me an easy mark by offering free t-shirts in exchange for my John Hancock. When I go out with Charly I still use the old, tired, “I’ll put on my dress t-shirt” joke.

If I had the means, I would be the Imelda Marcos of bad-ass t-shirts. Since I’m not (yet) independently wealthy, I need to be selective, feeding my addiction with nothing but primo stuff. Selecting from the geek category, in no particular order, here are my top 5 favorite geek t-shirts of all time (that I own).

I’m Well Built

Atlassian makes a lot of really sweet software, stuff I use on a daily basis, both at the house and at the day job.  While I’ve never actually used Bamboo (that’s next on the project list), I dig the shirt for a couple of reasons.  First, I’m a fan of all the Atlassian products that I’ve used so far, and I’ve always had good experiences dealing with Atlassian support.  Second, while you can’t tell from the lame graphic, this is actually a really good looking shirt.  Third, not being particularly well built, I love wearing a shirt that says I am.  It reminds me of my old “Who needs hair with a body like this?” shirt I wore when I was 220lbs of out of shape slob.  Oh sweet, sweet juxtaposition.

Get yours here.

Mine

What can I say about this one? It was love at first sight.  The only way I could love it more is if it were an official Office Space Hawaiian shirt, which does not exist and would be another post anyhow.  The thing I can’t understand is how few people recognize the red Swingline stapler for what it is.  Last time I was traveling, the only guy that got the joke was a ticketing agent at the airport.   We both had a good laugh.  Everyone else just looked at us funny.

Get yours here.

fork you

I haven’t ever used Git, I’m not a fan of their marketing strategies (svn sucks! Whaa?), I’m irrationally prejudiced against Rails, but I still love this t-shirt.  Grey is a splash of color in my mostly black wardrobe, it features cool typography, short, punchy copy, and it’s got a spot on the back intended for a little DIY customization, Sharpie style.  Mine says “sucks."  Take that, Git. Har, har, har. Also, this is the shirt you want if you’re just angsty enough to want the world to fork off every once in a while, but not angsty enough to get yourself an FTW face tattoo (and I don’t mean "for the win”).

Get yours here.

SQL query

I picked this one up when I was working as a technical support rep, taking calls for 8 to 10 hours a day and hating my life.  While the tech support career path doesn’t generally leave one with a working knowledge of SQL, I was doing everything I could to teach myself to program so that I would never have to take another support call as long as I lived.  While that hasn’t quite worked out (I don’t take calls directly, but I live in JIRA), this shirt has remained hilarious and relevant from the first time I put it on.  Making jokes in code is like learning to swear in a foreign language, you can express your frustration about those around you without having to worry about being understood and a) getting punched in the jeans, b) getting fired, or c) getting punched in the jeans and then getting fired.  WARNING: when you start making jokes in code, you’ve crossed the line from earth person to geek.  There is no going back.

Get yours here.

Real Programmers Wear Corpsepaint

I grew up as a metal baby in the late 80s/early 90s, and I’ve never lost my taste for the hard stuff.  The combination of two of my great loves, heavy metal and computer programming, in one of my favorite mediums, the t-shirt, makes this an instant favorite. 

Fun fact: Although not widely known, corpse paint has been worn by computer programmers as early as the late 1960s.  It’s rumored that Kim Petersen, better known as King Diamond, was first exposed to corpse paint by some LISP) developers who were attending a mathematics conference in Denmark in the early 1970s.

Pro-tip: While real programmers wear do wear corpsepaint, real programmers do not wear nail studded gauntlets.  They’re a major contributing factor in repetitive stress injuries.

Get yours here.

Two More Apache Tweaks Required After Ubuntu 10.04 Upgrade

While I was troubleshooting why Apache stopped serving php apps from my home directory, I ran into two more annoyances that required attention. I figured I’d share them as well in case you run into them yourself.

Here’s what I saw when I reloaded Apache:

jkendall@san-diego:/etc/apache2$ sudo /etc/init.d/apache2 reload
  * Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri Apr 30 13:47:38 2010] [warn] NameVirtualHost *:80 has no VirtualHosts
                                                                                    [ OK ]

As you can see, Apache reloaded fine, but I don’t like seeing anything other than [ OK ] when I’m reloading my web server. Let’s tackle these one at a time.

Could not reliably determine the server’s fully qualified domain name

Why is Apache all of a sudden complaining about what’s worked for so long? I’m not sure exactly, but thankfully the fix was simple and easy. Simply adding “ServerName localhost” to /etc/apache2/httpd.conf took care of the first complaint (Big thanks to Mohamed Aslam for his clear instructions on how to get this fixed.).

NameVirtualHost *:80 has no VirtualHosts

The problem boiled down to having NameVirtualHost defined in more than one place. In my case, NameVirtualHost was defined both in /ect/apache2/ports.conf and /etc/apache2/sites-available/default. Commenting out the NameVirtualHost *:80 line in /etc/apache2/sites-available/default did the trick (Thanks to the guys in this Server Fault thread, especially to Ivan, for providing the necessary clues to track this one down.).

After making the above changes, reloading Apache didn’t throw any more warnings. w00t!

Upgrading to Ubuntu 10.04 Breaks Serving Php From Home Directories

I upgraded to Ubuntu 10.04 this morning and immediately noticed I could no longer serve php applications from my home directory. When I tried to visit one of my projects, http://test.local for example, Firefox opened a download dialog with a message similar to “You have chosen to open index.phtml …”

After quite a bit of googling and forum searching, I went to Twitter asking for help. Many thanks to @sypherNL for helping me resolve this one.

It seems that something has changed in /etc/apache2/mods-enabled/php5.conf. If you’re experiencing this same issue, check your php5.conf and see if it matches mine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    # To re-enable php in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_value engine Off
        </Directory>
    </IfModule>
</IfModule>

If your php5.conf file looks like the one above, simply comment out the <IfModule mod_userdir.c> lines as instructed. Once that’s done, restart apache with the following command:

1
sudo /etc/init.d/apache2 reload

Clear your browser’s cache and try to visit your site again. I didn’t think the fix took at first, but after clearing cache everything worked just fine.

Related Links

From Zero to Zend Framework Project in 10 Minutes

I first started working with the Zend Framework in July of 2007. The framework has come a long way since then, and one of my favorite new components is Zend Tool. Until Zend Tool came on the scene, my least favorite part of any Zend Framework project was getting the project up and running, from zero to “Hello World,” if you will. I always left out some important piece of configuration, screwed up the directory structure, or made some other equally foolish, simple mistake that kept me chasing my tail until I finally got everything set up just right. No longer! Zend Tool does all of that work for me, allowing me to get to work on the meat of my project right away.

Of course, you can’t use Zend Tool until you’ve got the framework installed. Once the framework is installed, there are very specific steps required to fire up Zend Tool. Once Zend Tool builds the project for you, you’re going to need a virtual host set up so that you can actually run the thing. No problem, right?  Well, maybe not.

It can be really challenging for the new guy to get from zero to a Zend Framework project without wanting to chunk his computer out the window (headdesk anyone?). I know it was that way for me. In the interest of saving his sanity and helping the new gal get going, I’ve tried to put all the necessary steps together in one place.

Here’s what we’re going to do:

  • Install the Zend Framework
  • Get Zend Tool up and running
  • Create a new Zend Framework project
  • Get an virtual host up and running
  • Celebrate victory!

Disclaimer

While I’m going try to stay true to my “Zero to Zend Framework Project” thesis, I am making a few assumptions. This tutorial is written for Ubuntu, PHP 5, and Apache. While I’d love to be able to address Windows, Mac, and other *nix distros, I can only share what I know.  I’m also assuming PHP 5 (PHP 5.2.4 at minimum) and Apache are both installed and functioning correctly, and Apache’s mod_rewrite module is up and running. If that’s not the case, please refer to the resources section at the end of this post to find instructions on getting everything ready to go.

Installing the Zend Framework

Installing the Zend Framework is as easy as downloading a .zip or .tar.gz file (your choice) and extracting the contents onto your machine.

  • Create a directory named phplib in your home folder.
  • Head over to Zend Framework: Downloads and download Zend Framework Full.
  • Double click on the downloaded file, choose “Extract,” navigate to the phplib directory, and click “Extract.”

As of this writing, the most recent version of the Zend Framework is 1.10.3, so the full path to my Zend Framework installation would be

1
/home/jkendall/phplib/ZendFramework-1.10.3

IMPORTANT: Make sure that you downloaded Zend Framework Full.  That will be important later.

TIP: As new versions of the framework are released, I like to be able to switch between them easily.  I always make a soft link (symbolic link, symlink) to the latest release and name it Zend.  You can either right-click on the ZendFramework-1.10.3 folder and select “Make Link” (make sure to name the link “Zend”), or create a soft link from the command line like so:

1
~/phplib/ZendFramework-1.10.3$ ln -s ZendFramework-1.10.3 Zend

When a new version of the framework is released, I install the new version to its own folder and switch the soft link to target the directory containing the latest release.  That can come in handy down the road.

Get Zend Tool running

There are a few different ways to get Zend Tool running, perhaps better than mine, but I like to create a bash alias for zf.sh (For information on how to get bash aliases working, see this bash aliases tutorial.). My alias looks like alias zf='/usr/share/phplib/Zend/bin/zf.sh'.

Whichever method you use, make sure to test your alias by calling zf --help from the command line.

Creating a new Zend Framework Project

Now we’re getting to the good stuff.  First, head back to your home directory and create a new directory called public_html.  This is where you’re going to store your Zend Framework project (and any future web projects, for that matter).

Next, cd into the public_html directory and execute the following command:

1
~/public_html$ zf create project ZeroToZF

That’s all there is to it!  You’ve got your project structure in place, a default IndexController and ErrorController, your application config, the necessary view scripts, etc (See the Zend Application Quick Start for full rundown of what got created.).

IMPORTANT: While the full project structure is now in place, the Zend Framework is not included in your project for you.  Deciding how the framework should be included in the project is up to the developer.  I like to copy the library out of the Zend Framework install folder into the application’s library folder.  In our example, I would copy

1
/home/jkendall/phplib/ZendFramework-1.10.3/library/Zend

into

1
/home/jkendall/public_html/ZeroToZF/library

When done properly, the full path to Zend/Log.php in your application should be

1
/home/<username>/public_html/ZeroToZF/library/Zend/Log.php

Sweet!  We’re almost there.

Creating a Virtual Host

There are a decent number of steps here, but executing them is straightforward, so bear with me.  Also, a lot of these steps need to be executed from the command line.  Forewarned is forearmed and all that.

If you have not done so already, open the terminal application (Applications -> Accessories -> Terminal) and cd into /etc/apache2/sites-available.  Here you’ll find virtual host definitions.  Most likely you’ll see a file named default (or possibly 000-default).  Peek at that if you’d like to see an example of a virtual host, but what we’re going to put together is a lot simpler.

IMPORTANT: Since /etc and its subfolders are owned by root, you’ll need to run all of the following commands as root.  We’ll be using both the sudo and the gksudo commands to do that.

After using the command line to cd into /etc/apache2/sites-available, execute the following command to create your own vhost file:

1
/etc/apache2/sites-available$ gksudo gedit ZeroToZf.local

The file extension isn’t important, a lot of people use .conf, but I like to use .local for sites hosted locally.

Once you’ve got gedit open, the file’s contents should look like this:

1
2
3
4
<VirtualHost *:80>
        ServerName zerotozf.local
        DocumentRoot /home/jkendall/public_html/ZeroToZF/public
</VirtualHost>

Of course, jkendall should be replaced by your username.

Next we need to make your new virtual host file available to Apache.  You can do that by executing

1
/etc/apache2/sites-available$ sudo a2ensite ZeroToZF.local

If everything worked properly, you should see the following message:

1
2
Enabling site ZeroToZF.local.
Run '/etc/init.d/apache2 reload' to activate new configuration!

Next, edit your /etc/hosts file by adding zerotozf.local like so:

1
/etc/apache2/sites-available$ gksudo gedit /etc/hosts

Add the following line below the entry for localhost

1
127.0.0.1 zerotozf.local

NOTE: When adding a host to /etc/hosts, the case of the hostname is not important.  I like to add hostnames in lowercase, but you can add it as ZeroToZF.local if you like.

Save the file, close gedit, and execute

1
/etc/apache2/sites-available$ sudo /etc/init.d/apache2 reload

You should see the message

1
* Reloading web server config apache2                                          [ OK ]

Open up your browser and visit http://zerotozf.local.  You should see the Zend Framework welcome screen.

Congrats!  You did it!

Next Steps

Now that you’ve got your first project up and running, you’re probably going to want to actually do something with it.  I’d highly recommend heading over to Rob Allen’s site for his excellent Getting Started with Zend Framework tutorial.  It’s the same tutorial I followed when I first started with the framework (an earlier version, of course), and I’ve referred back to it many times since.

Wrapping Up

Getting started with the Zend Framework was a challenging proposition for me.  Just getting to the point where I could start working on a project was sometimes maddening as a result of all the steps involved, many of which had nothing to do with the framework, at least not directly.  I’ve tried, hopefully successfully, to lay out all the steps you might need to get from zero to a Zend Framework project in (about) 10 minutes.

Working with the Zend Framework has been a rich and rewarding experience for me.  I’ve learned almost everything I know about best practices, object oriented programming, *nix, and Apache (to name just a few) as a direct or indirect result of the Zend Framework.  I wouldn’t have been able to do that without the help of the Zend Framework community.  I won’t name names, as I’m sure to unintentionally leave out some great folks, so I’ll throw you a link to the Zend Framework Community Forum.  Head over there when you’ve got a Zend Framework problem you just can’t solve on your own.  You’ll meet some great folks and learn a lot in the process.  They’ve saved my bacon more than once.

If I’ve left out any steps or made some egregious error, please let me know in the comments.  I’ll be grateful and post updates and corrections as soon as possible.

Resources

DIY Network Monitoring and Logging With Perl

The Problem

I’ve been having trouble with my AT&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. Nope. Didn’t work.

I’ve had this problem before with AT&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’m not crossing my fingers that I’ll have such luck again.

What’s Really Going On?

I decided to try and log the bounces so that I could get a better feel for what was going on. I couldn’t find exactly what I wanted online (and I couldn’t always get online), so I whipped up a Perl script to keep an eye on my connection for me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl

#
# Test AT&T DSL connectivity. If network is down, log to file
# Will use log info as ammo when I call tech support.
#

use warnings;
use strict;
use Log::Handler;
use Net::Ping;
use Sys::HostIP;

my $log = Log::Handler->new();

$log->add(
    file => {
        filename => "/var/log/testNetwork.log",
        mode     => "append",
        maxlevel => "info",
        minlevel => "warning",
    }
);

my $ipAddress          = Sys::HostIP->ip;
my $matchHomeNetworkIp = ($ipAddress =~ /^192\.168\.10\.\d{1,3}$/);

if (!$matchHomeNetworkIp) {
    $log->debug("Current IP $ipAddress does not appear to be on your home network. Exiting");
    exit;
}

my $router = "192.168.10.1";
my $modem  = "192.168.1.254";
my $host   = "www.yahoo.com";

my $p = Net::Ping->new("icmp");

if (!$p->ping($router)) {
    $log->warning("Router $router is unreachable. Exiting.");
    exit;
}

if (!$p->ping($modem)) {
    $log->warning("Modem $modem is unreachable. Exiting.");
    exit;
}

if ($p->ping($host, 2)) {
    $log->info("$host is reachable");
} else {
    $log->warning("$host is NOT reachable");
}

$p->close();

Code Review

While the code is simple, there are a couple of things to note. First, you’ll notice I’ve baked my router’s IP range into a regex that will tell me if I can even get that far. If not, there’s no point in checking anything else, so I exit.

Next I fire up Net::Ping. 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.

Next I ping 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.

If everything looks good on the inside, I’ll ping an external site and see if I get anything back. You’ll notice that I’ve added a second parameter to ping this time. That’s the number of seconds I’ll wait for a response before failing (of course, it is possible that Yahoo! won’t respond to a ping request here and there, making it appear as if the network is down, but I’m not so worried about a false positive or two).

Implementation

Now that I’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’s important to run it as root because of the icmp ping. Cron was the obvious solution, as it’s purpose is to run commands on a predetermined schedule. As long as I add the script to root’s cron file, it’ll run with root permissions. Sweet!

Adding my script to the root cron file was as easy as issuing

sudo crontab -e

and adding the following line:

*/1 * * * * perl /home/jkendall/dev/perl/util/testNetwork.pl

With my cron file in place, my script fires off every minute. As long as I’m on my home network, I’ll get a log entry telling me whether or not the network is up.

Keeping an Eye on the Results

Now that my script is actually doing something, I need to be able to parse the results. A quick

tail -f /var/log/testNetwork.log

allows me to keep track of the results as they come in. I’m also using grep to pull all of the “NOT reachable” lines out of the log file with

grep -n --color "NOT reachable" /var/log/testNetwork.log

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’t whipped it up yet.

Teh Suck

As I’ve been writing this blog post, I’ve been running this script in the background. Here are the results of an hour or so of logging (all times are CDT):

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

Weak sauce, man. Weak sauce.

Wrapping Up

Having this script handy doesn’t make the fail any better, but at least I know a little more about what’s happening. I’d like to think it’ll give me some leverage when I try to get this worked out with AT&T, but who knows. I’ll let you know how it goes.

[Update: post title change to better reflect content]

ZF-7984 - Zend_Tool Exits With Fatal Errors After Installing PHPUnit 3.4.0+

I’m lucky enough to have made it to ZendCon again this year, and I’m having a blast learning new stuff, hanging out with old friends, making new friends, and generally grabbing up as much schwag as possible.

One of the topics that I’m most interested in is unit testing, specifically unit testing Zend Framework MVC apps.  While there’s a lot I have yet to learn on that topic, I ran into a bug last night that I wanted to let you know about.

In preparation to dig into ZF unit testing, I updated my install of PHPUnit to the latest version (currently 3.4.1, installed via PEAR).  When I tried to create a new ZF project using Zend_Tool, I received the following error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
jkendall@san-diego:~/dev/www$ zf create project asplode

Fatal error: Cannot redeclare class phpunit_framework_testsuite_dataprovider in /usr/share/php/PHPUnit/Framework/TestSuite/DataProvider.php on line 64

Call Stack:
    0.0020     111440   1. {main}() /usr/share/phplib/ZendFramework-1.9.3PL1/bin/zf.php:0
    0.0020     111560   2. zf_main() /usr/share/phplib/ZendFramework-1.9.3PL1/bin/zf.php:23
    0.0220     686832   3. zf_run($zfConfig = array ('HOME' => '/home/jkendall')) /usr/share/phplib/ZendFramework-1.9.3PL1/bin/zf.php:36
    0.0221     686952   4. Zend_Tool_Framework_Client_Console::main($options = array ()) /usr/share/phplib/ZendFramework-1.9.3PL1/bin/zf.php:214
    0.0221     687440   5. Zend_Tool_Framework_Client_Abstract->dispatch() /usr/share/phplib/ZendFramework-1.9.3PL1/library/Zend/Tool/Framework/Client/Console.php:96
    0.0222     687560   6. Zend_Tool_Framework_Client_Abstract->initialize() /usr/share/phplib/ZendFramework-1.9.3PL1/library/Zend/Tool/Framework/Client/Abstract.php:209
    0.0296     866600   7. Zend_Tool_Framework_Loader_Abstract->load() /usr/share/phplib/ZendFramework-1.9.3PL1/library/Zend/Tool/Framework/Client/Abstract.php:118
    0.4100    2729736   8. include_once('/usr/share/php/PHPUnit/Framework/TestSuite/DataProvider.php') /usr/share/phplib/ZendFramework-1.9.3PL1/library/Zend/Tool/Framework/Loader/Abstract.php:90

jkendall@san-diego:~/dev/www$

As it turns out, this is a known bug in version 1.9.0+ of the Zend Framework.  See ZF-7894 in the ZF issue tracker for full details.  While this issue is not yet resolved in the tracker, Raphael Stolt has provided a workaround in the form of a diff file attached to the issue.  While your mileage may vary, the patch worked perfectly for me.  I’m able to go ahead and dive into unit testing my Zend Framework applications.

UPDATE: ZF-7894 was resolved during Bug Hunt days this week. Many thanks to Benjamin Eberlei!