This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
class ServerMonitor { | |
public $hosts = array( | |
'wp.pl', | |
'ukrywamsieglebokopl.tld', | |
'google.pl', | |
); | |
function check($host) { | |
exec("ping -c 1 $host", $o, $r); | |
return (int)$r === 0; | |
} | |
function alert($host) { | |
$msg = "$host is down\n"; | |
`DISPLAY=:0.0 /usr/bin/notify-send -u critical -i /usr/share/icons/Faenza/status/scalable/error.svg '$msg' `; | |
} | |
function run() { | |
foreach($this->hosts as $host) { | |
if (!$this->check($host)) $this->alert($host); | |
} | |
} | |
} | |
$Monitoring = new ServerMonitor(); | |
$Monitoring->run(); |
Change hosts variable (array) and path to icon file (-i /usr/share/icons/Faenza/status/scalable/error.svg).
You can use it in your crontab: Edit your cron settings:
crontab -e
and insert:
* * * * * php /home/exu/scripts/monitoring
(change /home/exu/scripts/monitoring to path to your file) Enjoy!
No comments:
Post a Comment