#!/bin/perl -w use Net::Telnet(); use Net::FTP(); use strict; unless (@ARGV) { print "\n\n\tUsage: pingtest.pl \n\n"; exit(0); } chomp (my $CALLING_SCRIPT = "$ARGV[0]"); ############################################################################### ### Note: this script only tests for hosts external to the Boeing network ### ### that are reached through a firewall ### ############################################################################### my $FIREWALL; my @FIREWALLS = qw (gate.somecompany.com othergate.somecompany.com); my @REACHABLE_FIREWALLS; my $REACHABLE_FIREWALL; my @USEABLE_FIREWALLS; my $USEABLE_FIREWALL; my @TOUCHABLE_FIREWALLS; my $TOUCHABLE_FIREWALL; my $FTP_SESSION; my $SUCCESSFUL_PROXY_CONNECTION = "none"; my $EXTERNAL_HOST = "192.xxx.185.xxx"; my $KEY = "default"; my @MESSAGE; umask 027; ############################################################################### ### Beginning of main ### ############################################################################### @REACHABLE_FIREWALLS = pingFireWall(@FIREWALLS); @USEABLE_FIREWALLS = pingExternalHost(@REACHABLE_FIREWALLS); testFtpConnectivity(@USEABLE_FIREWALLS); print "$KEY $SUCCESSFUL_PROXY_CONNECTION"; if (($CALLING_SCRIPT eq "manualtest") or ($KEY ne "Working")) { `/opt/ECXpert_custom/scripts/notify.pl -k $KEY -s $CALLING_SCRIPT \"@MESSAGE\" `; exit(2); } ############################################################################### ### Beginning of subroutine sections ### ############################################################################### sub pingFireWall { @FIREWALLS = @_; foreach $FIREWALL (@FIREWALLS) { my $PINGFIREWALL = `/usr/sbin/ping \"$FIREWALL\"`; if ($PINGFIREWALL =~ /alive/) { push @MESSAGE, "Ping of $FIREWALL successful..."; $KEY = "Working"; push (@REACHABLE_FIREWALLS, $FIREWALL); } else { push @MESSAGE, "Ping of $FIREWALL failed!..."; $KEY = "Serious"; } } ### error check and notify section unless (@REACHABLE_FIREWALLS >= 1) { push @MESSAGE, "Unable to reach any Firewall servers!!..."; $KEY = "Critical"; } return(@REACHABLE_FIREWALLS); } sub pingExternalHost { my @LINES; my $LINE; my $T; @REACHABLE_FIREWALLS = @_; foreach $REACHABLE_FIREWALL (@REACHABLE_FIREWALLS) { $T = new Net::Telnet (Timeout => 20, Prompt => '/tination/'); $T->open("$REACHABLE_FIREWALL"); $T->waitfor('/tination/'); if ($T) { push @TOUCHABLE_FIREWALLS, $REACHABLE_FIREWALL; push @MESSAGE, "Telnet to $REACHABLE_FIREWALL successful..."; @LINES = $T->cmd("!ping $EXTERNAL_HOST"); $LINE ="@LINES"; if ($LINE =~ /alive/) { push @MESSAGE, "Ping of $EXTERNAL_HOST from $REACHABLE_FIREWALL sucessful..."; $KEY = "Working"; push @USEABLE_FIREWALLS, $REACHABLE_FIREWALL; } else { push @MESSAGE, "Ping of $EXTERNAL_HOST from $REACHABLE_FIREWALL failed!..."; } } else { push @MESSAGE, "Telnet to $REACHABLE_FIREWALL failed!..."; push @MESSAGE, $LINE; $KEY = "Serious"; } } ### error check and notify section unless (@TOUCHABLE_FIREWALLS >= 1) { push @MESSAGE, "Cannot Telnet to either Firewall!!..."; $KEY = "Critical"; } unless (@USEABLE_FIREWALLS >= 1) { $KEY = "Critical"; } return(@USEABLE_FIREWALLS); } sub testFtpConnectivity { @USEABLE_FIREWALLS = @_; foreach $USEABLE_FIREWALL (@USEABLE_FIREWALLS) { if ($FTP_SESSION = Net::FTP-> new("$USEABLE_FIREWALL", Debug => 0)) { $SUCCESSFUL_PROXY_CONNECTION = $USEABLE_FIREWALL; push @MESSAGE, "Ftp connection to $USEABLE_FIREWALL successful..."; $KEY = "Working"; last; } else { push @MESSAGE, "Ftp connection to $USEABLE_FIREWALL failed!!!..."; $KEY = "Serious"; } } ### error check and notify section unless ($SUCCESSFUL_PROXY_CONNECTION ne "none") { push @MESSAGE, "No FTP connections could be made!!!..."; $KEY = "Critical"; } return ($SUCCESSFUL_PROXY_CONNECTION); }