I did a search on the PM site for a ping monitor with email notification, but did not find one. So...I wrote this using Net::Ping and MIME::Lite. Improvements to this script are encouraged. Currently I run it from cron every 15 minutes.

:::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 (@_) { &notify ($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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.