/* Heartbeat script - to run regularly on crontab and gather server
status from Well House Manor. This script runs on a remote server and
will email us if:
a) The Router at Well House Manor is not responding
e.g. changed IP, power failure
b) The Manor Web server is down
e.g. switched off / disconnected / has no power
c) Software issue on web server
i.e. the httpd daemon is not running or is overloaded */
/* Crontab line on main server
9,24,39,54 * * * * /usr/local/bin/php /home/welho/private/zzppxping.php
*/
/* Script that runs at heartbeat.php
<?php
$result = `uptime`;
print $result;
?>
*/
$robo = @file_get_contents("http://zzppx.welho.net/heartbeat.php");
$message = "";
$subject = "";
if (strlen ($robo) > 0) {
# Page status is fine
# Add Logging
$fields = explode(" ",trim($robo));
$ld = 0 + $fields[count($fields)-3];
if ($ld > 4) {
$subject = "[zzppx] Server Overloaded zzppx.welho.net";
$message = "Load $ld at $fields[0]";
}
} else {
# No response
$subject = "[zzppx] Server FAILED TO RESPOND zzppx.welho.net";
$message = "No response from server";
}
if ($message) {
$extras = "From: G.E.
/n".
"cc: lisa@welho.net, chris@welho.net/n";
"Reply-to: graham@welho.net/n";
mail ("graham@welho.net",$subject,$message,$extras);
}
# print ("Test - $ld - $message - $subject");
?>
-------------------------------------------------------
# Heartbeat script to watch vital server
/* This is a heartbeat script that tests a server (and a page
on that server) and should be run through crontab at an
appropriate interval ... sample crontab line:
8,23,38,53 * * * * /home/wellho/private/phping.php
*/
# Test the server
$robo = @file_get_contents("http://www.wellho.net/demo/rs.php");
# Sample response:
# 06:46:38 * 8 2 9 5 3 2 4 6 13 4 * 136 d 3:58 *
# 1 user * 0.38, 0.44, 0.67
$message = "";
$subject = "";
# Did we get a good response?
if (strlen ($robo) > 0) {
# Page status is fine
# In our particular example, the page we have called up is
# a server status report so we can analyse it. Usually, there
# would be no code in this section.
$fields = explode(" ",trim($robo));
$ld = 0 + $fields[count($fields)-3];
# Is the cpu load over 4? If so - report an issue
if ($ld > 4) {
$subject = "Server Overloaded www.wellho.net";
$message = "Load $ld at $fields[0]";
}
} else {
# No response from server or blank page
$subject = "Server FAILED TO RESPOND www.wellho.net";
$message = "No response from server";
}
# Use email to alter the admin
# No email sent if nothing is wrong
if ($message) {
$extras = "From: G.E.
/n".
"cc: lisa@wellho.net, chris@wellho.net/n";
"Reply-to: graham@wellho.net/n";
mail ("graham@wellho.net",$subject,$message,$extras);
}
# print ("Test - $ld - $message - $subject");
?>
------------------------------------------------------------------------------------