CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
problem related to date

 



perlisgreat
Novice

Jul 14, 2009, 1:17 AM

Post #1 of 1 (2336 views)
problem related to date Can't Post

Hi,

My script is here--


Code
#!/usr/bin/perl 
no warnings "uninitialized";
use File::Copy;
use File::stat;
use Time::Local;
use IO::Handle;
use DateTime;
use Getopt::Long;
use File::Glob ':glob';


my $Summary;
my $Individual;
my $Diagnostics;
my $All;
my $help;

main();

sub main
{
$result = GetOptions ("LogDir=s" => \$LogDir,
"Summary" => \$Summary,
"Individual=s" => \$Individual ,
"Diagnostics=s" => \$Diagnostics,
"Prefix=s" => \$Prefix,
"All" => \$All,
"help" => \$help);
usage_help() if($help);
usage_help() unless($Prefix);
usgage_help() unless($LogDir);

if($LogDir)
{
printf "LOG DIR = $LogDir\n";
die "Log dir '$LogDir' doesn't exist" unless -d $LogDir;
}

$glob_path = "$LogDir/${Prefix}*";
@log_paths = glob $glob_path or die "No files found in '$glob_path'";
#printf "log files = \n";
#print @log_paths;
#printf "\n";

if($Summary)
{
process_summaryreport (@log_paths);
}


# This function tells the usage of the script.
sub usage_help
{
printf <<EOF
Script usage is
Scriptname --Summary
Scriptname --Indiviual=Arcotid/QNA/OTP/Password/All/Arcotid Revoke/Expire/All/QNA number
Scriptname --Diagnostics=username/system
Scriptname --ALL
printf "Example:-> perl WFLogStat.pl --LogDir = <DirName if current then put '.'> --Prefix = <arcotwebfort> --Summary";
printf "Example:-> perl WFLogStat.pl --LogDir = <DirName if current then put '.'> --Prefix = <arcotwebfort> --Individual=ArcotID/QnA/OTP/UP/ALL/ArcotID_Expired/ArcotID_Reset/ArcotID_Revoke/Total/UserQnA";
printf "Example:-> perl WFLogStat.pl --LogDir = <DirName if current then put '.'> --Prefix = <arcotwebfort> --Diagnostics=User_Name/System ";
EOF



}

# This function in turn calls many functions which give us the summary about the AOK webfort logs.
sub process_summaryreport
{
printf "in process summary\n";


Avg_Time_Taken_Per_Transaction (@log_paths);


}


# This function gives the Average time taken for a transaction to complete. The transaction can be for ArcotID
# or QnA or OTP or User Password.

sub Avg_Time_Taken_Per_Transaction
{
avg_time_taken_in_UP(@log_paths);
avg_time_taken_in_QnA(@log_paths);
avg_time_taken_in_OTP(@log_paths);


}
sub avg_time_taken_in_QnA
{

die if not @_;
my @log_files = @_;
open(AVG_OUT,">avg_time") or die "cannot create file avg_time for writing";
my %mon2num = qw(
Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6
Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12
);

my ( $start_dt, $end_dt );

for my $log_file (@log_files)
{
open my $log, '<', $log_file or die "Can't open '$log_file' for reading.";
printf AVG_OUT "Processing file $log_file...\n";
while( <$log> )
{
s{\s+\z}{};
#m/^\s*\w+\s+(\w+)\s+(\d+)\s+(\d\d:\d\d:\d\d\.\d\d\d)\s+(\d+)\s+..*pid\s+(\d+)\s+tid\s+(\d+):..*RiskServer : Read.*/i)
if (/(?:Entering|Exiting) QnAModule::authenticate/)
{
$end_dt = '';
my @dtA = split;
my @time = split /[:.]/, $dtA[3];

( /Exiting/ ? $end_dt : $start_dt ) = DateTime->new
(
year => $dtA[4],
month => $mon2num{ $dtA[1] },
day => $dtA[2],
hour => $time[0],
minute => $time[1],
second => $time[2],
nanosecond => $time[3],
);


if ($end_dt && $start_dt)
{
print AVG_OUT "start: ", $start_dt, "\n";
print AVG_OUT "end: ", $end_dt, "\n";
my $e = $end_dt->subtract_datetime($start_dt);
printf AVG_OUT "elapsed time for QnA Module: %s year(s), %s month(s), %s week(s), %s day(s), %s hour(s), %s min, %s sec, %s ms\n",
$e->years, $e->months, $e->weeks, $e->days, $e->hours,
$e->minutes, $e->seconds, $e->nanoseconds;

}
}
}
close $log or warn;
}
close (AVG_OUT);
}

sub avg_time_taken_in_OTP
{

die if not @_;
my @log_files = @_;
open(AVG_OUT,">>avg_time") or die "cannot create file avg_time for writing";

my %mon2num = qw(
Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6
Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12
);

my ( $start_dt, $end_dt );

for my $log_file (@log_files)
{
open my $log, '<', $log_file or die "Can't open '$log_file' for reading.";
printf AVG_OUT "Processing file $log_file...\n";
while( <$log> )
{
s{\s+\z}{};
if (/(?:Entering|Exiting) OTPAuthModule::authenticate/)
{
$end_dt = '';
my @dtA = split;
my @time = split /[:.]/, $dtA[3];
( /Exiting/ ? $end_dt : $start_dt ) = DateTime->new
(
year => $dtA[4],
month => $mon2num{ $dtA[1] },
day => $dtA[2],
hour => $time[0],
minute => $time[1],
second => $time[2],
nanosecond => $time[3],
);

if ($end_dt && $start_dt)
{
print AVG_OUT "start: ", $start_dt, "\n";
print AVG_OUT "end: ", $end_dt, "\n";
my $e = $end_dt->subtract_datetime($start_dt);
printf AVG_OUT "elapsed time for OTP Module: %s year(s), %s month(s), %s week(s), %s day(s), %s hour(s), %s min, %s sec, %s ms\n",
$e->years, $e->months, $e->weeks, $e->days, $e->hours,
$e->minutes, $e->seconds, $e->nanoseconds;

}
}
}
close $log or warn;
}
close (AVG_OUT);
}

sub avg_time_taken_in_UP
{

die if not @_;
my @log_files = @_;
open(AVG_OUT,">>avg_time") or die "cannot create file avg_time for writing";
my %mon2num = qw(
Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6
Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12
);

my ( $start_dt, $end_dt );

for my $log_file (@log_files)
{
open my $log, '<', $log_file or die "Can't open '$log_file' for reading.";
printf AVG_OUT "Processing file $log_file...\n";
while( <$log> )
{
s{\s+\z}{};
if (/(?:Entering|Exiting) UPAuthModule::authenticate/)
{
$end_dt = '';
my @dtA = split;
my @time = split /[:.]/, $dtA[3];
( /Exiting/ ? $end_dt : $start_dt ) = DateTime->new
(
year => $dtA[4],
month => $mon2num{ $dtA[1] },
day => $dtA[2],
hour => $time[0],
minute => $time[1],
second => $time[2],
nanosecond => $time[3],
);

if ($end_dt && $start_dt)
{
print AVG_OUT "start: ", $start_dt, "\n";
print AVG_OUT "end: ", $end_dt, "\n";
my $e = $end_dt->subtract_datetime($start_dt);
printf AVG_OUT "elapsed time for User Password Module: %s year(s), %s month(s), %s week(s), %s day(s), %s hour(s), %s min, %s sec, %s ms\n",
$e->years, $e->months, $e->weeks, $e->days, $e->hours,
$e->minutes, $e->seconds, $e->nanoseconds;

}
}
}
close $log or warn;
}
close (AVG_OUT);


}


When i run the perl script i get this warning , which i want to remove.
The output is coming fine.

I am running the script like this--


Code
C:\Perl Script>perl WFLogStat.pl --LogDir=. --Prefix=arcotwebfort --Summary 

when i run the script , i get this messages--

The 'hour' parameter (undef) to DateTime::new was an 'undef', which is not one o
f the allowed types: scalar
at C:/Perl/lib/Params/ValidatePP.pm line 634
Params::Validate::__ANON__('The \'hour\' parameter (undef) to DateTime::
new was an \'unde...') called at C:/Perl/lib/Params/ValidatePP.pm line 485
Params::Validate::_validate_one_param('undef', 'HASH(0x183182c)', 'HASH(
0x1d39618)', 'The \'hour\' parameter (undef)') called at C:/Perl/lib/Params/Vali
datePP.pm line 345
Params::Validate::validate('ARRAY(0x1c2d24c)', 'HASH(0x1d3978c)') called
at C:/Perl/lib/DateTime.pm line 171
DateTime::new('undef', 'year', 'undef', 'month', 'undef', 'day', 'undef'
, 'hour', 'undef', ...) called at WFLogStat.pl line 372
main::avg_time_taken_in_UP('./arcotwebfort.log', './arcotwebfort_20May09
_00_03_55.log', './arcotwebfort_20May09_15_12_18.log', './arcotwebfort_20May09_2
3_32_56.log', './arcotwebfort_29May09_18_29_45.log', './arcotwebfort_29May09_19_
17_47.log') called at WFLogStat.pl line 231
main::Avg_Time_Taken_Per_Transaction('./arcotwebfort.log', './arcotwebfo
rt_20May09_00_03_55.log', './arcotwebfort_20May09_15_12_18.log', './arcotwebfort
_20May09_23_32_56.log', './arcotwebfort_29May09_18_29_45.log', './arcotwebfort_2
9May09_19_17_47.log') called at WFLogStat.pl line 182
main::process_summaryreport('./arcotwebfort.log', './arcotwebfort_20May0
9_00_03_55.log', './arcotwebfort_20May09_15_12_18.log', './arcotwebfort_20May09_
23_32_56.log', './arcotwebfort_29May09_18_29_45.log', './arcotwebfort_29May09_19
_17_47.log') called at WFLogStat.pl line 84
main::main() called at WFLogStat.pl line 57

I have removed some part of code so the warning lines may not match.

Kindly suggest what is wrong here.

The sample log file is--


Code
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 150: 10090433: Entering UPAuthModule::authenticate 
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO: pid 2172 tid 688: 150: 10090433: UPAuth Session Id :[1:10090433]
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO: pid 2172 tid 688: 150: 10090433: UpAuth User DB Query is based on username[123456] and groupID[1007]:
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO: pid 2172 tid 688: 150: 10090433: Number of rows fetched from DB : 1
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO: pid 2172 tid 688: 150: 10090433: UPAuth SUCCESS for user[123456]
Wed May 20 00:03:52.774 2009 Morocco Standard Time INFO: pid 2172 tid 688: 150: 10090433: Exiting UPAuthModule::authenticate


One more thing when i run the program individually, i do not get any errors.

Kindly suggest what can be wrong here.

Thanks
NT

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives