September 2009 Archives

Simple Remote Monitor for Apache with Perl

| 3 Comments | 2 TrackBacks
| | | |
Sometime last week Apache on one of the servers that manages some websites I host stop responding to requests, resulting in said websites being unavailable for a day and half (or so). Unfortunately I didn't know about the problem until someone else notified me of the issue. Opps. Not good system administration that.


There are plenty of solutions for monitoring network services, but given that I'm just running Apache for a half dozen non-critical websites on the side, there's no reason to go overboard. Any sysadmin worth their weight in salt should be able to whip something up with Perl in no time.1 So, what's needed? Well, something that will remotely monitor the pool of websites and notify me if something is amiss:

monitor_flow.jpg

First up, making a simple HTTP GET request:

my $url = "http://$host";
my $ua = LWP::UserAgent->new;
my $response = $ua->get( $url );

Now we test the response, was it successful? If so, Apache returns an appropriate status code and the requested resource. If Apache is available, but unable to properly process the request it will responded with some relevant status code, which we wish to pass on for further troubleshooting:

if ( !$response->is_success ) {

	# Do we have an error code?
	if ( $response->code ) {

	     reportError("$host reports $response->message \n");

	} else {

However a failed GET request will result in no status code since Apache probably failed to respond at all. In this case it would be helpful to determine if the issue is with Apache or something else. For that test a network ping is issued:

		# HTTP is down, is the network connection down too?
		my $p = Net::Ping->new("icmp");
		if ( $p->ping( $host, 2 )) {

		     reportError ("$host is responding,
		     		     	     but Apache is not.\n");

		} else {

		     reportError ("$host is unreachable.\n");

		}
	}

Not too difficult that. Now, how do we go about communicating the issue at hand? SMS has always been my preferred method since my phone is usually close at hand and, iPhone or not, SMS is widely implemented and easy to use.

# Send SMS via cellular Email to SMS gateway
my ( $msg ) = @_;
my $to = "7735551234\@txt.att.net";
my $from = "pdw\@weinstein.org";
my $subject = "Service Notification";

my $sendmail = '/usr/lib/sendmail';
open( MAIL, "|$sendmail -oi -t" );
	print MAIL "From: $from\n";
	print MAIL "To: $to\n";
	print MAIL "Subject: $subject\n\n";
	print MAIL $msg;
close( MAIL ); 

All's done? Not quite. For the fun of it, I figured broadcasting a message that the server was unavailable might be of use to regular visitors. What better way to broadcast a short message than via Twitter?

my ( $msg ) = @_;
my $nt = Net::Twitter::Lite->new(
	username => $username,
	password => $password );

my $result = eval { $nt->update( $msg ) };

Bring this all together, with cron gives us:

# monitor remote httpd servers every 30 minutes
*/30 * * * *   pdw  /home/pdw/bin/monitor.pl >/dev/null 2>&1



#!/usr/bin/perl
use strict;

use LWP::UserAgent;
use Net::Ping;
use Net::Twitter::Lite;

my @hosts = ( "pdw.weinstein.org", "www.weinstein.org" );

foreach my $host ( @hosts ) {

my $url = "http://$host";
my $ua = LWP::UserAgent->new;
my $response = $ua->get( $url );

if ( !$response->is_success ) {

# Do we have an error code?
if ( $response->code ) {

reportError("$host reports
$response->message.\n");

} else {

# HTTP is down, is the network connection down too?
my $p = Net::Ping->new("icmp");
if ( $p->ping( $host, 2 )) {

reportError ( "$host is responding,
but Apache is not.\n" );

} else {

reportError ( "$host is unreachable.\n" );

}

}

}

sub reportError ($) {

my ( $msg ) = @_;
my $nt = Net::Twitter::Lite->new( username => $username, password => $pasword );
my $result = eval { $nt->update( $msg ) };

if ( !$result ) {

# Twitter has failed us,
# need to get the word out still...
smsEmail ( $msg );

}

}

sub smsEmail ($) {

my ( $msg ) = @_;
my $to = "7735551234\@txt.att.net";
my $from = "pdw\@weinstein.org";
my $subject = "Service Notification";

my $sendmail = '/usr/lib/sendmail';
open(MAIL, "|$sendmail -oi -t");
print MAIL "From: $from\n";
print MAIL "To: $to\n";
print MAIL "Subject: $subject\n\n";
print MAIL $msg;
close( MAIL );

}



1 Of course if I was worth my weight I would have had something in place long before it was called for....

About Last Night...

| 0 Comments | 0 TrackBacks
| | | |

To my non-Illinoisan friends who watched Jon Stewart last night I offer these three simple facts:

1) The people of Illinois had soured on Mr. Blagojevich's budgeting by fiat long before the formal charges of corruption. Before his indictment his approval rating was between 20% - 30%

2) Mr. Blagojevich (should) know that the rules and reasons for impeachment are different than those of a criminal (or even civil) trial. While there are many explanations and interpretations for this I offer the most simple and straightforward: We deserve a Governor who is above reproach.

3) Everyone, even the disgraced governor, wants to focus on the "(bleep)ing golden" Senate seat. However, "selling" of the Senate seat is only one of pending criminal charges. He is also charged with attempting to bride the Tribune company with state funds while selling its ownership stake in the Chicago Cubs and attempting to gain campaign funds from the Children's Memorial Hospital, among others.


The Daily Show With Jon StewartMon - Thurs 11p / 10c
Rod Blagojevich
www.thedailyshow.com
Daily Show
Full Episodes
Political HumorHealthcare Protests

Learning to Program

| 0 Comments | 0 TrackBacks
| | | |

In high school I took my first formal course in programming, an introduction to Computer Science with BASIC and the good-old Apple //e. My friends and I drove our teacher, Mrs. McBride, a bit batty. She knew we knew our stuff, but so did we. As a result a few of us would do anything but work. I hardly documented my code and when I did I'd write all kinds of nonsense to see if she was actually checking. I was sloppy with my variables, created them whenever and wherever. Same with my logic, the code jumped around from one GOTO to the next as it occurred to me. Spaghetti code it its truest form, writing on the fly with no consideration of design.

Yet I aced the course. I had so many points that I could have skipped the final and still have easily passed.

How?

Well an interesting dynamic developed, I and a couple of my classmates comprehended enough that, even with our lack of application our B and C work ended up as A++ because the rest of the class was struggling. Struggling so much so that even on a curve set by us, others would have failed. So the next highest grouping of grades defined the grading curve, resulting in extra credit points for my friends and I.

Introduction to Compute Science I in college was more of the same, minus the sliding scale. This despite the fact that the computers had changed along with the programming language, C and IBM clones. I aced my tests and programming exercises and wondered how others failed to see that the Professor had basically written the answer on the blackboard, short a line or two of code, while explaining the concept at hand.


Distribution of Grades

Apparently, this type of grouping, between those who start to develop a clear understand of the concepts and those who don't isn't that uncommon. You either pass, grasping all that has been covered or you fail to grasp even the most fundamental aspect of the theory and get left behind.

So I'm just lucky, right? I just got it. After all I remember going to a campus preview and being told by the head of the Computer Science department that. "No, we don't expect incoming students to have had classes in programming prior to entering our program."1

Well Michael K├Âlling a Professor at the University of Kent notes in a recent posting, Quality-oriented teaching of programming, that while this type of division has been common for decades, it may be more about how the concepts are taught, one building on the other, than about any natural ability to "just get it."

That is, if you don't understand a fundamental concept, however are you expecting to understand a more advanced one? Yet that's exactly how Computer Science has been taught for years.

I say he's right.

Consider my own subjective experience; I struggled with the transition from BASIC to Pascal in high school. All those bad programming habits caught up to me. The light bulb didn't go off until I revisited structured programming with C in college. Same happen when the college adopted object-oriented programming and C++. I, along with a few others, basically had to retake CS I, with all the same algorithms and data structures but now with these odd concepts of "objects" with their "methods". I never felt comfortable with OO until I came back to it a few years into my career as a web developer with Perl.

It's a shame really. All those people out there now, thinking that they just don't "get it" when it comes to computers, that they're not technologically savvy enough. Just like all those people who throw up their arms in frustration the moment you mention algebra or statistics. "I just don't get this stuff."

But of course the failing isn't necessarily that they lack some left-brain analytical function, but that they never got the time/chance/break to develop that understanding in the first place.



1 Keep in mind this wasn't MIT and my senior year in high school was 1992. So while I had a computer at home, was enrolled in computer programming classes and getting ready for the Advanced Placement test in Computer Science, the personal computer revolution had only just reached it's zenith before the 1991 rescission. In other words, the department chair wasn't assuming that any incoming student had been greatly exposed to a computer - other than video games and word processing - let along programming.

The iTablet, Only from AT&T?

| 0 Comments | 1 TrackBack
| | | |

Short of some as yet unforeseen issue, it seems that most Apple rumors these days agree that sometime early next year, Apple will be releasing a "tablet-like" device to the masses.


The rumored specifications include one or more devices of varying screen size (between 6 to 10 inches) with multitouch support, a screen resolution around 720x480, an Apple designed ARM-based Processor, WiFi and a long-duration battery.


Rumors also include a built-in 3G HSDPA chip for accessing the Internet, away from WiFi hotspots, via a cellular carrier that supports the same data standard.


The cellular data support begs the question, will Apple's new device be sold by AT&T with a price subsidy?


Why do I ask? Well, the current rumors put this tablet device at anywhere between $600 - $1000. Now ask yourself, would you pay $1000 for a device that could get lost or dropped easily? If your going to spend that much would you just purchase a Macbook? Even at the $600 price-range would you by Apple's tablet, a cheap laptop or a netbook?


However a price subsidy could drop the upfront price for the consumer from $600 - $1000 to $250 - $400.1 But that subsidy would no doubt require a 2-year contract for data service from AT&T.


That of course begs more questions; If this new Apple device is indeed getting a price subsidy similar to the iPhone, one has to ask won't a successful new Apple device put more strain on that same AT&T data network that's supposedly getting hammered by all those iPhone users?


Or, given the high price and resulting subsidy that AT&T would need to make back, it would suggest that the unlimited data plan for the new Apple device would be more than the $30 per month rate for the same plan on the iPhone. That in turn suggests the preclusion of being able to share the iPhone's data plan between devices. Will people accept that?


And of course would said device be exclusive to AT&T?


Lots of questions. Not many answers, just yet.





1 In fact AT&T already offers two netbooks for $199 after rebate.

The Misunderstanding of Information Technologists

| 0 Comments | 0 TrackBacks
| | | |

In many ways an employee in a business with any significant headcount has to deal with the same social constructs as any student in high school. Social groups, pressures and mores impact decisions and actions just as much as the organizational chart. Alas this also means that stereotypes and group labels can quickly impact how various teams and business organizations perceive themselves and others.


For IT Professionals this of course means retaining the label of "geek, nerd, dork and dweeb" along with an equivalent high school social hierarchy, low man on the totem-pole. Which means IT Professionals can end up in a lose-lose situation where an executive or manager might perceive an IT geek as antisocial, bullheaded and business-challenged.

But in an opinion piece last week for Computerworld Jeff Ello, an IT manager for the Krannert School of Management at Purdue University, feels that at the heart of the matter, IT Professionals are simply just misunderstood.


That is, IT Professionals are analytical individuals that can empower those around them and that their behaviors and intentions are simply misread. What might look to one manager as an individual that can't accept the manager's decision on how something is to be done is really an individual who is fighting for something to be done in a logical and effective manner. "It's not about being right for the sake of being right but being right for the sake of saving a lot of time, effort, money and credibility."


His opinion puts one in mind of Mike Judge's movie Office Space in which programmers Peter, Michael and Samir1 are terrorized by Initech's demanding and perplexing management team, personified by the company's Vice President, Bill Lumbergh. But the appeal of a movie such as Office Space is that one doesn't have to be a programmer to have ever felt terrorized by an impersonal business executive. A customer service representative can feel equally marginalized.


Yes, of course Executives should look at IT department as they would any revenue generating organization in general and not as some group of misbehaving malcontents. Each organization and individual, taken at face value, is an important asset to the business, with specific skills that can benefit a company. For IT this means bringing strong creative and analytical abilities to the table, skills that can be brought to bear on just about any business problem.


In noting that within the analytical skill set, "at the most fundamental level" of IT's job is "to build, maintain and improve frameworks" Jeff Ello reminds us of what IT can do best, bring about significant strategic advantage for the business.


However, for whatever reason Jeff Ello seems interested more in trying to justify the specific social group and mores of IT Professionals than he seems in communicating how those misunderstood stereotypes can be overcome. For whatever grievance or special treatment he might wish to argue to the world's collection of Executives on behalf of IT Professionals, it should be noted that in the end, we all want the same thing, for whatever enterprise we find ourselves engaged in to succeed. For that is what differentiates business from high school.


In any case, it works both ways. If IT Professionals are going to gain the respect of those Executives and Managers in endeavors great and small, technical and non-technical alike, it also means that IT Professionals need to understand the rules of the game governing Executives and business. It is time for both groups to shed past stereotypes and move on to bigger and better things.



1 And of course Milton, can't forget about him. He can set fire to this place, you know?

Is Information at the Speed of Light Better?

| 0 Comments | 0 TrackBacks
| | | |

A couple of weeks ago I started following Dave Winer on Twitter and the discussion about the relevancy of RSS and RSS updates in "real-time" has lead me to ask a simply question that I have yet to see asked: Is all this "real-time" communication even necessary?


What are you talking about, I hear some of you asking? Ok, here's the deal, Dave Winer is one of the developers of RSS. RSS is a file format that allows for the dissemination of web content, usually blogs, to be discoverable and readable by others online. That is not everyone goes to my website, on a daily basis to see if I've posted a new article. Many people use an aggregator that "subscribes" to a "news feed" provided on my site. When a new article posts, it appears in their aggregator at which point it can be read. All of this depends on RSS.


Supposedly, however, RSS is dead. Or at least RSS is dying. Why? Well because it takes time for the propagation of new posts to appear in one's aggregator/reader. Of course time is relative and one has to reconcile the illusion of faster with the actuality of faster, but for some it seems RSS takes too much time compared to status updates. Why should my readers wait for their aggregator when I can tell them right away on Twitter or Facebook?


But wait, RSS isn't dying, rssCloud will save it by speeding up the notification process for RSS feeds


But, wait. Wait, I ask. Why do we need really fast (or the appearance thereof) in the first place? I'm mean think about it, phone calls, emails, status updates, news feeds. All of this is running really fast, probably as close to instantaneous as we many ever be able to get.


And what do we all end up doing? We all end up developing with personal tricks and time management decisions about how to best process all this information. We allot Monday mornings to catching up on Facebook. We flag emails for levels of priority and we filter phone calls based on caller id.


Why? Well because my time, schedule and level of interest is different from yours. That doesn't mean I'm ignoring you, it just means, well, I've got something else on my mind....


Which brings me back to my initial question for us developers and users: Do all of these different types of communication have to be in real-time? Is it necessary?

The All Clear

| 0 Comments | 0 TrackBacks
| | | |

Well from my standpoint it looks like the server relocation has been a success.

I did run into a little roadblock with the Xen kernel in CentOS not booting into single user mode. This of course made it a bit difficult to boot the system so that I could modify the network settings for the new location since network based services like sendmail or httpd would slow-down and/or freeze the boot process with improper network settings. So minus single user mode where I could bypass all, but the most necessary services (sort of like Window's Safe-Mode), I had to use the interactive mode during the boot process to individually enable/disable services. That did the trick, but slowed me down quite a bit determining which services would freeze.

But the good news is the server has been installed, is running and DNS looks to be point everyone in the right direction. Not that anyone probably noticed, since all the while Google's Gmail was down for the count.

About the Author

Paul is a technologist and all around nice guy for technology oriented organizations and parties. Besides maintaining this blog and website you can follow Paul's particular pontifications on the Life Universe and Everything on Twitter.

   
   


Subscribe:
Add to Google Reader or Homepage
Add to My AOL

Add to netvibes
Subscribe in Bloglines
Add to Technorati Favorites

Powered
CentOS
Apache
MySQL
Perl
Movable Type Pro