Skip to content

Instantly share code, notes, and snippets.

@exu
Created September 8, 2011 13:18
Show Gist options
  • Save exu/1203367 to your computer and use it in GitHub Desktop.
Save exu/1203367 to your computer and use it in GitHub Desktop.
#!/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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment