[otrs-cvs] CVS: otrs/bin mkStats.pl,1.34,1.35
cvs-log at otrs.org
cvs-log at otrs.org
Thu Jul 13 13:43:22 CEST 2006
- Previous message: [otrs-cvs] CVS: otrs/Kernel/System Stats.pm,NONE,1.1
- Next message: [otrs-cvs] CVS: otrs/Kernel/Output/HTML/Standard
AgentStatsDelete.dtl,NONE,1.1 AgentStatsEditRestrictions.dtl,NONE,1.1
AgentStatsEditSpecification.dtl,NONE,1.1
AgentStatsEditValueSeries.dtl,NONE,1.1 AgentStatsEditXaxis.dtl,NONE,1.1
AgentStatsImport.dtl,NONE,1.1 AgentStatsOverview.dtl,NONE,1.1
AgentStatsPrint.dtl,NONE,1.1 AgentStatsView.dtl,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/otrs/bin
In directory lancelot:/tmp/cvs-serv2326
Modified Files:
mkStats.pl
Log Message:
mkStats.pl of the new stats module
Index: mkStats.pl
===================================================================
RCS file: /home/cvs/otrs/bin/mkStats.pl,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -r1.34 -r1.35
*** mkStats.pl 13 Jun 2006 08:14:39 -0000 1.34
--- mkStats.pl 13 Jul 2006 10:43:20 -0000 1.35
***************
*** 1,5 ****
#!/usr/bin/perl -w
# --
! # SendStats.pl - send stats output via email
# Copyright (C) 2001-2006 Martin Edenhofer <martin+code at otrs.org>
# --
--- 1,5 ----
#!/usr/bin/perl -w
# --
! # mkStats.pl - send stats output via email
# Copyright (C) 2001-2006 Martin Edenhofer <martin+code at otrs.org>
# --
***************
*** 30,33 ****
--- 30,34 ----
use vars qw($VERSION);
+
$VERSION = '$Revision$';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
***************
*** 41,45 ****
use Kernel::System::Email;
use Kernel::System::CheckItem;
! use Kernel::Output::HTML::Layout;
# --
--- 42,50 ----
use Kernel::System::Email;
use Kernel::System::CheckItem;
! use Kernel::System::Stats;
! use Kernel::System::Group;
! use Kernel::System::User;
! use Kernel::System::CSV;
!
# --
***************
*** 47,62 ****
# --
my %CommonObject = ();
! $CommonObject{ConfigObject} = Kernel::Config->new();
! $CommonObject{LogObject} = Kernel::System::Log->new(
LogPrefix => 'OTRS-SendStats',
%CommonObject,
);
! $CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
! $CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
! # create needed objects
! $CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
! $CommonObject{CheckItemObject} = Kernel::System::CheckItem->new(%CommonObject);
! $CommonObject{EmailObject} = Kernel::System::Email->new(%CommonObject);
! $CommonObject{LayoutObject} = Kernel::Output::HTML::Layout->new(%CommonObject);
# --
--- 52,70 ----
# --
my %CommonObject = ();
! $CommonObject{UserID} = 1;
! $CommonObject{ConfigObject} = Kernel::Config ->new();
! $CommonObject{LogObject} = Kernel::System::Log ->new(
LogPrefix => 'OTRS-SendStats',
%CommonObject,
);
! $CommonObject{CSVObject} = Kernel::System::CSV ->new(%CommonObject);
! $CommonObject{TimeObject} = Kernel::System::Time ->new(%CommonObject);
! $CommonObject{MainObject} = Kernel::System::Main ->new(%CommonObject);
! $CommonObject{DBObject} = Kernel::System::DB ->new(%CommonObject);
! $CommonObject{GroupObject} = Kernel::System::Group ->new(%CommonObject);
! $CommonObject{UserObject} = Kernel::System::User ->new(%CommonObject);
! $CommonObject{StatsObject} = Kernel::System::Stats ->new(%CommonObject);
! $CommonObject{CheckItemObject} = Kernel::System::CheckItem ->new(%CommonObject);
! $CommonObject{EmailObject} = Kernel::System::Email ->new(%CommonObject);
# --
***************
*** 64,103 ****
# --
my %Opts = ();
! getopt('mrsbhop', \%Opts);
if ($Opts{'h'}) {
print "mkStats.pl <Revision $VERSION> - OTRS cmd stats\n";
! print "Copyright (c) 2001-2005 Martin Edenhofer <martin\@otrs.org>\n";
! print "usage: mkStats.pl -m <REPORT_MODULE> [-p <PARAM_STRING> e. g. 'Year=1977&Month=10'] [-o /output/dir/] [-r <RECIPIENT> -s <SENDER>] [-b <MESSAGE>]\n";
exit 1;
}
-
# required output param check
if (!$Opts{'o'} && !$Opts{'r'}) {
! print STDERR "ERROR: Need -o /tmp/ OR -r email\@example.com [-b 'some message']\n";
exit 1;
}
# stats module check
! if (!$Opts{'m'}) {
! print STDERR "ERROR: Need -m StateAction\n";
exit 1;
}
# fill up body
! if (!$Opts{'b'} && $Opts{'p'}) {
! $Opts{'b'} .= "Stats with following options:\n\n";
! $Opts{'b'} .= "Module: $Opts{'m'}\n";
my @P = split(/&/, $Opts{'p'}||'');
foreach (@P) {
my ($Key, $Value) = split(/=/, $_, 2);
! $Opts{'b'} .= "$Key: $Value\n";
}
}
! if (!$Opts{'b'}) {
! print STDERR "ERROR: Need -b 'some message'\n";
exit 1;
}
# recipient check
if ($Opts{'r'}) {
if (!$CommonObject{CheckItemObject}->CheckEmail(Address => $Opts{'r'})) {
! print STDERR "ERROR: ".$CommonObject{CheckItemObject}->CheckError()."\n";
exit 1;
}
--- 72,114 ----
# --
my %Opts = ();
! getopt('nrsmhop', \%Opts);
if ($Opts{'h'}) {
print "mkStats.pl <Revision $VERSION> - OTRS cmd stats\n";
! print "Copyright (C) 2003-2006 OTRS GmbH, http://www.otrs.com/\n";
! print "usage: mkStats.pl -n <StatNumber> [-p <PARAM_STRING>] [-o <DIRECTORY>] [-r <RECIPIENT> -s <SENDER>] [-m <MESSAGE>]\n";
! print " <PARAM_STRING> e. g. 'Year=1977&Month=10' (only for static files)\n";
! print " <DIRECTORY> /output/dir/\n";
exit 1;
}
# required output param check
if (!$Opts{'o'} && !$Opts{'r'}) {
! print STDERR "ERROR: Need -o /tmp/ OR -r email\@example.com [-m 'some message']\n";
exit 1;
}
# stats module check
! if (!$Opts{'n'}) {
! print STDERR "ERROR: Need -n StatNumber\n";
exit 1;
}
# fill up body
! if (!$Opts{'m'} && $Opts{'p'}) {
! $Opts{'m'} .= "Stats with following options:\n\n";
! $Opts{'m'} .= "StatNumber: $Opts{'n'}\n";
my @P = split(/&/, $Opts{'p'}||'');
foreach (@P) {
my ($Key, $Value) = split(/=/, $_, 2);
! $Opts{'m'} .= "$Key: $Value\n";
}
}
! # only necessary for emails
! if (!$Opts{'m'} && $Opts{'r'}) {
! print STDERR "ERROR: Need -m 'some message (necessary for emails)'\n";
exit 1;
}
+
# recipient check
if ($Opts{'r'}) {
if (!$CommonObject{CheckItemObject}->CheckEmail(Address => $Opts{'r'})) {
! print STDERR "ERROR: " . $CommonObject{CheckItemObject}->CheckError() . "\n";
exit 1;
}
***************
*** 112,242 ****
exit 1;
}
- my $Format = 'CSV';
- my $Module = "Kernel::System::Stats::$Opts{'m'}";
! # get module config
! my %Config = %{$CommonObject{ConfigObject}->Get('SystemStatsMap')};
! my %ConfigItem = ();
! foreach my $Stats (sort keys %Config) {
! if ($Config{$Stats}->{Module} && $Config{$Stats}->{Module} eq $Module) {
! %ConfigItem = %{$Config{$Stats}};
}
- }
- if (!%ConfigItem) {
- print STDERR "ERROR: No Config found for '$Module'!\n";
- exit 1;
- }
! if (eval "require $Module") {
! my %GetParam = ();
! my $StatsModule = $Module->new(%CommonObject);
! # set std params
! my ($s,$m,$h, $D,$M,$Y, $wd,$yd,$dst) = localtime(time());
! $Y = $Y+1900;
! $M++;
! $GetParam{Year} = $Y;
! $GetParam{Month} = $M;
! $GetParam{Day} = $D;
! # get params from -p
! my @Params = $StatsModule->Param();
! foreach my $ParamItem (@Params) {
! if (!$ParamItem->{Multiple}) {
! my $Value = GetParam(
! Param => $ParamItem->{Name},
! );
! if (defined($Value)) {
! $GetParam{$ParamItem->{Name}} = GetParam(
Param => $ParamItem->{Name},
);
! }
! elsif (defined($ParamItem->{SelectedID})) {
! $GetParam{$ParamItem->{Name}} = $ParamItem->{SelectedID};
! }
! # print STDERR "$ParamItem->{Name}: $GetParam{$ParamItem->{Name}}\n";
! }
! else {
! my @Value = GetArray(
! Param => $ParamItem->{Name},
! );
! if (@Value) {
! $GetParam{$ParamItem->{Name}} = \@Value;
! }
! elsif (defined($ParamItem->{SelectedID})) {
! $GetParam{$ParamItem->{Name}} = [$ParamItem->{SelectedID}];
! }
! # print STDERR "$ParamItem->{Name}: $GetParam{$ParamItem->{Name}}\n";
! }
! }
! my $Time = sprintf("%02d:%02d:%02d", $h,$m,$s);
! # get data
! my @Data = $StatsModule->Run(%GetParam);
!
! my $TitleArrayRef = shift (@Data);
! my $Title = $TitleArrayRef->[0];
! my $HeadArrayRef = shift (@Data);
! my $CountData = @Data;
! # add sum y
! if ($ConfigItem{SumRow}) {
! push (@{$HeadArrayRef}, 'Sum');
! foreach my $Col (@Data) {
! my $Sum = 0;
! foreach (@{$Col}) {
! if ($_ =~ /[0-9]/ && $_ !~ /[A-z]/i) {
! $Sum = $Sum + $_;
}
}
! push (@{$Col}, $Sum);
! }
! }
! # add sum x
! if ($ConfigItem{SumCol}) {
! my @R1 = ();
! foreach my $Col (@Data) {
! my $Count = -1;
! foreach my $Dig (@{$Col}) {
! $Count++;
! if ($Dig =~ /[0-9]/ && $Dig !~ /[A-z]/i) {
! if ($R1[$Count]) {
! $R1[$Count] = $R1[$Count] + $Dig;
! }
! else {
! $R1[$Count] = $Dig;
! }
}
}
}
- # add sum
- if (!defined($R1[0])) {
- $R1[0] = 'Sum';
- }
- push (@Data, \@R1);
}
- my $Output = '';
- my %Attachment = ();
# generate output
! if ($Format eq 'CSV') {
! $ConfigItem{Module} =~ s/^.*::(.+?)$/$1/;
! $Output = "$ConfigItem{Name}: $Title; Created: $Y-$M-$D $Time\n";
! $Output .= $CommonObject{LayoutObject}->OutputCSV(
! Head => $HeadArrayRef,
! Data => \@Data,
! );
! # return csv to download
! my ($s,$m,$h, $D,$M,$Y, $wd,$yd,$dst) = localtime(time);
! $Y = $Y+1900;
! $M++;
! $M = sprintf("%02d", $M);
! $D = sprintf("%02d", $D);
! $h = sprintf("%02d", $h);
! $m = sprintf("%02d", $m);
! %Attachment = (
! Filename => "$ConfigItem{Module}"."_"."$Y-$M-$D"."_"."$h-$m.csv",
! ContentType => "text/csv",
! Content => $Output,
! Encoding => "base64",
! Disposition => "attachment",
! );
! }
# write output
if ($Opts{'o'}) {
--- 123,217 ----
exit 1;
}
! if ($Opts{'n'}) {
! my $StatNumber = $Opts{'n'};
! my $StatID = $CommonObject{StatsObject}->StatNumber2StatID(StatNumber => $StatNumber);
! if (!$StatID) {
! print STDERR "ERROR: No StatNumber: $Opts{'n'}\n";
! exit 1;
}
! my ($s,$m,$h, $D,$M,$Y) = $CommonObject{TimeObject}->SystemTime2Date(
! SystemTime => $CommonObject{TimeObject}->SystemTime(),
! );
!
! my %GetParam = ();
! my $Stat = $CommonObject{StatsObject}->StatsGet(StatID => $StatID);
!
! if ($Stat->{StatType} eq 'static') {
! $GetParam{Year} = $Y;
! $GetParam{Month} = $M;
! $GetParam{Day} = $D;
!
! # get params from -p
! # only for static files
! my $Params = $CommonObject{StatsObject}->GetParams(StatID => $StatID);
! foreach my $ParamItem (@{$Params}) {
! if (!$ParamItem->{Multiple}) {
! my $Value = GetParam(
Param => $ParamItem->{Name},
);
! if (defined($Value)) {
! $GetParam{$ParamItem->{Name}} = GetParam(
! Param => $ParamItem->{Name},
! );
! }
! elsif (defined($ParamItem->{SelectedID})) {
! $GetParam{$ParamItem->{Name}} = $ParamItem->{SelectedID};
}
}
! else {
! my @Value = GetArray(
! Param => $ParamItem->{Name},
! );
! if (@Value) {
! $GetParam{$ParamItem->{Name}} = \@Value;
! }
! elsif (defined($ParamItem->{SelectedID})) {
! $GetParam{$ParamItem->{Name}} = [$ParamItem->{SelectedID}];
}
}
}
}
+ elsif ($Stat->{StatType} eq 'dynamic') {
+ %GetParam = %{$Stat};
+ }
+
+ # run stat...
+ my @StatArray = @{$CommonObject{StatsObject}->StatsRun(
+ StatID => $StatID,
+ GetParam => \%GetParam,
+ )};
# generate output
! my $TitleArrayRef = shift (@StatArray);
! my $Title = $TitleArrayRef->[0];
! my $HeadArrayRef = shift (@StatArray);
! my $CountStatArray = @StatArray;
! my $Time = sprintf("%04d-%02d-%02d %02d:%02d:%02d",$Y,$M,$D,$h,$m,$s);
! if (!@StatArray) {
! push(@StatArray, [' ',0]);
! }
!
! # Greate the CVS data
! my $Output = "Name: $Title; Created: $Time\n";
! $Output .= $CommonObject{CSVObject}->Array2CSV(
! Head => $HeadArrayRef,
! Data => \@StatArray,
! );
!
! # save the csv with the title and timestamp as filename
! my $Filename = $CommonObject{StatsObject}->StringAndTimestamp2Filename(
! String => $Title . " Created",
! );
!
! my %Attachment = (
! Filename => $Filename . ".csv",
! ContentType => "text/csv",
! Content => $Output,
! Encoding => "base64",
! Disposition => "attachment",
! );
!
# write output
if ($Opts{'o'}) {
***************
*** 254,261 ****
# send email
elsif ($CommonObject{EmailObject}->Send(
! From => $Opts{'s'},
! To => $Opts{'r'},
! Subject => "[Stats - $CountData Records] $ConfigItem{Module} $Y-$M-$D $Time",
! Body => $Opts{'b'},
Attachment => [
{
--- 229,236 ----
# send email
elsif ($CommonObject{EmailObject}->Send(
! From => $Opts{'s'},
! To => $Opts{'r'},
! Subject => "[Stats - $CountStatArray Records] $Title; Created: $Time",
! Body => $Opts{'m'},
Attachment => [
{
***************
*** 276,282 ****
foreach (@P) {
my ($Key, $Value) = split(/=/, $_, 2);
- #print STDERR "$Key, $Value, $Param{Param} ---\n";
if ($Key eq $Param{Param}) {
- #print STDERR "$Key, $Value ---\n";
return $Value;
}
--- 251,255 ----
- Previous message: [otrs-cvs] CVS: otrs/Kernel/System Stats.pm,NONE,1.1
- Next message: [otrs-cvs] CVS: otrs/Kernel/Output/HTML/Standard
AgentStatsDelete.dtl,NONE,1.1 AgentStatsEditRestrictions.dtl,NONE,1.1
AgentStatsEditSpecification.dtl,NONE,1.1
AgentStatsEditValueSeries.dtl,NONE,1.1 AgentStatsEditXaxis.dtl,NONE,1.1
AgentStatsImport.dtl,NONE,1.1 AgentStatsOverview.dtl,NONE,1.1
AgentStatsPrint.dtl,NONE,1.1 AgentStatsView.dtl,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cvs-log
mailing list