line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::OverWatch::EventLog; |
2
|
|
|
|
|
|
|
# ABSTRACT: EventLog base class |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1226
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
27
|
use App::OverWatch::DB; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use App::OverWatch::Event; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Module::Load qw( load ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
my $class = shift; |
14
|
|
|
|
|
|
|
my $rh_options = shift || {}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $DB = $rh_options->{db} // die "Require 'db'"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $type = $DB->type(); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $subclass = $class . '::' . $type; |
21
|
|
|
|
|
|
|
load($subclass); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $self = bless( {}, $subclass ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$self->{DB} = $DB; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my @EventTypes = qw( START PROGRESS END POINT ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub create_event { |
33
|
|
|
|
|
|
|
my $self = shift; |
34
|
|
|
|
|
|
|
my $rh_args = shift; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $system = $rh_args->{system} // die "Error: require 'system'"; |
37
|
|
|
|
|
|
|
my $subsystem = $rh_args->{subsystem} // die "Error: require 'subsystem'"; |
38
|
|
|
|
|
|
|
my $worker = $rh_args->{worker} // die "Error: require 'worker'"; |
39
|
|
|
|
|
|
|
my $type = $rh_args->{type} // die "Error: require 'type'"; |
40
|
|
|
|
|
|
|
my $data = $rh_args->{data} // ''; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
die "Error: Bad type '$type'" |
43
|
|
|
|
|
|
|
if (grep { /^$type$/ } @EventTypes == 0); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $sql =<<"SQL"; |
46
|
|
|
|
|
|
|
INSERT INTO |
47
|
|
|
|
|
|
|
events ( system, subsystem, worker, eventtype, ctime, data ) |
48
|
|
|
|
|
|
|
VALUES |
49
|
|
|
|
|
|
|
( ?, ?, ?, ?, NOW(), ? ) |
50
|
|
|
|
|
|
|
SQL |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $ret = $self->{DB}->dbix_run( $sql, $system, $subsystem, $worker, |
53
|
|
|
|
|
|
|
$type, $data ); |
54
|
|
|
|
|
|
|
return $ret; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get_events { |
58
|
|
|
|
|
|
|
my $self = shift; |
59
|
|
|
|
|
|
|
my $rh_args = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $sql =<<"SQL"; |
62
|
|
|
|
|
|
|
SELECT |
63
|
|
|
|
|
|
|
* |
64
|
|
|
|
|
|
|
FROM |
65
|
|
|
|
|
|
|
events |
66
|
|
|
|
|
|
|
SQL |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $sth = $self->{DB}->dbix_select( $sql ); |
69
|
|
|
|
|
|
|
return undef if (!defined($sth)); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my @events; |
72
|
|
|
|
|
|
|
while ( my $rh_row = $sth->fetchrow_hashref() ) { |
73
|
|
|
|
|
|
|
my $Event = App::OverWatch::Event->new($rh_row); |
74
|
|
|
|
|
|
|
push(@events, $Event); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
return \@events; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |