# FDO Standard Logger Configuration File
# Define Loggers
# set category level to INFO and appender to screen
log4perl.logger= INFO, Screen
# set category level to INFO and appender to screen plus logfiles
log4perl.logger.logfile= INFO, InfoFile, ErrFile
# set category level to INFO and appender to screen plus logfiles plus errors to email
log4perl.logger.logfile.logmail= INFO, Mailer
# Define Appenders
#Screen
log4perl.appender.Screen=Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr = 0
# [millisecs] source-filename line-number class - message newline
log4perl.appender.Screen.layout=PatternLayout
log4perl.appender.Screen.layout.ConversionPattern=[%d] %p %c %H:%F Ln:%L - %m%n
#InfoFile
log4perl.appender.InfoFile = Log::Log4perl::Appender::File
log4perl.appender.InfoFile.filename = sub {Get_LogFile("INFO");};
# log4perl.appender.InfoFile.mode = append
log4perl.appender.InfoFile.mode = clobber
# [millisecs] source-filename line-number class - message newline
log4perl.appender.InfoFile.layout=PatternLayout
log4perl.appender.InfoFile.layout.ConversionPattern=[%d] %c %H:%F Ln:%L - %m%n
#ErrFile
log4perl.filter.MatchErr = Log::Log4perl::Filter::LevelRange
log4perl.filter.MatchErr.LevelMin = WARN
log4perl.filter.MatchErr.LevelMax = FATAL
log4perl.filter.MatchErr.AcceptOnMatch = true
log4perl.appender.ErrFile = Log::Log4perl::Appender::File
log4perl.appender.ErrFile.filename = sub {Get_LogFile("ERROR");};
# log4perl.appender.ErrFile.mode = append
log4perl.appender.ErrFile.mode = clobber
# [millisecs] source-filename line-number class - message newline
log4perl.appender.ErrFile.layout=PatternLayout
log4perl.appender.ErrFile.layout.ConversionPattern=[%d] %c %H:%F Ln:%L - %m%n
log4perl.appender.ErrFile.Filter = MatchErr
#Mailer
log4perl.filter.MatchFatalErr = Log::Log4perl::Filter::LevelRange
log4perl.filter.MatchFatalErr.LevelMin = ERROR
log4perl.filter.MatchFatalErr.LevelMax = FATAL
log4perl.filter.MatchFatalErr.AcceptOnMatch = true
log4perl.appender.Mailer = Log::Dispatch::Email::MailSendmail
log4perl.appender.Mailer.to = ckelly@telesat.com
log4perl.appender.Mailer.from = ckelly@telesat.com
log4perl.appender.Mailer.subject = SCRIPT ERROR
log4perl.appender.Mailer.buffered = 0
log4perl.appender.Mailer.layout=PatternLayout
log4perl.appender.Mailer.layout.ConversionPattern=[%d] %c %H:%F Ln:%L - %m%n
log4perl.appender.Mailer.Filter = MatchFatalErr
####
#!/opt/perl/bin/perl
use strict;
use warnings;
sub Get_LogFile($) #logfile takes "INFO" or "ERROR"
{
my($fileType)= @_;
my($scriptName)= fileparse($0);
my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime;
my $curEpoch = sprintf("%4.4d%3.3d%2.2d%2.2d%2.2d",$year+1900, $yday+1, $hour, $min, $sec);
if (lc($fileType) =~ /^info/)
{
return "/tmp/$scriptName.$curEpoch.info.log";
}
elsif (lc($fileType) =~ /^error/)
{
return "/tmp/$scriptName.$curEpoch.err.log";
}
else
{
return "/tmp/$scriptName.$curEpoch.log";
}
}
1; # need this for the require to work in calling file
####
#!/opt/perl/bin/perl
use strict;
use warnings;
# 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
require "/usr/fds/fdo/scripts/Check_Inhibits.pl"; # should make this into a module
# Subroutine prototypes
sub Get_LogFile($); #logfile takes "INFO" or "ERROR"
sub Check_Inhibits($$$$);
# 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 at the logfile category
# which logs INFO and up messages to the screen and to a log file
# and WARN and up message to an additional error log file
Log::Log4perl->init("/usr/fds/fdo/scripts/log4perl_FDO.conf");
my($log) = Log::Log4perl->get_logger("logfile");
my($infoFileApp) = Log::Log4perl->appender_by_name("InfoFile");
my($errFileApp) = Log::Log4perl->appender_by_name("ErrFile");
my($infoLogFile) = $infoFileApp->filename();
my($errLogFile) = $errFileApp->filename();
$log->info("Execution Started");
$log->info("Log File: $infoLogFile");
$log->info("Error Log File: $errLogFile");
my($inhWarn) = Check_Inhibits("2009:016:22","2009:016:22:30", "/tmp/Test.inhibit.out", 30);
print "inhMsg:\n $inhWarn";
$log->info("Execution Complete");
exit 1; # successful end
####
#!/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
####
2008:352 UTC 22:53:47 23:10:33 00:21:51 01:33:08 01:50:13 .9 (N) 64.5
2009:004 11:53:56 13:22:10 14:50:24 3.1 (N) 50.9
2009:013 20:42:14 20:59:06 22:10:46 23:22:26 23:39:37 1.7 (N) 88.8
2009:015 21:31:25 21:48:29 22:59:37 00:10:45 00:27:29 2.7 (S) 72.2
2009:016 22:16:21 22:33:23 23:44:28 00:55:33 01:12:16 2.7 (S) 62.2
2009:041 19:17:16 19:34:06 20:45:41 21:57:16 22:14:26 1.1 (N) 97.6
2009:043 20:06:42 20:23:47 21:35:01 22:46:16 23:03:02 .2 (S) 86.9
2009:068 17:04:33 17:21:25 18:33:04 19:44:44 20:01:54 1.8 (N) 97.8
2009:070 17:55:22 18:12:27 19:23:46 20:35:04 20:51:50 2.7 (S) 99.4
2009:071 18:42:10 18:59:16 20:10:35 21:21:53 21:38:39 2.8 (S) 96.5