#!/opt/perl/bin/perl use strict; use warnings; sub Check_Inhibits($$$$){ # Check_Inhibits takes StartEpoch, EndEpoch, InhibitFile, Padding # Add in my file with the subroutine to generate the log file names # This is called by the loggers that output to log files - see logfile_FDO.conf # require "/usr/fds/fdo/scripts/Get_LogFile.pl"; # should make this into a module # Subroutine prototypes # sub Get_LogFile($); #logfile takes "INFO" or "ERROR" # PERL modules use Sys::Hostname; use File::Basename; use File::Copy; use Net::FTP; use Getopt::Long; use MIME::Lite; use Log::Dispatch::Email::MIMELite; use Log::Log4perl; # use Log::Log4perl qw(get_logger :no_extra_logdie_message) ; # initialize logger instance (?? from main script - how??) my($log) = Log::Log4perl->get_logger(); $log->info("Execution Started"); # get calling arguments my($startEp)=$_[0]; my($endEp)=$_[1]; my($inhibitFile)=$_[2]; my($padding) = $_[3]; $log->info("User Input - Checking Start Epoch entered: $startEp"); $log->info("User Input - Checking End Epoch entered: $endEp"); $log->info("User Input - Inhibit File entered: $inhibitFile"); $log->info("User Input - Inhibit Padding entered: $padding min"); # parse the input epochs # Start Epoch my($startEpYear, $startEpDay, $startEpHour, $startEpMin, $startEpSec, $startEpMsec) = split(/:/,$startEp); if (!defined $startEpYear || !defined $startEpDay) {$log->logdie("Start Epoch $startEp not defined (yyyy:dd[:hh:mm:ss:msc])\n")}; if (!defined $startEpHour) {$startEpHour=0}; if (!defined $startEpMin) {$startEpMin=0}; if (!defined $startEpSec) {$startEpSec=0}; if (!defined $startEpMsec) {$startEpMsec=0}; my($startEpNSec) = (((($startEpDay*24.0)+$startEpHour)*60.0)+$startEpMin)*60.0 + $startEpSec + $startEpMsec/1000.0; # End Epoch my($endEpYear, $endEpDay, $endEpHour, $endEpMin, $endEpSec, $endEpMsec) = split(/:/,$endEp); if (!defined $endEpYear || !defined $endEpDay) {$log->logdie("Start Epoch $endEp not defined (yyyy:dd[:hh:mm:ss:msc])\n")}; if (!defined $endEpHour) {$endEpHour=0}; if (!defined $endEpMin) {$endEpMin=0}; if (!defined $endEpSec) {$endEpSec=0}; if (!defined $endEpMsec) {$endEpMsec=0}; my($endEpNSec) = (((($endEpDay*24.0)+$endEpHour)*60.0)+$endEpMin)*60.0 + $endEpSec + $endEpMsec/1000.0; # Convert padding from minutes to seconds my($paddingSec)=$padding*60.0; # open inhibit file for read access open(INH_FH, "<$inhibitFile") || $log->logdie("Could not open inhibit file $inhibitFile: $!\n"); # my($inhMsg)=''; while() { next unless (m#^\s+\d+:\d+# ); next unless (my(@inhArray)=m#(\d+:\d+:*\d*:*\d*)#g); # print "@inhArray,\n"; my($inhStartYear,$inhStartDay) = split(/:/,$inhArray[0]); my($inhEndYear) = $inhStartYear; my($inhEndDay) = $inhStartDay; my($inhStartHour,$inhStartMin, $inhStartSec) = split(/:/,$inhArray[1]); my($inhEndHour,$inhEndMin, $inhEndSec) = split(/:/,$inhArray[$#inhArray]); if ($inhEndHour < $inhStartHour) {$inhEndDay = $inhEndDay +1}; my($inhStartNSec) = (((($inhStartDay*24.0)+$inhStartHour)*60.0)+$inhStartMin)*60.0 + $inhStartSec - $paddingSec; my($inhEndNSec) = (((($inhEndDay*24.0)+$inhEndHour)*60.0)+$inhEndMin)*60.0 + $inhEndSec + $paddingSec; # print ("inhStartNSec = $inhStartNSec and inhEndNSec = $inhEndNSec\n"); # print ("startEpNSec = $startEpNSec and endEpNSec = $endEpNSec\n"); if ( ($inhStartNSec <= $startEpNSec && $startEpNSec <= $inhEndNSec) || ($inhStartNSec <= $endEpNSec && $endEpNSec <= $inhEndNSec)){ $log->warn("Event ($startEp \- $endEp) and inhibit conflict: $_\n"); $inhMsg .= "Event ($startEp \- $endEp) and inhibit conflict: $_\n"; } elsif ($inhStartDay == $startEpDay || $inhEndDay == $startEpDay || $inhEndDay == $startEpDay || $inhEndDay == $startEpDay || $inhStartDay == $endEpDay || $inhEndDay == $endEpDay || $inhEndDay == $endEpDay || $inhEndDay == $endEpDay){ $log->info("Inhibit occurs on event day ($startEp \- $endEp) without conflict: $_\n"); $inhMsg .= "Inhibit occurs on event day ($startEp \- $endEp) without conflict: $_\n"; } } close(INH_FH); $log->info("Execution Complete"); return $inhMsg; } 1; # need this for the require to work in calling file