Skip to content

Commit

Permalink
add monitor host script
Browse files Browse the repository at this point in the history
  • Loading branch information
catalyst-donovan-jones committed Feb 28, 2011
1 parent 916365a commit 95a907f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions monitor-host/monitor-host.pl
@@ -0,0 +1,35 @@
#!/usr/bin/perl

use strict;
use warnings;

use Net::Ping::External qw(ping);

my $target = shift;

my $state = ping(host => $target);

if ($state) {
print "monitoring $target (currently up)\n";
}
else {
print "monitoring $target (currently down)\n";
}

while (1) {
sleep 5;
my $alive = ping(host => $target);
if ($alive == 0 and $state == 1) {
system('notify-send', "$target just went down");
}
elsif ($alive == 1 and $state == 0) {
system('notify-send', "$target just came up");
}
if ($alive) {
print "$target is alive ($alive)\n";
}
else {
print "$target is down ($alive)\n";
}
$state = $alive;
}

0 comments on commit 95a907f

Please sign in to comment.