mainfile . . . . sub r21HostAvailability { #create the error logging file my $errorLoggingFile = "datetime"."_ErrorLogging"; #need to get localDateTime my $localPath = "C:\\Rescue21\\installs\\"; my @pinghosts = HostMap::read($myMapFileToUse); my $strPingHost = ""; foreach my $hosts(@pinghosts) { $strPingHost = $strPingHost . Host::get_ip($hosts) . " "; } if( -e $fErrorLogFile ) { #open(ERROR_LOG, "+>>$fErrorLogFile"); open( $stdout , ">&STDOUT" ); open( $stderr , ">&STDERR" ); open( STDOUT , "| tee -a $fErrorLogFile" ); select STDOUT; $| = 1; print "#######################################################\n"; print "Testing IPPLAN\n"; print "#######################################################\n\n"; testIpPlan(); print "#######################################################\n"; print "Testing the host availability for the region\n"; print "#######################################################\n\n"; open( HOST_AVAIL, "perl region_test.pl $strPingHost |"); while() { print $_; if( length $_ > 1 ) { print ERROR_LOG "$_"; } } close(HOST_AVAIL); } else { print "File $_ not present!\n"; } close( STDERR ); close( STDOUT ); open( STDOUT, ">&", $stdout ); open( STDERR , ">&" , $stderr ); } sub testIpPlan { use constant CMD_SUCCESS => 0; use constant CMD_FAILURE => 1; local $hname = ${$siteToUse}{HostFile}; my $hostlist = ""; my $reg_abbr = ""; my $dirIpPlan = ".\\IpPlan\\"; my $labTest = "FALSE"; #if using a lab, we want to do nothing if( $hname =~ m/(preswit\d_|sim_|swit\d+_)/i ) { print "INFO: Using a lab, no IP plan to ping THIS WILL BE FOR TESTING ONLY\n"; print "Will use either Eastern Shore IP Plan or Atlantic City IP Plan\n"; print "Based upon what Host is being used\n"; $labTest = 'TRUE'; if( $hname =~ m/atlantic_city/i ) { $hname = $&; $hname =~ s/_/ /g; } elsif( $hanem =~ m/eastern_shore/i ) { $hname = $&; $hname =~ s/_/ /g; } else { die "bad host passed in\n"; } #find the abbreviation $hostlist = new GCCList( $hname ); $reg_abbr = $hostlist->{ region_abbrev }; } else { #find the abbreviation my $hostlist = new GCCList( $hname =~ s/_/ /g ); my $reg_abbr = $hostlist->{ region_abbrev }; print "reg_abbr = $reg_abbr\n"; } $hostlist = new GCCList( $hname ); $reg_abbr = $hostlist->{ region_abbrev }; #create the file name my $fIpPlanName = "region_data_$reg_abbr\.csv"; #make sure the file is open my @aIpPlan = (); if( -e $dirIpPlan.$fIpPlanName ) { local $tfile = $dirIpPlan.$fIpPlanName; open(IPPLAN, "<$tfile"); @aIpPlan = ; close (IPPLAN); } else { print "ERROR: $fIpPlanName NOT FOUND~\n"; } if( -e $fErrorLogFile ) { print "#######################################################\n"; print "Testing the IP Plan for the $hname \n"; print "#######################################################\n\n"; #PARSE OUT THE CONTENTS FOR EACH ONE AND PING IT foreach my $ipaddr(@aIpPlan) { $retval = CMD_SUCCESS; my($abbrv, $region_name, $site, $sitename, $ip, $device, $state, $yn, $logical_name) = split(/\,/,$ipaddr); if( $labTest eq 'TRUE') { $ip = '127.0.0.1'; } my $pinging = Net::Ping->new( "tcp" , 5 ) || die "Abort. Unable to create ping object\n"; my $retval = ( $pinging->ping( $ip ) ? 0 : 1 ); print( ( ( 0 == $retval ) ? "alive : " : "NOT alive : " ) , $ip ," [", $sitename ," ", $device , "]\n" ); } } }