4 use Net::SSH qw( ssh_cmd );
7 my @other_hosts = ( 'freeside.biz', 'saturn5.com' );
9 my( $machine, @emails ) = @ARGV;
10 die "no notification email given" unless @emails;
12 my $ping = new Net::Ping; # 'icmp'; #requires root
15 # can't tcp ping... $ping->ping($machine) and
16 $pong = eval { ssh_cmd('freeside@'.$machine, 'echo pong') };
17 #(command ignored if authorized_keys setup w/command=)
19 if ( $@ || $pong !~ /pong/ ) { #houston, we may have a problem
21 #warn "can't reach $machine, checking @other_hosts\n";
23 #let's do a sanity check, can we see some other hosts?
24 exit unless grep $ping->ping($_), @other_hosts;
28 #warn "checking to see if we've alerted on this recently\n";
30 #but we don't want to be too noisy, have we alerted on this in the last 24h?
31 my $file = "/tmp/alert-$machine";
32 exit if -e $file && -M $file < 1;
34 open(FILE, ">>$file");
35 print FILE "emailing\n";
38 #warn "emailing alerts\n";
40 foreach my $email ( @emails ) {
42 my $message = <<"__MESSAGE__";
43 From: support\@freeside.biz
45 Subject: ALERT - $machine
47 ALERT: $machine appears to be down.
51 my $sender = Email::Send->new({mailer => 'SMTP'});
52 $sender->mailer_args([Host => 'mail.freeside.biz']);
53 $sender->send($message);