Index of /tools/watchdog
Name Last modified Size Description
Parent Directory -
wd_stat.json 2017-05-18 13:55 646
wd_check.php 2017-05-18 14:08 2.2K
wd_readme.txt 2017-07-19 10:55 1.6K
wd_alive.php 2018-03-27 19:50 1.2K
Simple PHP based watchdog
(c) 2017 Thorsten Maerz (firstname.lastname@example.org) - Public Domain
Check, wether a certain device is on- or offline.
The device that should be watched has to request a PHP file on a remote
webserver. This updates a timestamp for that device on the webserver.
The webserver regularly checks, if the timestamps are up to date and sends an
email, if the state (on- or offline) changed.
** On the device:
Create a cronjob that updates the timestamp.
Every 15minutes may be a good start:
*/15 * * * * wget -O /dev/null -q http://HOST.TLD/PATH/wd_alive.php?host=HOSTNAME
** On the webserver:
Put the scripts "wd_check.php" and "wd_alive.php" into an accessible directory
on the webserver. Edit the "wd_check.php" and modify "$json_stat_name".
Use an absolute path for the status file ($json_stat_name), otherwise the cron
job may not find it.
Run the script using "php wd_check.php". This will create a sample status file
("wd_stat.json"), unless it already exists. You should receive 2 emails, that
the hosts are offline.
Edit the status file. Only hosts that are mentioned there, will be checked
(unless you set "ignore" to "true" or the current time lies outside
"watchstart" and "watchend"). Change "mailto" and "mailfrom" to sensible values.
The other fields should be self-explanatory.
Finally create a cronjob that regularly calls the "wd_check.php" script:
*/15 * * * * php /var/www/watchdog/wd_check.php
(If you cannot set up cron jobs, you may as well call the "wd_check.php"
script from any other host using wget, curl, etc.).