line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::TT::Render; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
440
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
114
|
|
4
|
5
|
|
|
5
|
|
17
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
99
|
|
5
|
5
|
|
|
5
|
|
529
|
use utf8; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
18
|
|
6
|
5
|
|
|
5
|
|
74
|
use Carp; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
222
|
|
7
|
5
|
|
|
5
|
|
317
|
use Monitoring::TT::Log qw/error warn info debug trace log/; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
3831
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
##################################################################### |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Monitoring::TT::Render - Render Helper Functions |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
All functions from this render helper can be used in templates |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
##################################################################### |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 METHODS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 die |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
die(error message) |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
die with an hopefully useful error message |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
sub die { |
33
|
0
|
|
|
0
|
1
|
0
|
my( $msg ) = @_; |
34
|
0
|
|
|
|
|
0
|
return croak($msg); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
##################################################################### |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 _warn |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
_warn(message) |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
sub _warn { |
45
|
0
|
|
|
0
|
|
0
|
return warn(@_); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
##################################################################### |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 _die |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
_die(message) |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
sub _die { |
56
|
0
|
|
|
0
|
|
0
|
return __PACKAGE__::die(@_); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
##################################################################### |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 _info |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
_info(message) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
sub _info { |
67
|
0
|
|
|
0
|
|
0
|
return info(@_); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
##################################################################### |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 _error |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
_error(message) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
sub _error { |
78
|
0
|
|
|
0
|
|
0
|
return error(@_); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
##################################################################### |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 _debug |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
_debug(message) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
sub _debug { |
89
|
0
|
|
|
0
|
|
0
|
return debug(@_); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
##################################################################### |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 _trace |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
_trace(message) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
sub _trace { |
100
|
0
|
|
|
0
|
|
0
|
return trace(@_); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
##################################################################### |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 _log |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
_log(lvl, message) |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
sub _log { |
111
|
0
|
|
|
0
|
|
0
|
return log(@_); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
##################################################################### |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 uniq |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
uniq(objects, attr) |
119
|
|
|
|
|
|
|
uniq(objects, attr, name) |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
returns list of uniq values for one attr of a list of objects |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
ex.: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
get uniq list of group items |
126
|
|
|
|
|
|
|
uniq(hosts, 'group') |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
get uniq list of test tags |
129
|
|
|
|
|
|
|
uniq(hosts, 'tag', 'test') |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
sub uniq { |
133
|
0
|
|
|
0
|
1
|
0
|
my( $objects, $attrlist , $name ) = @_; |
134
|
0
|
0
|
|
|
|
0
|
croak('expected list of objects') unless ref $objects eq 'ARRAY'; |
135
|
0
|
|
|
|
|
0
|
my $uniq = {}; |
136
|
0
|
|
|
|
|
0
|
for my $o (@{$objects}) { |
|
0
|
|
|
|
|
0
|
|
137
|
0
|
|
|
|
|
0
|
for my $attr (@{_list($attrlist)}) { |
|
0
|
|
|
|
|
0
|
|
138
|
0
|
0
|
|
|
|
0
|
if($name) { |
139
|
0
|
0
|
|
|
|
0
|
next unless defined $o->{$attr}; |
140
|
0
|
0
|
|
|
|
0
|
next unless defined $o->{$attr}->{$name}; |
141
|
0
|
|
|
|
|
0
|
for my $v (split(/\s*\|\s*|\s*,\s*/mx, $o->{$attr}->{$name})) { |
142
|
0
|
|
|
|
|
0
|
$uniq->{$v} = 1; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} else { |
145
|
0
|
0
|
|
|
|
0
|
next unless defined $o->{$attr}; |
146
|
0
|
|
|
|
|
0
|
my $tmp = $o->{$attr}; |
147
|
0
|
0
|
|
|
|
0
|
if(ref $tmp ne 'ARRAY') { my @tmp = split(/\s*,\s*/mx,$tmp); $tmp = \@tmp; } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
148
|
0
|
|
|
|
|
0
|
for my $a (@{$tmp}) { |
|
0
|
|
|
|
|
0
|
|
149
|
0
|
|
|
|
|
0
|
$uniq->{$a} = 1; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
0
|
|
|
|
|
0
|
my @list = keys %{$uniq}; |
|
0
|
|
|
|
|
0
|
|
155
|
0
|
|
|
|
|
0
|
return \@list; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
##################################################################### |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 uniq_list |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
uniq_list(list1, list2, ...) |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
returns list of uniq values in all lists |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
sub uniq_list { |
168
|
8
|
50
|
33
|
8
|
1
|
25
|
return join_hash_list(@_) if defined $_[0] and ref $_[0] eq 'HASH'; |
169
|
8
|
|
|
|
|
7
|
my $uniq = {}; |
170
|
8
|
|
|
|
|
8
|
for my $list (@_) { |
171
|
8
|
50
|
|
|
|
13
|
if(ref $list eq 'HASH') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
172
|
0
|
|
|
|
|
0
|
for my $i (keys %{$list}) { |
|
0
|
|
|
|
|
0
|
|
173
|
0
|
|
|
|
|
0
|
$i =~ s/^\s+//mx; |
174
|
0
|
|
|
|
|
0
|
$i =~ s/\s+$//mx; |
175
|
0
|
|
|
|
|
0
|
$uniq->{$i} = 1; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
elsif(ref $list eq 'ARRAY') { |
179
|
2
|
|
|
|
|
2
|
for my $i (@{$list}) { |
|
2
|
|
|
|
|
2
|
|
180
|
6
|
|
|
|
|
8
|
my $tmp = uniq_list($i); |
181
|
6
|
50
|
|
|
|
8
|
if(ref $tmp eq '') { $tmp = [split(/\s*,\s*/mx, $tmp)]; } |
|
0
|
|
|
|
|
0
|
|
182
|
6
|
|
|
|
|
4
|
for my $k (@{$tmp}) { |
|
6
|
|
|
|
|
6
|
|
183
|
6
|
|
|
|
|
6
|
$k =~ s/^\s+//mx; |
184
|
6
|
|
|
|
|
5
|
$k =~ s/\s+$//mx; |
185
|
6
|
|
|
|
|
9
|
$uniq->{$k} = 1; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
elsif(ref $list eq '') { |
190
|
6
|
|
|
|
|
8
|
$list =~ s/^\s+//mx; |
191
|
6
|
|
|
|
|
6
|
$list =~ s/\s+$//mx; |
192
|
6
|
|
|
|
|
10
|
$uniq->{$list} = 1; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
else { |
195
|
0
|
|
|
|
|
0
|
croak('unexpected objects type in uniq_list()'.(ref $list)); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
8
|
|
|
|
|
6
|
my @items = sort keys %{$uniq}; |
|
8
|
|
|
|
|
15
|
|
199
|
8
|
|
|
|
|
14
|
return \@items; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
##################################################################### |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 join_hash_list |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
join_hash_list($hashlist, $exceptions) |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
returns list csv list for hash but leave out exceptions |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
sub join_hash_list { |
212
|
2
|
|
|
2
|
1
|
1035
|
my($hash, $exceptions) = @_; |
213
|
2
|
50
|
|
|
|
5
|
return "" unless defined $hash; |
214
|
2
|
|
|
|
|
3
|
my $list = []; |
215
|
2
|
|
|
|
|
2
|
for my $key (sort keys %{$hash}) { |
|
2
|
|
|
|
|
7
|
|
216
|
5
|
|
|
|
|
5
|
my $skip = 0; |
217
|
5
|
|
|
|
|
3
|
for my $ex (@{_list($exceptions)}) { |
|
5
|
|
|
|
|
7
|
|
218
|
3
|
100
|
|
|
|
15
|
if($key =~ m/$ex/mx) { |
219
|
1
|
|
|
|
|
2
|
$skip = 1; |
220
|
1
|
|
|
|
|
1
|
last; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
} |
223
|
5
|
100
|
|
|
|
9
|
next if $skip; |
224
|
4
|
|
|
|
|
1
|
for my $val (@{_list($hash->{$key})}) { |
|
4
|
|
|
|
|
6
|
|
225
|
6
|
100
|
|
|
|
8
|
if($val) { |
226
|
4
|
|
|
|
|
2
|
push @{$list}, $key.'='.$val; |
|
4
|
|
|
|
|
8
|
|
227
|
|
|
|
|
|
|
} else { |
228
|
2
|
|
|
|
|
1
|
push @{$list}, $key; |
|
2
|
|
|
|
|
12
|
|
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
} |
232
|
2
|
|
|
|
|
3
|
$list = uniq_list($list); |
233
|
2
|
|
|
|
|
3
|
return join(', ', sort @{$list}); |
|
2
|
|
|
|
|
6
|
|
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
##################################################################### |
237
|
|
|
|
|
|
|
sub _list { |
238
|
9
|
|
|
9
|
|
7
|
my($data) = @_; |
239
|
9
|
100
|
|
|
|
12
|
return([]) unless defined $data; |
240
|
7
|
100
|
|
|
|
16
|
return($data) if ref $data eq 'ARRAY'; |
241
|
2
|
|
|
|
|
4
|
return([$data]); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
##################################################################### |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 AUTHOR |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Sven Nierlein, 2013, |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
1; |