| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Notify; |
|
6
|
|
|
|
|
|
|
|
|
7
|
102
|
|
|
102
|
|
1257
|
use v5.12.5; |
|
|
102
|
|
|
|
|
349
|
|
|
8
|
102
|
|
|
102
|
|
520
|
use warnings; |
|
|
102
|
|
|
|
|
184
|
|
|
|
102
|
|
|
|
|
73820
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
103
|
|
|
103
|
0
|
337
|
my $that = shift; |
|
14
|
103
|
|
33
|
|
|
813
|
my $proto = ref($that) || $that; |
|
15
|
103
|
|
|
|
|
306
|
my $self = {@_}; |
|
16
|
|
|
|
|
|
|
|
|
17
|
103
|
|
|
|
|
433
|
bless( $self, $proto ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
103
|
|
|
|
|
893
|
$self->{__types__} = {}; |
|
20
|
103
|
|
|
|
|
376
|
$self->{__postponed__} = []; |
|
21
|
103
|
|
|
|
|
307
|
$self->{__running_postponed__} = 0; |
|
22
|
103
|
|
|
|
|
253
|
$self->{__in_notify__} = 0; |
|
23
|
|
|
|
|
|
|
|
|
24
|
103
|
|
|
|
|
2576
|
return $self; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub add { |
|
28
|
0
|
|
|
0
|
0
|
0
|
my ( $self, %option ) = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
0
|
return if ( $self->{__in_notify__} ); |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
0
|
if ( exists $self->{__types__}->{ $option{type} }->{ $option{name} } ) { |
|
33
|
0
|
|
|
|
|
0
|
Rex::Logger::debug( |
|
34
|
|
|
|
|
|
|
"A resource of the type $option{type} and name $option{name}" |
|
35
|
|
|
|
|
|
|
. "already exists.", |
|
36
|
|
|
|
|
|
|
"warn" |
|
37
|
|
|
|
|
|
|
); |
|
38
|
0
|
|
|
|
|
0
|
return; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->{__types__}->{ $option{type} }->{ $option{name} } = { |
|
42
|
|
|
|
|
|
|
postpone => $option{postpone} || 0, |
|
43
|
|
|
|
|
|
|
options => $option{options}, |
|
44
|
|
|
|
|
|
|
cb => $option{cb}, |
|
45
|
0
|
|
0
|
|
|
0
|
}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub run { |
|
49
|
0
|
|
|
0
|
0
|
0
|
my ( $self, %option ) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
Rex::Logger::debug("Try to notify $option{type} -> $option{name}"); |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
0
|
0
|
|
|
0
|
if ( exists $self->{__types__}->{ $option{type} } |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
54
|
|
|
|
|
|
|
&& exists $self->{__types__}->{ $option{type} }->{ $option{name} } |
|
55
|
|
|
|
|
|
|
&& exists $self->{__types__}->{ $option{type} }->{ $option{name} }->{cb} |
|
56
|
|
|
|
|
|
|
&& $self->{__types__}->{ $option{type} }->{ $option{name} }->{postpone} == |
|
57
|
|
|
|
|
|
|
0 ) |
|
58
|
|
|
|
|
|
|
{ |
|
59
|
0
|
|
|
|
|
0
|
Rex::Logger::debug("Running notify $option{type} -> $option{name}"); |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
my $cb = $self->{__types__}->{ $option{type} }->{ $option{name} }->{cb}; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
$self->{__in_notify__} = 1; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$cb->( |
|
66
|
0
|
|
|
|
|
0
|
$self->{__types__}->{ $option{type} }->{ $option{name} }->{options} ); |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
$self->{__in_notify__} = 0; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
else { |
|
71
|
0
|
0
|
|
|
|
0
|
if ( !$self->{__running_postponed__} ) { |
|
72
|
0
|
|
|
|
|
0
|
Rex::Logger::debug( |
|
73
|
|
|
|
|
|
|
"Can't notify $option{type} -> $option{name}. Postponing..."); |
|
74
|
0
|
|
|
|
|
0
|
$self->_postpone(%option); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
else { |
|
77
|
0
|
|
|
|
|
0
|
Rex::Logger::info( |
|
78
|
|
|
|
|
|
|
"Can't run postponed notification. " |
|
79
|
|
|
|
|
|
|
. "Resource not found ($option{type} -> $option{name})", |
|
80
|
|
|
|
|
|
|
"warn" |
|
81
|
|
|
|
|
|
|
); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub run_postponed { |
|
88
|
47
|
|
|
47
|
0
|
239
|
my ($self) = @_; |
|
89
|
47
|
|
|
|
|
248
|
$self->{__running_postponed__} = 1; |
|
90
|
47
|
|
|
|
|
292
|
Rex::Logger::debug("Running postponed notifications."); |
|
91
|
47
|
|
|
|
|
174
|
for my $p ( @{ $self->{__postponed__} } ) { |
|
|
47
|
|
|
|
|
797
|
|
|
92
|
0
|
|
|
|
|
|
$self->run( %{$p} ); |
|
|
0
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _postpone { |
|
97
|
0
|
|
|
0
|
|
|
my ( $self, %option ) = @_; |
|
98
|
0
|
|
|
|
|
|
push @{ $self->{__postponed__} }, \%option; |
|
|
0
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |