:::BACKGROUND DRAMA:::
As a backup Network / Firewall admin. I am responsible for 37 network access devices, only really need to take action if the device is down for over 15 minutes. This is important as the sleep statement in the tryagain sub routine could cause the program to take up to n times sleep (60); per down device. If your requirements are to be notified for every hiccup in the network (or if your provider doesn't drop a frame relay ckt. several times per day just modify the script).
#!/usr/local/bin/perl -w use strict; use Net::Ping; use MIME::Lite; unless(@ARGV) { print "Supply a file with hostnames \(example usage\)-- \n$0 /etc/ +hosts\n"; exit; } my @host_array=<>; my $p = Net::Ping->new("icmp"); foreach our $host (@host_array) { print "$host is "; &tryagain ($host) unless $p->ping($host, 5); print "reachable.\n"; } $p->close(); sub tryagain { print "NOT "; sleep (60); my ($host)=@_; my $p = Net::Ping->new("icmp"); foreach our $host (@_) { ¬ify ($host) unless $p->ping($host, 30); } $p->close(); } sub notify { my $date= localtime(time); my ($host)=@_; my $msg=MIME::Lite-> new( From =>'ICMP Monitor <joeblow@i.com>', To =>'linebacker@perlmonks.org', Subject =>'Ping Failure', Data =>"Ping failure for $host at $date" ); $msg->send; }
In reply to Ping Monitor with Email Notification by linebacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |