#!/usr/bin/perl -w
#################################################################################
## Author: BRIAN HUNTER
## Date: 8/10/2020
## Email: brian@sutechy.com
#################################################################################
use strict;
use Net::Ping;
my $sysadm="brian\@sutechy.com";
my $host="/etc/hosts";
my $p = Net::Ping->new();
open(HOST, "<$host") or die "Unable to read $host:$!\n";
while(< HOST>) {
my($ip,$svr) = split(/\s+/,$_);
if ($p->ping("$svr")) {
print "Server alive : $svr\n";
} else{
print "ALERT: Server Down\n";
system("/bin/mailx -s 'Server Down: $svr' $sysadm < $host");
}
}
close(HOST);
exit(0);