line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::TT::Render; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
620
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
123
|
|
4
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
118
|
|
5
|
5
|
|
|
5
|
|
476
|
use utf8; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
21
|
|
6
|
5
|
|
|
5
|
|
127
|
use Carp; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
275
|
|
7
|
5
|
|
|
5
|
|
352
|
use Monitoring::TT::Log qw/error warn info debug trace log/; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
5636
|
|
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
|
24
|
return join_hash_list(@_) if defined $_[0] and ref $_[0] eq 'HASH'; |
169
|
8
|
|
|
|
|
10
|
my $uniq = {}; |
170
|
8
|
|
|
|
|
9
|
for my $list (@_) { |
171
|
8
|
50
|
|
|
|
18
|
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
|
|
|
|
|
14
|
my $tmp = uniq_list($i); |
181
|
6
|
50
|
|
|
|
12
|
if(ref $tmp eq '') { $tmp = [split(/\s*,\s*/mx, $tmp)]; } |
|
0
|
|
|
|
|
0
|
|
182
|
6
|
|
|
|
|
6
|
for my $k (@{$tmp}) { |
|
6
|
|
|
|
|
8
|
|
183
|
6
|
|
|
|
|
9
|
$k =~ s/^\s+//mx; |
184
|
6
|
|
|
|
|
8
|
$k =~ s/\s+$//mx; |
185
|
6
|
|
|
|
|
12
|
$uniq->{$k} = 1; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
elsif(ref $list eq '') { |
190
|
6
|
|
|
|
|
10
|
$list =~ s/^\s+//mx; |
191
|
6
|
|
|
|
|
11
|
$list =~ s/\s+$//mx; |
192
|
6
|
|
|
|
|
11
|
$uniq->{$list} = 1; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
else { |
195
|
0
|
|
|
|
|
0
|
croak('unexpected objects type in uniq_list()'.(ref $list)); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
8
|
|
|
|
|
8
|
my @items = sort keys %{$uniq}; |
|
8
|
|
|
|
|
21
|
|
199
|
8
|
|
|
|
|
17
|
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
|
1466
|
my($hash, $exceptions) = @_; |
213
|
2
|
50
|
|
|
|
5
|
return "" unless defined $hash; |
214
|
2
|
|
|
|
|
4
|
my $list = []; |
215
|
2
|
|
|
|
|
3
|
for my $key (sort keys %{$hash}) { |
|
2
|
|
|
|
|
7
|
|
216
|
5
|
|
|
|
|
6
|
my $skip = 0; |
217
|
5
|
|
|
|
|
6
|
for my $ex (@{_list($exceptions)}) { |
|
5
|
|
|
|
|
6
|
|
218
|
3
|
100
|
|
|
|
18
|
if($key =~ m/$ex/mx) { |
219
|
1
|
|
|
|
|
2
|
$skip = 1; |
220
|
1
|
|
|
|
|
2
|
last; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
} |
223
|
5
|
100
|
|
|
|
10
|
next if $skip; |
224
|
4
|
|
|
|
|
4
|
for my $val (@{_list($hash->{$key})}) { |
|
4
|
|
|
|
|
5
|
|
225
|
6
|
100
|
|
|
|
10
|
if($val) { |
226
|
4
|
|
|
|
|
4
|
push @{$list}, $key.'='.$val; |
|
4
|
|
|
|
|
11
|
|
227
|
|
|
|
|
|
|
} else { |
228
|
2
|
|
|
|
|
3
|
push @{$list}, $key; |
|
2
|
|
|
|
|
4
|
|
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
} |
232
|
2
|
|
|
|
|
5
|
$list = uniq_list($list); |
233
|
2
|
|
|
|
|
3
|
return join(', ', sort @{$list}); |
|
2
|
|
|
|
|
10
|
|
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
##################################################################### |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 lower |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
lower(str) |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
returns lower case string |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=cut |
245
|
|
|
|
|
|
|
sub lower { |
246
|
0
|
|
|
0
|
1
|
0
|
return lc($_[0]); |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
##################################################################### |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head2 services |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
services() |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
returns list of services |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=cut |
258
|
|
|
|
|
|
|
sub services { |
259
|
0
|
|
|
0
|
1
|
0
|
my $tt = $Monitoring::TT::Render::tt; |
260
|
0
|
0
|
|
|
|
0
|
if($tt->{'data'}->{'services'}) { |
261
|
0
|
|
|
|
|
0
|
return($tt->{'data'}->{'services'}); |
262
|
|
|
|
|
|
|
} |
263
|
0
|
|
|
|
|
0
|
my $reader = Monitoring::TT::Input::Nagios->new(montt => $tt); |
264
|
0
|
|
|
|
|
0
|
my $data = $reader->read($tt->{'out'}.'/conf.d/', ''); |
265
|
0
|
|
|
|
|
0
|
my @services; |
266
|
0
|
|
|
|
|
0
|
for my $o (@{$data}) { |
|
0
|
|
|
|
|
0
|
|
267
|
0
|
0
|
|
|
|
0
|
push @services, $o if $o->{'type'} eq 'service'; |
268
|
|
|
|
|
|
|
} |
269
|
0
|
|
|
|
|
0
|
$tt->{'data'}->{'services'} = \@services; |
270
|
0
|
|
|
|
|
0
|
return($tt->{'data'}->{'services'}); |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
##################################################################### |
274
|
|
|
|
|
|
|
sub _list { |
275
|
9
|
|
|
9
|
|
13
|
my($data) = @_; |
276
|
9
|
100
|
|
|
|
16
|
return([]) unless defined $data; |
277
|
7
|
100
|
|
|
|
14
|
return($data) if ref $data eq 'ARRAY'; |
278
|
2
|
|
|
|
|
4
|
return([$data]); |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
##################################################################### |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head1 AUTHOR |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Sven Nierlein, 2013, |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=cut |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
1; |