My first perl script for the production environment, although not very good, but also took a solid step :)
The leader has a task to send a batch of IP addresses to the list and ping each machine. If no response is received, an email notification is sent. The notification emails must be separated and cannot be sent to a list. A notification must be enclosed.
Use the email: send module because Gmail is required.
#! /Usr/bin/perl
Use warnings;
Use strict;
Use Email: Send;
Use Email: Send: Gmail;
Use Email: Simple: Creator;
My @ list = qw/
192.168.1.2
192.168.2.3
192.168.5.3
/;
Foreach my $ re (@ list ){
My $ p = 'Ping $ re-c 3'; three icmp requests
If ($ p = ~ /100% packet loss /){
My $ email = Email: Simple-> create (
Header => [
From => 'Monitor @ hongshu.com ',
To => 'Monitor @ hs.com ',
Subject => "$ re 100% packet loss ",
],
Body => "$ re the server is down! \ N ",
);
My $ sender = Email: Send-> new (
{Mailer => 'gmail ',
Mailer_args => [
Username => 'Monitor @ hongshu.com ',
Password => 'xxx ',
]
}
);
Eval {$ sender-> send ($ email )};
Die "Error sending email: $ @" if $ @;
}
}
This article is from the blog "let me men grow together" and will not be reproduced!