Using the internet to remotely check for power failure at home (PHP)
Archive - Originally posted on "The Horse's Mouth" - 2009-04-29 23:35:26 - Graham EllisDo you have freezers and other electrical equipment at home and worry about whether they'll be all right while you're away on holiday? Do you have a broadband connection with a rarely changing IP address, and a web site that you host with a web space provider? Then you'll be able to set up a "heartbeat" script to check out your home systems. We're doing this to keep an eye on Well House Manor, where we have two separate power feeds and want to be alerted if either of them trips.
Sample Scheme (what we have done - there are lots of alternatives at some stages):
a) Set up your home modem / router to point to a local machine that's permanently running, and is running Apache httpd and PHP. We have a Mac mini that fulfils this role. On this machine write a very simple web page that returns a status, such as:
<?php print(`uptime`); ?>
b) Set up a script of your main web site (remote from home) that runs this script, analyses the results, and emails you if there's a problem. We have a sample of such a script here ... ours is slightly more sophisticated in that is also looks at the server loading and reports back if there are overloading issues too
c) Set up a regular timed (crontab) job on your web site to run the 'heartbeat' script at an appropriate frequency. We have the following line in our 'crontab' file:
9,24,39,54 * * * * /usr/local/bin/php /home/welho/private/zzppxping.php
Here is my slightly longer explanation of the various things this script will catch, taken from the comments I have added so that I can remember what I did when I come to look at the script in the future ...
/* 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 */
I should now write an equal and opposite script that has our local server checking that the web space provide system is live and responding ;-)