line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Target; |
2
|
|
|
|
|
|
|
|
3
|
35
|
|
|
35
|
|
2572463
|
use strict; |
|
35
|
|
|
|
|
41
|
|
|
35
|
|
|
|
|
768
|
|
4
|
35
|
|
|
35
|
|
113
|
use warnings; |
|
35
|
|
|
|
|
33
|
|
|
35
|
|
|
|
|
799
|
|
5
|
|
|
|
|
|
|
|
6
|
35
|
|
|
35
|
|
498
|
use English qw(-no_match_vars); |
|
35
|
|
|
|
|
1215
|
|
|
35
|
|
|
|
|
183
|
|
7
|
|
|
|
|
|
|
|
8
|
35
|
|
|
35
|
|
12141
|
use FusionInventory::Agent::Logger; |
|
35
|
|
|
|
|
42
|
|
|
35
|
|
|
|
|
1617
|
|
9
|
35
|
|
|
35
|
|
1987
|
use FusionInventory::Agent::Storage; |
|
35
|
|
|
|
|
61
|
|
|
35
|
|
|
|
|
167
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
9
|
|
|
9
|
1
|
19
|
my ($class, %params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
9
|
100
|
|
|
|
30
|
die 'no basevardir parameter' unless $params{basevardir}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $self = { |
17
|
|
|
|
|
|
|
logger => $params{logger} || |
18
|
|
|
|
|
|
|
FusionInventory::Agent::Logger->new(), |
19
|
|
|
|
|
|
|
maxDelay => $params{maxDelay} || 3600, |
20
|
|
|
|
|
|
|
initialDelay => $params{delaytime}, |
21
|
8
|
|
66
|
|
|
65
|
}; |
|
|
|
50
|
|
|
|
|
22
|
8
|
|
|
|
|
15
|
bless $self, $class; |
23
|
|
|
|
|
|
|
|
24
|
8
|
|
|
|
|
20
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _init { |
28
|
8
|
|
|
8
|
|
22
|
my ($self, %params) = @_; |
29
|
|
|
|
|
|
|
|
30
|
8
|
|
|
|
|
13
|
my $logger = $self->{logger}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# target identity |
33
|
8
|
|
|
|
|
13
|
$self->{id} = $params{id}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->{storage} = FusionInventory::Agent::Storage->new( |
36
|
|
|
|
|
|
|
logger => $self->{logger}, |
37
|
|
|
|
|
|
|
directory => $params{vardir} |
38
|
8
|
|
|
|
|
58
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# handle persistent state |
41
|
8
|
|
|
|
|
38
|
$self->_loadState(); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->{nextRunDate} = $self->_computeNextRunDate() |
44
|
8
|
100
|
|
|
|
44
|
if !$self->{nextRunDate}; |
45
|
|
|
|
|
|
|
|
46
|
8
|
|
|
|
|
28
|
$self->_saveState(); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$logger->debug( |
49
|
|
|
|
|
|
|
"[target $self->{id}] Next server contact planned for " . |
50
|
|
|
|
|
|
|
localtime($self->{nextRunDate}) |
51
|
8
|
|
|
|
|
1414
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub getStorage { |
56
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
return $self->{storage}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub setNextRunDate { |
62
|
0
|
|
|
0
|
1
|
0
|
my ($self, $nextRunDate) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
0
|
lock($self->{nextRunDate}) if $self->{shared}; |
65
|
0
|
|
|
|
|
0
|
$self->{nextRunDate} = $nextRunDate; |
66
|
0
|
|
|
|
|
0
|
$self->_saveState(); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub resetNextRunDate { |
70
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
0
|
lock($self->{nextRunDate}) if $self->{shared}; |
73
|
0
|
|
|
|
|
0
|
$self->{nextRunDate} = $self->_computeNextRunDate(); |
74
|
0
|
|
|
|
|
0
|
$self->_saveState(); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub getNextRunDate { |
78
|
2
|
|
|
2
|
1
|
7
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
5
|
return $self->{nextRunDate}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub getFormatedNextRunDate { |
84
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return $self->{nextRunDate} > 1 ? |
87
|
0
|
0
|
|
|
|
0
|
scalar localtime($self->{nextRunDate}) : "now"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub getMaxDelay { |
91
|
1
|
|
|
1
|
1
|
2
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
4
|
return $self->{maxDelay}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub setMaxDelay { |
97
|
0
|
|
|
0
|
1
|
0
|
my ($self, $maxDelay) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
0
|
$self->{maxDelay} = $maxDelay; |
100
|
0
|
|
|
|
|
0
|
$self->_saveState(); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# compute a run date, as current date and a random delay |
104
|
|
|
|
|
|
|
# between maxDelay / 2 and maxDelay |
105
|
|
|
|
|
|
|
sub _computeNextRunDate { |
106
|
5
|
|
|
5
|
|
6
|
my ($self) = @_; |
107
|
|
|
|
|
|
|
|
108
|
5
|
|
|
|
|
7
|
my $ret; |
109
|
5
|
100
|
|
|
|
14
|
if ($self->{initialDelay}) { |
110
|
1
|
|
|
|
|
8
|
$ret = time + ($self->{initialDelay} / 2) + int rand($self->{initialDelay} / 2); |
111
|
1
|
|
|
|
|
1
|
$self->{initialDelay} = undef; |
112
|
|
|
|
|
|
|
} else { |
113
|
|
|
|
|
|
|
$ret = |
114
|
|
|
|
|
|
|
time + |
115
|
|
|
|
|
|
|
$self->{maxDelay} / 2 + |
116
|
4
|
|
|
|
|
29
|
int rand($self->{maxDelay} / 2); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
5
|
|
|
|
|
13
|
return $ret; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _loadState { |
123
|
8
|
|
|
8
|
|
11
|
my ($self) = @_; |
124
|
|
|
|
|
|
|
|
125
|
8
|
|
|
|
|
27
|
my $data = $self->{storage}->restore(name => 'target'); |
126
|
|
|
|
|
|
|
|
127
|
8
|
100
|
|
|
|
28
|
$self->{maxDelay} = $data->{maxDelay} if $data->{maxDelay}; |
128
|
8
|
100
|
|
|
|
21
|
$self->{nextRunDate} = $data->{nextRunDate} if $data->{nextRunDate}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _saveState { |
132
|
8
|
|
|
8
|
|
7
|
my ($self) = @_; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$self->{storage}->save( |
135
|
|
|
|
|
|
|
name => 'target', |
136
|
|
|
|
|
|
|
data => { |
137
|
|
|
|
|
|
|
maxDelay => $self->{maxDelay}, |
138
|
|
|
|
|
|
|
nextRunDate => $self->{nextRunDate}, |
139
|
|
|
|
|
|
|
} |
140
|
8
|
|
|
|
|
43
|
); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
__END__ |