My first Perl script for the production environment, though not very good, has taken a solid step:)
Leaders have tasks, to a number of IP list, ping each machine, if there is no response to send an email notification, the message needs to separate, can not notify a list, get a Feng Yi notice.
Use the Email::send module because you need to use Gmail.
Copy Code code as follows:
#!/usr/bin/perl
Use warnings;
Use strict;
Use Email::send;
Use Email::send::gmail;
Use Email::simple::creator;
My @list = qw/
1.1.1.1
2.2.2.2
3.3.3.3
/;
foreach my $re (@list) {
My $p = ' ping $re-C 3 ';
if ($p =~/100% packet loss/) {
My $email = Email::simple->create (
Header => [
From => ' monitor@a.com ',
To => ' monitor@b.com ',
Subject => "$re 100% packet Loss",
],
Body => "$re the down!\n",
);
My $sender = Email::send->new (
{Mailer => ' Gmail ',
Mailer_args => [
Username => ' monitor@a.com ',
Password => ' xxx ',
]
}
);
eval {$sender->send ($email)};
Die "Error Sending email: $@" if $@;
}
}