<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w

use strict;
use vars qw ($VERSION $found $url $title $To);

$VERSION = '1.04';

# $wait is the number of down notices you'll allow before freaking out.  
# Running at 1 usually produces a couple false alarms per week.  2 is recommended.
my $wait = 2;

# $From is who you want these to be sent from?
# Leave blank to default to /etc/HOSTNAME.
# my $From = DISPLAY NAME &lt;email address&gt;
my $From = "MYCOMPUTER &lt;root\@my.domain.com&gt;";

# Add as many websites as you like here using multiple &amp;whatsup subroutines.
# ('URL', 'Title', 'To an email address, To another email address')                           
#&amp;whatsup('http://my.domain.com/index.html','MY WEBSITE','email@domain.com,email@mydomain.com,pageme@domain.com');
&amp;whatsup('http://www.s1te.com/index.html','S1TE.COM','BarracodE@s1te.com');

exit;

sub whatsup
{
	$found = 0;
	$url = shift;
	$title = shift;
	$To = shift;

	# Check if it's up.
	open (PIPE, "/usr/bin/lynx -source $url|") || die "Can't open /usr/bin/lynx: $!\n";
	while (&lt;PIPE&gt;)
	{
   	$found = 1 if ($_ =~ /IMUP/);
	}
	close PIPE;

	# Use IPC::ShareLite shared memory for easy access to DB info.
	use IPC::ShareLite;
	my $share = new IPC::ShareLite( -key 		=&gt; "$title",
											  -create	=&gt; 'yes',
											  -destroy	=&gt; 'no',
											  -size		=&gt; 25 );
	my $count = $share-&gt;fetch;
	$count++;	

	if (!$found)
	{
		my $result = $share-&gt;store("$count");

		# Send email after $wait number of down notices.
		&amp;email('DOWN') if ($wait == $count);

		# Debug.
		#print "$title is DOWN (found=$found, count=$count, wait=$wait)\n";
		#print "I'm sending DOWN email now for $title.\n" if ($wait == $count);
	}
	else	
	{
		my $result = $share-&gt;store("0");

		# Send email if we're past the $wait period.
		&amp;email('UP') if ($count &gt; $wait);

		# Debug.
		#print "$title is UP (found=$found, count=$count, wait=$wait)\n";
		#print "I'm sending UP email now for $title.\n" if ($count &gt; $wait);
	}
}

sub email
{
	my $what = shift;
	open(MAIL, "|/usr/sbin/sendmail -t") || die "Can't open /usr/sbin/sendmail: $!\n";

	print MAIL "To: $To\n";
	print MAIL "From: $From\n";
	print MAIL "Subject: $title IS $what!!!!\n\n";
	print MAIL "$url\n";

	close MAIL;
}

__END__

=head1 NAME

	whatsup.pl $VERSION.  Verify's your websites are running.

=head1 README

	Verify your websites are running from multiple servers,
	inside and outside your firewall.  Notify you when they go
	down.

=head1 DESCRIPTION

	Checks each webpage for an &lt;IMUP&gt; tag every (cron).
	It let's you know when you're down, &amp; when you're back up.
	Recommended to run (cron) every 5 minutes.

	Compared to watchdog, this was designed to be executed on multiple servers.
	Apache Restart logic has NOT been added (if Apache happens to go down,
	there are usually bigger problems than simply restarting the webserver).

	Current logic is to watch every webserver from every other webserver.
	It's recommended you run this outside your firewall as well.   Find a partner
	to cross watch websites, much like secondary DNS logic.

	If your websites are ever unreachable, page/email every admin so they can
	jump on a terminal and get it back up.

=head1 SYNOPSIS

	Add &lt;IMUP&gt; to the bottom of any webpage you'd like to monitor.

	Run this from your cron:

	1-60/5 * * * * /home/httpd/cgi-bin/whatsup-1.XX.pl &gt; /dev/null 2&gt;&amp;1
	or
	1-60/5 * * * * /home/httpd/cgi-bin/whatsup-1.XX.pl &gt; &amp; /dev/null

	$wait is the number of down notices you'll allow before freaking out.
	Running at 1 usually produces a couple false alarms per week.  2 is recommended.

	$From is who you want these to be sent from?
	Leave blank to default to /etc/HOSTNAME.
	$From = DISPLAY NAME &lt;email address&gt;

	&amp;whatsup('URL', 'Title', 'To an email address, To another email address');

	URL is obvious.
	Title what webpage you're monitoring (My Dog Skip, My Flower Shop).
	To: email address are comma dilimited.  Add as many admins here as you like.

	It's recommended you find a paging service you can send an email to which will
	in turn page you immediately.

	Uncomment the Debug lines to see what's going on.  Comment them out again when
	things are running smoothly.

=head1 AUTHOR

   Charles Day
   BarracodE@CPAN.org
   http://www.s1te.com

=pod SCRIPT CATEGORIES

Web

=pod PREREQUISITES

IPC::ShareLite

=cut
</pre></body></html>