Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
916365a
commit 95a907f
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |