Following is a simple script, written in PHP, which will send an E-mail alert to you when one or more of your Web servers is inaccessible.
<?php
/* things to edit/change */
$fileToFetch = "isalive.txt";
$mailTo = "shekhar@it4enterprise.com";
$mailFrom = "alert@it4enterprise.com";
$websites = array(
"Website 1" => "http://www.website1.com",
"Website 2" => "http://www.website2.com",
"Website 3" => "http://www.website3.com"
);
/* end of things to edit/change */
foreach($websites as $name=>$value)
if(!($fp = @fopen($value."/".$fileToFetch,"r")))
mail($mailTo,"WEBSITE DOWN: ".$name,"WEBSITE DOWN: ".$name,"From: ".$mailFrom);
?>
How to use this script:
0,15,30,45 * * * * php -q /opt/isalive.php >> /dev/null 2>&1
How the script works:
Why isalive.txt instead of home page
You may ask why cannot the script fetch the first page of your website and why you need to create isalive.txt. Remember this script is hitting your site frequently (15 mins). The first page of your website can be a heavy (in size) or slow (a page which is doing serveral database queries) page. Whereas isalive.txt can be as small as zero byte.
Todos
Obviously there can be more to be desired from this script (making it not so simple). For example:
How it works for me
Very recently, I have started using this script to monitor some servers of my clients’. As said above, ideally, I should get this alert through SMS for a timely action. But I get my E-mails almost as quick as SMSes on my mobile. Thanks to Push E-mail. I have a Windows Mobile phone and a Zimbra (www.zimbra.com) based E-mail server and I’m using Z-Push (http://z-push.sourceforge.net/soswp/) to get Push-ed E-mails. Refer to an article on setting up Z-Push at http://pcquest.ciol.com/content/enterprise/2008/108070503.asp, written by me. With preliminary testing, this is indeed a simple and working script for me.
Email This Post
⋅
Print This Post
⋅
Post A Comment
@shekharg
>>>I have a Windows Mobile phone and a Zimbra based E-mail server and I’m using Z-Push to get Push-ed E-mails
–
Just wondering whether you got Z-Push working with the OpenSource version of Zimbra or with one of the commercial versions.
loading...
I used it very successfully with the open source edition (OSE) of Zimbra 5.0
loading...