line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::TT::Render; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
779
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
152
|
|
4
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
121
|
|
5
|
5
|
|
|
5
|
|
908
|
use utf8; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
25
|
|
6
|
5
|
|
|
5
|
|
108
|
use Carp; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
307
|
|
7
|
5
|
|
|
5
|
|
474
|
use Monitoring::TT::Log qw/error warn info debug trace log/; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
3697
|
|
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
|
croak($msg); |
35
|
0
|
|
|
|
|
0
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
##################################################################### |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 uniq |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
uniq(objects, attr) |
43
|
|
|
|
|
|
|
uniq(objects, attr, name) |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
returns list of uniq values for one attr of a list of objects |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
ex.: |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
get uniq list of group items |
50
|
|
|
|
|
|
|
uniq(hosts, 'group') |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
get uniq list of test tags |
53
|
|
|
|
|
|
|
uniq(hosts, 'tag', 'test') |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
sub uniq { |
57
|
0
|
|
|
0
|
1
|
0
|
my( $objects, $attrlist , $name ) = @_; |
58
|
0
|
0
|
|
|
|
0
|
croak('expected list of objects') unless ref $objects eq 'ARRAY'; |
59
|
0
|
|
|
|
|
0
|
my $uniq = {}; |
60
|
0
|
|
|
|
|
0
|
for my $o (@{$objects}) { |
|
0
|
|
|
|
|
0
|
|
61
|
0
|
|
|
|
|
0
|
for my $attr (@{_list($attrlist)}) { |
|
0
|
|
|
|
|
0
|
|
62
|
0
|
0
|
|
|
|
0
|
if($name) { |
63
|
0
|
0
|
|
|
|
0
|
next unless defined $o->{$attr}; |
64
|
0
|
0
|
|
|
|
0
|
next unless defined $o->{$attr}->{$name}; |
65
|
0
|
|
|
|
|
0
|
for my $v (split(/\s*\|\s*|\s*,\s*/mx, $o->{$attr}->{$name})) { |
66
|
0
|
|
|
|
|
0
|
$uniq->{$v} = 1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
0
|
|
|
|
0
|
next unless defined $o->{$attr}; |
70
|
0
|
|
|
|
|
0
|
my $tmp = $o->{$attr}; |
71
|
0
|
0
|
|
|
|
0
|
if(ref $tmp ne 'ARRAY') { my @tmp = split(/\s*,\s*/mx,$tmp); $tmp = \@tmp; } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
72
|
0
|
|
|
|
|
0
|
for my $a (@{$tmp}) { |
|
0
|
|
|
|
|
0
|
|
73
|
0
|
|
|
|
|
0
|
$uniq->{$a} = 1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
0
|
my @list = keys %{$uniq}; |
|
0
|
|
|
|
|
0
|
|
79
|
0
|
|
|
|
|
0
|
return \@list; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
##################################################################### |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 uniq_list |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
uniq_list(list1, list2, ...) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
returns list of uniq values in all lists |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
sub uniq_list { |
92
|
2
|
50
|
33
|
2
|
1
|
13
|
return join_hash_list(@_) if defined $_[0] and ref $_[0] eq 'HASH'; |
93
|
2
|
|
|
|
|
3
|
my $uniq = {}; |
94
|
2
|
|
|
|
|
4
|
for my $list (@_) { |
95
|
2
|
|
|
|
|
2
|
for my $i (@{$list}) { |
|
2
|
|
|
|
|
6
|
|
96
|
6
|
|
|
|
|
12
|
$uniq->{$i} = 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
2
|
|
|
|
|
3
|
my @items = sort keys %{$uniq}; |
|
2
|
|
|
|
|
8
|
|
100
|
2
|
|
|
|
|
7
|
return \@items; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
##################################################################### |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 join_hash_list |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
join_hash_list($hashlist, $exceptions) |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
returns list csv list for hash but leave out exceptions |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
sub join_hash_list { |
113
|
2
|
|
|
2
|
1
|
1543
|
my($hash, $exceptions) = @_; |
114
|
2
|
50
|
|
|
|
9
|
return "" unless defined $hash; |
115
|
2
|
|
|
|
|
4
|
my $list = []; |
116
|
2
|
|
|
|
|
3
|
for my $key (sort keys %{$hash}) { |
|
2
|
|
|
|
|
12
|
|
117
|
5
|
|
|
|
|
7
|
my $skip = 0; |
118
|
5
|
|
|
|
|
6
|
for my $ex (@{_list($exceptions)}) { |
|
5
|
|
|
|
|
11
|
|
119
|
3
|
100
|
|
|
|
23
|
if($key =~ m/$ex/mx) { |
120
|
1
|
|
|
|
|
1
|
$skip = 1; |
121
|
1
|
|
|
|
|
2
|
last; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
5
|
100
|
|
|
|
16
|
next if $skip; |
125
|
4
|
|
|
|
|
5
|
for my $val (@{_list($hash->{$key})}) { |
|
4
|
|
|
|
|
9
|
|
126
|
6
|
100
|
|
|
|
10
|
if($val) { |
127
|
4
|
|
|
|
|
5
|
push @{$list}, $key.'='.$val; |
|
4
|
|
|
|
|
15
|
|
128
|
|
|
|
|
|
|
} else { |
129
|
2
|
|
|
|
|
3
|
push @{$list}, $key; |
|
2
|
|
|
|
|
26
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
2
|
|
|
|
|
6
|
$list = uniq_list($list); |
134
|
2
|
|
|
|
|
5
|
return join(', ', sort @{$list}); |
|
2
|
|
|
|
|
9
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
##################################################################### |
138
|
|
|
|
|
|
|
sub _list { |
139
|
9
|
|
|
9
|
|
10
|
my($data) = @_; |
140
|
9
|
100
|
|
|
|
81
|
return([]) unless defined $data; |
141
|
7
|
100
|
|
|
|
23
|
return($data) if ref $data eq 'ARRAY'; |
142
|
2
|
|
|
|
|
6
|
return([$data]); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
##################################################################### |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHOR |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Sven Nierlein, 2013, |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |