#!/bin/perl -w use Net::Telnet(); use strict; my $script = "$ARGV[0]"; my $availablefirewall = my $primaryfirewall = "main.firewall.com"; my $backupfirewall = "backup.firewall.com"; my $externalhost = "111.222.111.222"; my $key = ""; my @errors = ""; my @message = ""; ##################################### ###ping primary firewall server ### ##################################### my $command = "/usr/sbin/ping $availablefirewall"; my $pingfirewall = `$command`; unless ($pingfirewall =~ /alive/) { @errors = ("Cannot reach primary firewall $primaryfirewall...T +rying backup firewall $backupfirewall\n"); $key = "Yellow"; ##################################### ###try backup firewall server ### ##################################### $availablefirewall = "$backupfirewall"; $command = "/usr/sbin/ping $availablefirewall"; $pingfirewall = `$command`; unless ($pingfirewall =~ /alive/) { push @errors,"\n!!! Unable to reach either firewall !! +!\n"; $key = "RED"; Notify ($key, $script, @errors, @message); exit(1); exit(1); } push @errors,"\nBackup firewall $backupfirewall reached\n"; Notify ($key, $script, @errors, @message); } ############################################# ###if the one of the firewalls is ### ###available then ping the external server### ############################################# my $t=new Net::Telnet (Timeout => 30, Prompt => '/Destination> /'); $t->open("$availablefirewall"); $t->waitfor('/Destination>/'); my $anothercommand = "!ping $externalhost"; my @lines = $t->cmd("$anothercommand"); my $lines="@lines"; if ($lines =~ /alive/) { @message = "Ping of $availablefirewall successful\nPing of $externalho +st successful\n$lines\n"; $key = "Green"; ################################################## ###to verify that pingtest is testing connectivity ###uncomment the following line. You will get ###notification of successes. Leave commented if ###you do not want notification of successes. ################################################## Notify ($key, $script, @message, @errors); } else { push @message,"Cannot ping $externalhost\n$lines\n"; $key = "RED"; Notify ($key, $script, @errors, @message); } close MAIL; my @returnvalues = ($key, $availablefirewall); print "@returnvalues"; sub Notify { ################################################ ###uses three inputs. typically script name### ###and the command or part of the script that### ###failed and a key value (severity) ### ################################################ my $notifylist = "your.name@yourcompany.com"; my $key = shift @_; my $script = shift @_; my $errors = "@_"; open (MAIL, "|mail $notifylist"); if ($key eq "Red") { open (MAIL, "|mail $notifylist"); print MAIL "SUBJECT:\[!!!\] $key failure of $script\n"; print MAIL "$key failure of $script: $errors\n"; close MAIL; } if ($key eq "Yellow") { open (MAIL, "|mail $notifylist"); print MAIL "SUBJECT:\[!!\] $key failure of $script\n"; print MAIL "$errors\n"; close MAIL; } if ($key eq "Green") { open (MAIL, "|mail $notifylist"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WhichHost AKA pingtest.pl
by grinder (Bishop) on Apr 17, 2002 at 20:04 UTC | |
by cybear (Monk) on Jun 03, 2002 at 23:55 UTC |