| 1 | package oEdtk::Tracking; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | my ( $_TRACK_SIG, $_TRACK_TRK, @_TRACK_JSON ); | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.4
| |||||||||||||||||||||||||||||
| 8 | 0 | ▶ | $SIG{'__WARN__'} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # if ($WARN2LOGGER){ | ||||||||||||||||||||||||||||
| 11 | # &logger (4, $_[0]); | ||||||||||||||||||||||||||||
| 12 | # } else { | ||||||||||||||||||||||||||||
| 13 | 0 | warn $_[0]; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # } | ||||||||||||||||||||||||||||
| 16 | # when Tracking object is defined, $_TRACK_TRK is defined so that events can be catch and sent to tracker | ||||||||||||||||||||||||||||
| 17 | 0 | ▶ | if ( defined $_TRACK_TRK && $_TRACK_SIG =~ /warn/i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_TRACK_TRK and $_TRACK_SIG =~ /warn/i
MC/DC0%0/2
defined $_TRACK_TRK and $_TRACK_SIG =~ /warn/i
defined $_TRACK_TRK
$_TRACK_SIG =~ /warn/i
Truth table0%0/3
A and B
A= defined $_TRACK_TRKB= $_TRACK_SIG =~ /warn/i
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # http://perldoc.perl.org/functions/warn.html | ||||||||||||||||||||||||||||
| 20 | 0 | my $message = $_[0]; | |||||||||||||||||||||||||||
| 21 | 0 | chomp($message); | |||||||||||||||||||||||||||
| 22 | 0 | $_TRACK_TRK->track( 'Warn', 1, $message ); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 2 | }; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 43 | ▶ | $SIG{'__DIE__'} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=10.1
| |||||||||||||||||||||||||||||
| 27 | 43 | ▶ | if ( defined $_TRACK_TRK ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | my $message = $_[0]; | |||||||||||||||||||||||||||
| 29 | 0 | chomp($message); | |||||||||||||||||||||||||||
| 30 | 0 | $_TRACK_TRK->track( 'Halt', 1, $message ); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 43 | die $_[0]; | |||||||||||||||||||||||||||
| 33 | 2 | }; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use oEdtk::Main; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 37 | use oEdtk::Config qw(config_read); | ||||||||||||||||||||||||||||
| 38 | use oEdtk::DBAdmin qw(db_connect create_table_TRACKING); | ||||||||||||||||||||||||||||
| 39 | use oEdtk::logger qw(logger $WARN2LOGGER); | ||||||||||||||||||||||||||||
| 40 | use oEdtk::Dict; | ||||||||||||||||||||||||||||
| 41 | use Config::IniFiles; | ||||||||||||||||||||||||||||
| 42 | use Sys::Hostname; | ||||||||||||||||||||||||||||
| 43 | use DBI; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #use JSON; | ||||||||||||||||||||||||||||
| 46 | use Exporter; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | our $VERSION = 2.1126; | ||||||||||||||||||||||||||||
| 49 | our @ISA = qw(Exporter); | ||||||||||||||||||||||||||||
| 50 | our @EXPORT_OK = qw(stats_iddest stats_week stats_month); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | #my @JSON_TRACE; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub new { | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # example call | ||||||||||||||||||||||||||||
| 57 | # $TRK = oEdtk::Tracking->new($ARGV[1] // "input file", | ||||||||||||||||||||||||||||
| 58 | # user => "utest", | ||||||||||||||||||||||||||||
| 59 | # entity => "Society", | ||||||||||||||||||||||||||||
| 60 | # keys => ['T_CALLID', 'T_TYPE', 'O_TT_TYP', 'O_TT_ID', 'T_PARAM', 'O_DESIGN', 'T_STATUT' ] | ||||||||||||||||||||||||||||
| 61 | # ); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | my ( $class, $source, %params ) = @_; | ||||||||||||||||||||||||||||
| 64 | $source = $source || ( $ARGV[1] || $ARGV[0] ); | ||||||||||||||||||||||||||||
| 65 | if ( $source =~ /^\-/ ) { | ||||||||||||||||||||||||||||
| 66 | $source = $ARGV[0]; | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | my $cfg = config_read('EDTK_DB'); | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Load the dictionary to normalize entity names. | ||||||||||||||||||||||||||||
| 71 | my $dict = oEdtk::Dict->new( $cfg->{'EDTK_DICO'}, { invert => 1 } ); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | my $mode = uc( $cfg->{'EDTK_TRACK_MODE'} ); | ||||||||||||||||||||||||||||
| 74 | if ( $mode eq 'NONE' ) { | ||||||||||||||||||||||||||||
| 75 | &logger( 6, "Tracking is currently disabled... (see EDTK_TRACK_MODE in config file)" ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Return a dummy object if tracking is disabled. | ||||||||||||||||||||||||||||
| 78 | return bless { dict => $dict, mode => $mode }, $class; | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | my $table = $cfg->{'EDTK_DBI_TRACKING'}; | ||||||||||||||||||||||||||||
| 82 | my $dbh = db_connect( $cfg, 'EDTK_DBI_DSN', { AutoCommit => 1 } ); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # XXX Should we ensure there is at least one key defined? | ||||||||||||||||||||||||||||
| 85 | my $keys = $params{'keys'} || []; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | if ( @$keys > $cfg->{'EDTK_MAX_USER_KEY'} ) { | ||||||||||||||||||||||||||||
| 88 | die "ERROR: too many tracking keys: got " . @$keys . ", max " . $cfg->{'EDTK_MAX_USER_KEY'}; | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # Check that all the keys are at most 8 characters long, and otherwise | ||||||||||||||||||||||||||||
| 92 | # truncate them. Also ensure we don't have the same key several times. | ||||||||||||||||||||||||||||
| 93 | my %seen = (); | ||||||||||||||||||||||||||||
| 94 | my @userkeys = (); | ||||||||||||||||||||||||||||
| 95 | foreach (@$keys) { | ||||||||||||||||||||||||||||
| 96 | my $key = uc($_); | ||||||||||||||||||||||||||||
| 97 | if ( length($key) > 8 ) { | ||||||||||||||||||||||||||||
| 98 | $key =~ s/^(.{8}).*$/$1/; | ||||||||||||||||||||||||||||
| 99 | &logger( 4, "column too long, truncated to '$key'" ); | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | if ( exists( $seen{$key} ) ) { | ||||||||||||||||||||||||||||
| 102 | die "ERROR: duplicate column \"$key\""; | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | push( @userkeys, $key ); | ||||||||||||||||||||||||||||
| 105 | $seen{$key} = 1; | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # Extract application name from the script name. | ||||||||||||||||||||||||||||
| 109 | my $app = $0; | ||||||||||||||||||||||||||||
| 110 | $app =~ s/^.*?[\/\\]?([\w-]+[\.plmex]*$)/$1/; | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | #$app =~ s/^.*?[\/\\]?([A-Z0-9-_]+)\.pl$/$1/; | ||||||||||||||||||||||||||||
| 113 | if ( length($app) > 20 ) { | ||||||||||||||||||||||||||||
| 114 | $app =~ s/\.pl$//i; | ||||||||||||||||||||||||||||
| 115 | $app =~ /(.{20})$/; | ||||||||||||||||||||||||||||
| 116 | &logger( 4, "application name '$app' too long, truncated to '$1'" ); | ||||||||||||||||||||||||||||
| 117 | $app = $1; | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # Validate the editing mode. | ||||||||||||||||||||||||||||
| 121 | my $edmode = _validate_edmode( $params{'edmode'} ); | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # Limit username length to 10 characters per the table schema. | ||||||||||||||||||||||||||||
| 124 | my $user = $params{'user'} || 'None'; | ||||||||||||||||||||||||||||
| 125 | if ( length($user) > 10 ) { | ||||||||||||||||||||||||||||
| 126 | $user =~ s/^(.{10}).*$/$1/; | ||||||||||||||||||||||||||||
| 127 | &logger( 4, "username \"$params{'user'}\" too long, truncated to \"$user\"" ); | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Truncate if necessary, by taking at most 128 characters on the right. | ||||||||||||||||||||||||||||
| 131 | if ( length($source) > 128 ) { | ||||||||||||||||||||||||||||
| 132 | $source = substr( $source, -128, 128 ); | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | my $self = bless { | ||||||||||||||||||||||||||||
| 136 | dict => $dict, | ||||||||||||||||||||||||||||
| 137 | mode => $mode, | ||||||||||||||||||||||||||||
| 138 | table => $table, | ||||||||||||||||||||||||||||
| 139 | edmode => $edmode, | ||||||||||||||||||||||||||||
| 140 | id => oe_ID_LDOC(), | ||||||||||||||||||||||||||||
| 141 | seq => 1, | ||||||||||||||||||||||||||||
| 142 | keys => \@userkeys, | ||||||||||||||||||||||||||||
| 143 | user => $user, | ||||||||||||||||||||||||||||
| 144 | source => $source, | ||||||||||||||||||||||||||||
| 145 | app => $app, | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | entity => $params{'entity'} // "", | ||||||||||||||||||||||||||||
| 148 | account => $params{'account'} // "", | ||||||||||||||||||||||||||||
| 149 | obj_typ => $params{'obj_typ'} // "", | ||||||||||||||||||||||||||||
| 150 | child_typ => $params{'child_typ'} // "", | ||||||||||||||||||||||||||||
| 151 | child_id => $params{'child_id'} // "", | ||||||||||||||||||||||||||||
| 152 | parent_id => $params{'parent_id'} // "", | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | dbh => $dbh | ||||||||||||||||||||||||||||
| 155 | }, $class; | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | my $entity = $params{'entity'} || $cfg->{'EDTK_CORP'}; | ||||||||||||||||||||||||||||
| 158 | $self->set_entity($entity); | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # Create the table in the SQLite case | ||||||||||||||||||||||||||||
| 161 | if ( $dbh->{'Driver'}->{'Name'} eq 'SQLite' ) { | ||||||||||||||||||||||||||||
| 162 | eval { create_table_TRACKING( $dbh, $table, $cfg->{'EDTK_MAX_USER_KEY'} ); }; | ||||||||||||||||||||||||||||
| 163 | if ($@) { | ||||||||||||||||||||||||||||
| 164 | &logger( 6, "Table already exist : $@" ); | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | $self->track( 'Job', 1, join( ' ', @ARGV ) ) | ||||||||||||||||||||||||||||
| 169 | ; # keep the join to place all the free parameters in the message area | ||||||||||||||||||||||||||||
| 170 | if ( defined $cfg->{'EDTK_TRACK_SIG'} && $cfg->{'EDTK_TRACK_SIG'} !~ /no/i ) { | ||||||||||||||||||||||||||||
| 171 | $_TRACK_SIG = $cfg->{'EDTK_TRACK_SIG'}; | ||||||||||||||||||||||||||||
| 172 | &logger( 6, | ||||||||||||||||||||||||||||
| 173 | "tracking catchs SIG messages = '$_TRACK_SIG' (see EDTK_TRACK_SIG : 'warn' for all, 'halt' for die only)" | ||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||
| 175 | $_TRACK_TRK = $self; | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # if (defined $cfg->{'EDTK_TRACK_JSON'} && $cfg->{'EDTK_TRACK_JSON'} !~/no/i ) { | ||||||||||||||||||||||||||||
| 179 | # # $_TRACK_TRK_JSON = $cfg->{'EDTK_TRACK_JSON'}; | ||||||||||||||||||||||||||||
| 180 | # push (@_TRACK_JSON, $cfg->{'EDTK_TRACK_JSON'}); | ||||||||||||||||||||||||||||
| 181 | # } | ||||||||||||||||||||||||||||
| 182 | # } else { | ||||||||||||||||||||||||||||
| 183 | # #$_TRACK_TRK_JSON = "no"; | ||||||||||||||||||||||||||||
| 184 | # $_TRACK_JSON[0] //= "no"; | ||||||||||||||||||||||||||||
| 185 | # #push (@_TRACK_JSON, "no"); | ||||||||||||||||||||||||||||
| 186 | # } | ||||||||||||||||||||||||||||
| 187 | # warn "INFO: _TRACK_JSON = " . @_TRACK_JSON ." \n"; | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | return $self; | ||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | sub track { | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # example call | ||||||||||||||||||||||||||||
| 195 | # $TRK->track('Spool', 1, "K0val", "K1val", "K2val", "Knval" ); | ||||||||||||||||||||||||||||
| 196 | my ( $self, $job, $count, @data ) = @_; | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | return if $self->{'mode'} eq 'NONE'; | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | $count ||= 1; | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | my @usercols = @{ $self->{'keys'} }; | ||||||||||||||||||||||||||||
| 203 | if ( @data > ( @usercols + 1 ) ) { | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # max is @usercols nbcol + 1 for message col | ||||||||||||||||||||||||||||
| 206 | &logger( 3, | ||||||||||||||||||||||||||||
| 207 | "Too much values : got " . @data . ", expected " . ( @usercols + 1 ) . " maximum" ); | ||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | # Validate the job event. | ||||||||||||||||||||||||||||
| 211 | $job = _validate_event($job); | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | # GENERATE SQL REQUEST. | ||||||||||||||||||||||||||||
| 214 | my $values = { | ||||||||||||||||||||||||||||
| 215 | ED_SNGL_ID => $self->{'id'}, | ||||||||||||||||||||||||||||
| 216 | ED_SEQ => $self->{'seq'}++, | ||||||||||||||||||||||||||||
| 217 | ED_TSTAMP => oe_now_time(), | ||||||||||||||||||||||||||||
| 218 | ED_USER => $self->{'user'}, | ||||||||||||||||||||||||||||
| 219 | ED_APP => $self->{'app'}, | ||||||||||||||||||||||||||||
| 220 | ED_CORP => $self->{'entity'}, | ||||||||||||||||||||||||||||
| 221 | ED_ACCOUNT => $self->{'account'} // "", | ||||||||||||||||||||||||||||
| 222 | ED_MOD_ED => $self->{'edmode'}, | ||||||||||||||||||||||||||||
| 223 | ED_JOB_EVT => $job, | ||||||||||||||||||||||||||||
| 224 | ED_OBJ_TYP => $self->{'obj_typ'}, | ||||||||||||||||||||||||||||
| 225 | ED_OBJ_COUNT => $count, | ||||||||||||||||||||||||||||
| 226 | ED_CHILD_TYP => $self->{'child_typ'} // "", | ||||||||||||||||||||||||||||
| 227 | ED_CHILD_ID => $self->{'child_id'} // "", | ||||||||||||||||||||||||||||
| 228 | ED_PARENT_ID => $self->{'parent_id'} // "", | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | ED_HOST => hostname(), | ||||||||||||||||||||||||||||
| 231 | ED_SOURCE => $self->{'source'} | ||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | foreach my $i ( 0 .. $#data ) { | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | # add a message column to handle messages and warnings | ||||||||||||||||||||||||||||
| 237 | # to ensure compatibility with what exists, we reverse | ||||||||||||||||||||||||||||
| 238 | # the data to put the message first while waiting for job_evt | ||||||||||||||||||||||||||||
| 239 | ################## PBM DATA NOT POPULATED, TO REVIEW | ||||||||||||||||||||||||||||
| 240 | my $val = $data[$i] // ""; | ||||||||||||||||||||||||||||
| 241 | $values->{'ED_MESSAGE'} = $val . " " . ( $values->{'ED_MESSAGE'} // "" ); | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # if there is only one data item, make sure not to put it needlessly in a user column | ||||||||||||||||||||||||||||
| 244 | if ( $#data > 0 ) { | ||||||||||||||||||||||||||||
| 245 | if ( defined( $data[$i] ) && length( $data[$i] ) > 128 ) { | ||||||||||||||||||||||||||||
| 246 | &logger( 4, "\"$data[$i]\" truncated to 128 characters" ); | ||||||||||||||||||||||||||||
| 247 | $data[$i] =~ s/^(.{128}).*$/$1/; | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | $values->{"ED_K${i}_NAME"} = $usercols[$i]; | ||||||||||||||||||||||||||||
| 250 | $values->{"ED_K${i}_VAL"} = $val; | ||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | if ( $job eq 'W' || $job eq 'H' ) { # Halt or Warn event | ||||||||||||||||||||||||||||
| 255 | # if job_evt is 'Warning' or 'Halt' we handle the messages and the source | ||||||||||||||||||||||||||||
| 256 | chomp $values->{'ED_MESSAGE'}; | ||||||||||||||||||||||||||||
| 257 | $values->{'ED_MESSAGE'} =~ s/\s+/ /g; | ||||||||||||||||||||||||||||
| 258 | $values->{'ED_MESSAGE'} =~ s/^(.{256}).*$/$1/; | ||||||||||||||||||||||||||||
| 259 | $values->{'ED_SOURCE'} = $self->{'source'} if ( $job eq 'H' ); | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | elsif ( $job eq 'J' ) { # JOB event | ||||||||||||||||||||||||||||
| 263 | $values->{'ED_SOURCE'} = $self->{'source'}; | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | else { | ||||||||||||||||||||||||||||
| 267 | undef( $values->{'ED_MESSAGE'} ); | ||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | my $dbh = $self->{'dbh'}; | ||||||||||||||||||||||||||||
| 271 | my @cols = keys(%$values); | ||||||||||||||||||||||||||||
| 272 | my $table = $self->{'table'}; | ||||||||||||||||||||||||||||
| 273 | $table = uc($table) if ( $dbh->{'Driver'}->{'Name'} eq 'mysql' ); | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | my $sql = | ||||||||||||||||||||||||||||
| 276 | "INSERT INTO $table (" | ||||||||||||||||||||||||||||
| 277 | . join( ', ', @cols ) | ||||||||||||||||||||||||||||
| 278 | . ") VALUES (" | ||||||||||||||||||||||||||||
| 279 | . join( ', ', ('?') x @cols ) . ")"; | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | #warn "sql = $sql \n"; | ||||||||||||||||||||||||||||
| 282 | #sql = insert into edtk_tracking (ed_job_evt, ed_app, ed_corp, ed_obj_typ, ed_user, ed_message, ed_tstamp, ed_sngl_id, ed_obj_count, ed_mod_ed, ed_source, ed_seq, ed_host) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | _tracking_insert( $dbh, $sql, $table, $values ); | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | if ( !$dbh->{'AutoCommit'} ) { | ||||||||||||||||||||||||||||
| 287 | $dbh->commit or die $dbh->errstr; | ||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | #if ($_TRACK_JSON[0] ne "no") { push (@_TRACK_JSON, $values) }; | ||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | # Run the tracking INSERT. On failure, report a stale schema (READ-ONLY) and | ||||||||||||||||||||||||||||
| 294 | # then die with the driver's message, as the historical code did. The check is | ||||||||||||||||||||||||||||
| 295 | # fully inside eval() so it can never mask the original error. | ||||||||||||||||||||||||||||
| 296 | sub _tracking_insert { | ||||||||||||||||||||||||||||
| 297 | my ( $dbh, $sql, $table, $values ) = @_; | ||||||||||||||||||||||||||||
| 298 | my $sth; | ||||||||||||||||||||||||||||
| 299 | my $ok = eval { | ||||||||||||||||||||||||||||
| 300 | $sth = $dbh->prepare($sql); | ||||||||||||||||||||||||||||
| 301 | $sth->execute( values(%$values) ); | ||||||||||||||||||||||||||||
| 302 | }; | ||||||||||||||||||||||||||||
| 303 | return if $ok; | ||||||||||||||||||||||||||||
| 304 | my $err = ( $@ ne '' ) ? $@ : ( $sth ? $sth->errstr : $dbh->errstr ); | ||||||||||||||||||||||||||||
| 305 | _tracking_schema_warn( $dbh, $table ); | ||||||||||||||||||||||||||||
| 306 | die $err; | ||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | # Warn once per process when a tracking write fails on a stale schema. The | ||||||||||||||||||||||||||||
| 310 | # warning itself is emitted by oEdtk::DBAdmin::schema_StaleWarning (read-only). | ||||||||||||||||||||||||||||
| 311 | my $_TRACK_STALE_WARNED = 0; | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | sub _tracking_schema_warn { | ||||||||||||||||||||||||||||
| 314 | my ( $dbh, $table ) = @_; | ||||||||||||||||||||||||||||
| 315 | return if $_TRACK_STALE_WARNED; | ||||||||||||||||||||||||||||
| 316 | return unless $dbh; | ||||||||||||||||||||||||||||
| 317 | my $warned = eval { oEdtk::DBAdmin::schema_StaleWarning( $dbh, tracking_table => $table ); }; | ||||||||||||||||||||||||||||
| 318 | $_TRACK_STALE_WARNED = 1 if $warned; | ||||||||||||||||||||||||||||
| 319 | return; | ||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | sub set_entity { | ||||||||||||||||||||||||||||
| 323 | my ( $self, $entity ) = @_; | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | if ( !defined($entity) || length($entity) == 0 ) { | ||||||||||||||||||||||||||||
| 326 | &logger( 3, "Tracking::set_entity() called with an undefined entity!" ); | ||||||||||||||||||||||||||||
| 327 | return; | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | # warn "INFO: translate >$entity< \n"; | ||||||||||||||||||||||||||||
| 331 | $entity = $self->{'dict'}->translate($entity); | ||||||||||||||||||||||||||||
| 332 | $self->{'entity'} = $entity; | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | # warn $self->{'entity'}. " \$self->{'entity'}\n"; | ||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | sub end { | ||||||||||||||||||||||||||||
| 338 | my $self = shift; | ||||||||||||||||||||||||||||
| 339 | $self->track( 'Halt', 1 ); | ||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | # For each application, for each legal entity, and for each week | ||||||||||||||||||||||||||||
| 343 | # the number of documents in the tracking. | ||||||||||||||||||||||||||||
| 344 | sub stats_week { | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # pass the options as hash keys... | ||||||||||||||||||||||||||||
| 347 | my ( $dbh, $cfg, $start, $end, $excluded_users ) = @_; | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | my $table = $cfg->{'EDTK_STATS_TRACKING'}; | ||||||||||||||||||||||||||||
| 350 | my $innersql = | ||||||||||||||||||||||||||||
| 351 | "select ed_corp, ed_app, " | ||||||||||||||||||||||||||||
| 352 | . "'s' || to_char(to_date(ed_tstamp, 'YYYYMMDDHH24MISS'), 'IW') as ed_week " | ||||||||||||||||||||||||||||
| 353 | . "from $table " | ||||||||||||||||||||||||||||
| 354 | . "where ed_job_evt = 'd' and ed_tstamp >= ? "; | ||||||||||||||||||||||||||||
| 355 | my @vals = ($start); | ||||||||||||||||||||||||||||
| 356 | if ( defined($end) ) { | ||||||||||||||||||||||||||||
| 357 | $innersql .= " and ed_tstamp <= ? "; | ||||||||||||||||||||||||||||
| 358 | push( @vals, $end ); | ||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | if ( defined $excluded_users ) { | ||||||||||||||||||||||||||||
| 362 | my @excluded = split( /,\s*/, $excluded_users ); | ||||||||||||||||||||||||||||
| 363 | for ( my $i = 0 ; $i <= $#excluded ; $i++ ) { | ||||||||||||||||||||||||||||
| 364 | $innersql .= " and ed_user != ? "; | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | push( @vals, @excluded ); | ||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | my $sql = "select i.ed_corp, i.ed_app, i.ed_week, count(*) as ed_count " | ||||||||||||||||||||||||||||
| 370 | . "from ($innersql) i group by ed_corp, ed_app, ed_week "; | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | # warn "\nINFO: $sql \n"; | ||||||||||||||||||||||||||||
| 373 | #SELECT i.ED_CORP, i.ED_APP, i.ED_WEEK, COUNT(*) AS ED_COUNT | ||||||||||||||||||||||||||||
| 374 | # FROM ( | ||||||||||||||||||||||||||||
| 375 | # SELECT ED_CORP, ED_APP, 'S' || TO_CHAR(TO_DATE(ED_TSTAMP, 'YYYYMMDDHH24MISS'), 'IW') AS ED_WEEK | ||||||||||||||||||||||||||||
| 376 | # FROM EDTK_TRACKING_2010 WHERE ED_JOB_EVT = 'D' AND ED_TSTAMP >= '20101212' | ||||||||||||||||||||||||||||
| 377 | # ) i | ||||||||||||||||||||||||||||
| 378 | # GROUP BY ED_CORP, ED_APP, ED_WEEK; | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | my $rows = $dbh->selectall_arrayref( $sql, { Slice => {} }, @vals ); | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | # use Data::Dumper; | ||||||||||||||||||||||||||||
| 383 | # print Dumper($rows); | ||||||||||||||||||||||||||||
| 384 | # { | ||||||||||||||||||||||||||||
| 385 | # 'ED_COUNT' => '4', | ||||||||||||||||||||||||||||
| 386 | # 'ED_APP' => 'FUS-AC007', | ||||||||||||||||||||||||||||
| 387 | # 'ED_CORP' => 'CPLTR', | ||||||||||||||||||||||||||||
| 388 | # 'ED_WEEK' => 'S51' | ||||||||||||||||||||||||||||
| 389 | # }, | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | return $rows; | ||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | sub stats_iddest { | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | # pass the options as hash keys... | ||||||||||||||||||||||||||||
| 397 | my ( $dbh, $cfg, $start, $end, $excluded_users, $ed_app ) = @_; | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | my $table = $cfg->{'EDTK_STATS_TRACKING'}; | ||||||||||||||||||||||||||||
| 400 | my $innersql = | ||||||||||||||||||||||||||||
| 401 | "select ed_corp, ed_k1_val as ed_emet, ed_k0_val as ed_iddest, ed_app, " | ||||||||||||||||||||||||||||
| 402 | . "'s' || to_char(to_date(ed_tstamp, 'YYYYMMDDHH24MISS'), 'IW') as ed_week " | ||||||||||||||||||||||||||||
| 403 | . "from $table " | ||||||||||||||||||||||||||||
| 404 | . "where ed_job_evt = 'd' and ed_tstamp >= ? "; | ||||||||||||||||||||||||||||
| 405 | my @vals = ($start); | ||||||||||||||||||||||||||||
| 406 | if ( defined($end) ) { | ||||||||||||||||||||||||||||
| 407 | $innersql .= " and ed_tstamp <= ? "; | ||||||||||||||||||||||||||||
| 408 | push( @vals, $end ); | ||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | if ( defined $excluded_users ) { | ||||||||||||||||||||||||||||
| 412 | my @excluded = split( /,\s*/, $excluded_users ); | ||||||||||||||||||||||||||||
| 413 | for ( my $i = 0 ; $i <= $#excluded ; $i++ ) { | ||||||||||||||||||||||||||||
| 414 | $innersql .= " and ed_user != ? "; | ||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | push( @vals, @excluded ); | ||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | if ( defined $ed_app ) { | ||||||||||||||||||||||||||||
| 420 | $innersql .= " and ed_app = ? "; | ||||||||||||||||||||||||||||
| 421 | push( @vals, $ed_app ); | ||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | my $sql = "select i.ed_corp, i.ed_emet, i.ed_iddest, i.ed_app, i.ed_week, count(*) as ed_count " | ||||||||||||||||||||||||||||
| 425 | . "from ($innersql) i group by i.ed_corp, i.ed_emet, i.ed_iddest, i.ed_app, i.ed_week "; | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | # warn "INFO: $sql \n"; | ||||||||||||||||||||||||||||
| 428 | # warn "INFO: @vals \n"; | ||||||||||||||||||||||||||||
| 429 | # SELECT i.ED_CORP, i.ED_SECTION, i.ED_IDDEST, i.ED_APP, i.ED_WEEK, COUNT(*) AS ED_COUNT | ||||||||||||||||||||||||||||
| 430 | # FROM ( | ||||||||||||||||||||||||||||
| 431 | # SELECT ED_CORP, ED_K1_VAL AS ED_SECTION, ED_K0_VAL AS ED_IDDEST, ED_APP, | ||||||||||||||||||||||||||||
| 432 | # 'S' || TO_CHAR(TO_DATE(ED_TSTAMP, 'YYYYMMDDHH24MISS'), 'IW') AS ED_WEEK | ||||||||||||||||||||||||||||
| 433 | # FROM EDTK_TRACKING_2010 WHERE ED_JOB_EVT = 'D' AND ED_TSTAMP >= ? | ||||||||||||||||||||||||||||
| 434 | # AND ED_TSTAMP <= ? AND ED_USER != ? AND ED_APP = ? ) i | ||||||||||||||||||||||||||||
| 435 | # GROUP BY i.ED_CORP, i.ED_SECTION, i.ED_IDDEST, i.ED_APP, i.ED_WEEK | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | my $rows = $dbh->selectall_arrayref( $sql, { Slice => {} }, @vals ); | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | # use Data::Dumper; | ||||||||||||||||||||||||||||
| 440 | # print Dumper($rows); | ||||||||||||||||||||||||||||
| 441 | # { | ||||||||||||||||||||||||||||
| 442 | # 'ED_COUNT' => '2', | ||||||||||||||||||||||||||||
| 443 | # 'ED_APP' => 'CTP-AC001', | ||||||||||||||||||||||||||||
| 444 | # 'ED_IDDEST' => '0000428193', | ||||||||||||||||||||||||||||
| 445 | # 'ED_CORP' => 'CORP_1', | ||||||||||||||||||||||||||||
| 446 | # 'ED_WEEK' => 'S50', | ||||||||||||||||||||||||||||
| 447 | # 'ED_EMET' => 'P004' | ||||||||||||||||||||||||||||
| 448 | # }, | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | return $rows; | ||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | # For each application, for each E.R., for each legal entity | ||||||||||||||||||||||||||||
| 454 | # and for each month, the number of documents in the tracking. | ||||||||||||||||||||||||||||
| 455 | sub stats_month { | ||||||||||||||||||||||||||||
| 456 | my ( $dbh, $cfg, $start, $end, $excluded_users ) = @_; | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | my $table = $cfg->{'EDTK_STATS_TRACKING'}; | ||||||||||||||||||||||||||||
| 459 | my $innersql = | ||||||||||||||||||||||||||||
| 460 | "select ed_app, ed_corp, ed_k1_val as ed_emet, " | ||||||||||||||||||||||||||||
| 461 | . "'m' || to_char(to_date(ed_tstamp, 'YYYYMMDDHH24MISS'), 'MM') as ed_month " | ||||||||||||||||||||||||||||
| 462 | . "from $table where ed_job_evt = 'd' and ed_tstamp >= ? "; | ||||||||||||||||||||||||||||
| 463 | my @vals = ($start); | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | if ( defined($end) ) { | ||||||||||||||||||||||||||||
| 466 | $innersql .= " and ed_tstamp <= ? "; | ||||||||||||||||||||||||||||
| 467 | push( @vals, $end ); | ||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | if ( defined $excluded_users ) { | ||||||||||||||||||||||||||||
| 471 | my @excluded = split( /,\s*/, $excluded_users ); | ||||||||||||||||||||||||||||
| 472 | for ( my $i = 0 ; $i <= $#excluded ; $i++ ) { | ||||||||||||||||||||||||||||
| 473 | $innersql .= " and ed_user != ? "; | ||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | push( @vals, @excluded ); | ||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | my $sql = "select i.ed_app, i.ed_corp, i.ed_emet, i.ed_month, count(*) as ed_count " | ||||||||||||||||||||||||||||
| 479 | . "from ($innersql) i group by ed_app, ed_corp, ed_emet, ed_month "; | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | my $rows = $dbh->selectall_arrayref( $sql, { Slice => {} }, @vals ); | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | # use Data::Dumper; | ||||||||||||||||||||||||||||
| 484 | # print Dumper($rows); | ||||||||||||||||||||||||||||
| 485 | # 'ED_MONTH' => 'M12', | ||||||||||||||||||||||||||||
| 486 | # 'ED_COUNT' => '1', | ||||||||||||||||||||||||||||
| 487 | # 'ED_CORP' => 'CORP_1', | ||||||||||||||||||||||||||||
| 488 | # 'ED_APP' => 'DEV-CAMELEON', | ||||||||||||||||||||||||||||
| 489 | # 'ED_EMET' => '37043' | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | return $rows; | ||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | sub _validate_event { | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | # Job Event : looking for one of the following : | ||||||||||||||||||||||||||||
| 497 | # Job (default), Spool, Document, Line, Warning, Error, Halt (critic), Reject, Track | ||||||||||||||||||||||||||||
| 498 | my $job = shift; | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | &logger( 3, "Halt event in Tracking = $job" ) if ( $job =~ /^H/ ); | ||||||||||||||||||||||||||||
| 501 | if ( !defined $job || $job !~ /^([JSDLWEHRT])/ ) { | ||||||||||||||||||||||||||||
| 502 | die "ERROR: Invalid job event : " | ||||||||||||||||||||||||||||
| 503 | . ( defined $job ? $job : '(undef)' ) . "\n" | ||||||||||||||||||||||||||||
| 504 | . "\t valid events are : Job / Spool / Document / Line / Warning / Reject / Error / Halt (critic)\n"; | ||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | return $1; | ||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | #{ | ||||||||||||||||||||||||||||
| 510 | #my $_edmode; | ||||||||||||||||||||||||||||
| 511 | # | ||||||||||||||||||||||||||||
| 512 | # sub display_edmode { | ||||||||||||||||||||||||||||
| 513 | # if (!defined $_edmode) { | ||||||||||||||||||||||||||||
| 514 | # $_edmode = _validate_edmode(shift); | ||||||||||||||||||||||||||||
| 515 | # } | ||||||||||||||||||||||||||||
| 516 | # return $_edmode; | ||||||||||||||||||||||||||||
| 517 | # } | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | sub _validate_edmode { | ||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | # Printing Mode : looking for one of the following : | ||||||||||||||||||||||||||||
| 522 | # Undef (default), Batch, Tp, Web, Mail, probinG | ||||||||||||||||||||||||||||
| 523 | my $edmode = shift; | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | if ( !defined $edmode || $edmode !~ /^([BTMWG])/ ) { | ||||||||||||||||||||||||||||
| 526 | return 'U'; | ||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | return $1; | ||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | #} | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | #END { | ||||||||||||||||||||||||||||
| 534 | # #if ($_TRACK_TRK_JSON !~/no/i) { | ||||||||||||||||||||||||||||
| 535 | # if ($_TRACK_JSON[0] ne "no") { | ||||||||||||||||||||||||||||
| 536 | # my $json = JSON->new; | ||||||||||||||||||||||||||||
| 537 | # #print $json->encode(\@_TRACK_JSON); | ||||||||||||||||||||||||||||
| 538 | # } | ||||||||||||||||||||||||||||
| 539 | #} | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | 1; | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | =head1 NAME | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | oEdtk::Tracking - object-oriented production tracking | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | use oEdtk::Tracking qw(stats_week); | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | my $trk = oEdtk::Tracking->new($source, user => 'utest', entity => 'Corp'); | ||||||||||||||||||||||||||||
| 552 | $trk->track('Job', 1, @values); | ||||||||||||||||||||||||||||
| 553 | $trk->end; | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | Records tracking events (job, spool, document, warn, halt) for a batch run into | ||||||||||||||||||||||||||||
| 558 | the table named by the C<EDTK_DB> configuration, and offers a few statistics | ||||||||||||||||||||||||||||
| 559 | queries over that table. When C<EDTK_TRACK_MODE> is C<NONE> the constructor | ||||||||||||||||||||||||||||
| 560 | returns an inert object and every method becomes a no-op. This is the current | ||||||||||||||||||||||||||||
| 561 | module; C<Tracking2.pm> is the older, warn-based duplicate that declares the same | ||||||||||||||||||||||||||||
| 562 | package C<oEdtk::Tracking>. | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | =head1 METHODS | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | =head2 new | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | my $trk = oEdtk::Tracking->new($source, %params); | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | Build a tracker. C<$source> names the input, and C<%params> may carry C<user>, | ||||||||||||||||||||||||||||
| 571 | C<entity>, C<keys>, C<edmode>, C<account>, C<obj_typ>, C<child_typ>, | ||||||||||||||||||||||||||||
| 572 | C<child_id> and C<parent_id>. Dies when there are too many keys or a duplicate | ||||||||||||||||||||||||||||
| 573 | key. | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | =head2 track | ||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | $trk->track($job, $count, @data); | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | Record one event: the job event, the number of objects, and the values of the | ||||||||||||||||||||||||||||
| 580 | configured user keys (an optional trailing value is the message). Values longer | ||||||||||||||||||||||||||||
| 581 | than the schema allows are truncated. | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | =head2 set_entity | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | $trk->set_entity($entity); | ||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | Normalise C<$entity> through the dictionary and store it. | ||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | =head2 end | ||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | $trk->end; | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | Record the final C<Halt> event. | ||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | =head2 stats_iddest | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | my $rows = stats_iddest($dbh, $cfg, $start, $end, $excluded_users, $ed_app); | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | Per recipient destination, per week, the number of documents tracked between | ||||||||||||||||||||||||||||
| 602 | C<$start> and C<$end>. | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | =head2 stats_week | ||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | my $rows = stats_week($dbh, $cfg, $start, $end, $excluded_users); | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | Per application, per legal entity and per ISO week, the number of documents | ||||||||||||||||||||||||||||
| 609 | tracked during the period. | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | =head2 stats_month | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | my $rows = stats_month($dbh, $cfg, $start, $end, $excluded_users); | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | Per application, per legal entity and per month, the number of documents tracked | ||||||||||||||||||||||||||||
| 616 | during the period. | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | The following subs are internal helpers and are not part of the public API: | ||||||||||||||||||||||||||||
| 619 | C<_tracking_insert>, C<_tracking_schema_warn>, C<_validate_event> and | ||||||||||||||||||||||||||||
| 620 | C<_validate_edmode>. | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | The oEdtk team. | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | =cut | ||||||||||||||||||||||||||||