line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::TT::Utils; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
13
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
84
|
|
4
|
4
|
|
|
4
|
|
12
|
use warnings; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
99
|
|
5
|
4
|
|
|
4
|
|
13
|
use utf8; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
12
|
|
6
|
4
|
|
|
4
|
|
52
|
use Carp; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
168
|
|
7
|
4
|
|
|
4
|
|
14
|
use Data::Dumper; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
1282
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
##################################################################### |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Monitoring::TT::Utils - Util Functions |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Utility functions used within Monitoring::TT |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 get_uniq_sorted |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
get_uniq_sorted(list) |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
returns list sorted and duplicates removed |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
sub get_uniq_sorted { |
27
|
4
|
|
|
4
|
1
|
21
|
my($list) = @_; |
28
|
4
|
|
|
|
|
7
|
my $hash = list2hash($list); |
29
|
4
|
|
|
|
|
4
|
my $uniq; |
30
|
4
|
|
|
|
|
4
|
@{$uniq} = sort keys %{$hash}; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
9
|
|
31
|
4
|
|
|
|
|
13
|
return $uniq; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
##################################################################### |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 list2hash |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
list2hash(list) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
returns list transformed to hash |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
sub list2hash { |
44
|
4
|
|
|
4
|
1
|
3
|
my($list) = @_; |
45
|
4
|
|
|
|
|
4
|
my $hash = {}; |
46
|
4
|
|
|
|
|
6
|
for my $i (@{$list}) { |
|
4
|
|
|
|
|
5
|
|
47
|
9
|
50
|
|
|
|
13
|
if(!defined $i) { |
48
|
0
|
|
|
|
|
0
|
confess("undef:".Dumper($list)); |
49
|
|
|
|
|
|
|
} |
50
|
9
|
|
|
|
|
13
|
$hash->{$i} = 1; |
51
|
|
|
|
|
|
|
} |
52
|
4
|
|
|
|
|
5
|
return $hash; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
##################################################################### |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 parse_tags |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
parse_tags(str) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
returns parsed tags list |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
sub parse_tags { |
65
|
15
|
|
|
15
|
1
|
515
|
my($str) = @_; |
66
|
15
|
|
|
|
|
16
|
my $tags = {}; |
67
|
15
|
100
|
|
|
|
62
|
return $tags unless defined $str; |
68
|
3
|
|
|
|
|
14
|
for my $s (split(/\s*,\s*/mx, $str)) { |
69
|
9
|
|
|
|
|
16
|
my($key,$val) = split(/\s*=\s*/mx,$s,2); |
70
|
9
|
|
|
|
|
12
|
$key = lc $key; |
71
|
9
|
100
|
|
|
|
15
|
$val = '' unless defined $val; |
72
|
9
|
100
|
|
|
|
13
|
if(defined $tags->{$key}) { |
73
|
2
|
100
|
|
|
|
5
|
if(ref $tags->{$key} eq 'ARRAY') { |
74
|
1
|
|
|
|
|
1
|
$tags->{$key} = get_uniq_sorted([@{$tags->{$key}}, $val]); |
|
1
|
|
|
|
|
2
|
|
75
|
|
|
|
|
|
|
} else { |
76
|
1
|
|
|
|
|
3
|
$tags->{$key} = get_uniq_sorted([$tags->{$key}, $val]); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} else { |
79
|
7
|
|
|
|
|
14
|
$tags->{$key} = $val; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
3
|
|
|
|
|
8
|
return $tags; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
##################################################################### |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 parse_groups |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
parse_groups(str) |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
returns parsed groups list |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
sub parse_groups { |
95
|
7
|
|
|
7
|
1
|
8
|
my($str) = @_; |
96
|
7
|
|
|
|
|
7
|
my $groups = []; |
97
|
7
|
50
|
|
|
|
20
|
return $groups unless defined $str; |
98
|
0
|
|
|
|
|
|
for my $s (split(/\s*,\s*/mx, $str)) { |
99
|
0
|
|
|
|
|
|
push @{$groups}, $s; |
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
0
|
|
|
|
|
|
return $groups; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
##################################################################### |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 AUTHOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Sven Nierlein, 2013, |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |