line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::TT::Utils; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
120
|
|
4
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
87
|
|
5
|
4
|
|
|
4
|
|
19
|
use utf8; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
83
|
|
6
|
4
|
|
|
4
|
|
75
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
202
|
|
7
|
4
|
|
|
4
|
|
19
|
use Data::Dumper; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1848
|
|
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
|
38
|
my($list) = @_; |
28
|
4
|
|
|
|
|
11
|
my $hash = list2hash($list); |
29
|
4
|
|
|
|
|
6
|
my $uniq; |
30
|
4
|
|
|
|
|
7
|
@{$uniq} = sort keys %{$hash}; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
16
|
|
31
|
4
|
|
|
|
|
20
|
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
|
7
|
my($list) = @_; |
45
|
4
|
|
|
|
|
8
|
my $hash = {}; |
46
|
4
|
|
|
|
|
6
|
for my $i (@{$list}) { |
|
4
|
|
|
|
|
9
|
|
47
|
9
|
50
|
|
|
|
29
|
if(!defined $i) { |
48
|
0
|
|
|
|
|
0
|
confess("undef:".Dumper($list)); |
49
|
|
|
|
|
|
|
} |
50
|
9
|
|
|
|
|
20
|
$hash->{$i} = 1; |
51
|
|
|
|
|
|
|
} |
52
|
4
|
|
|
|
|
11
|
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
|
860
|
my($str) = @_; |
66
|
15
|
|
|
|
|
21
|
my $tags = {}; |
67
|
15
|
100
|
|
|
|
57
|
return $tags unless defined $str; |
68
|
3
|
|
|
|
|
24
|
for my $s (split(/\s*,\s*/mx, $str)) { |
69
|
9
|
|
|
|
|
27
|
my($key,$val) = split(/\s*=\s*/mx,$s,2); |
70
|
9
|
|
|
|
|
15
|
$key = lc $key; |
71
|
9
|
100
|
|
|
|
25
|
$val = '' unless defined $val; |
72
|
9
|
100
|
|
|
|
28
|
if(defined $tags->{$key}) { |
73
|
2
|
100
|
|
|
|
8
|
if(ref $tags->{$key} eq 'ARRAY') { |
74
|
1
|
|
|
|
|
2
|
$tags->{$key} = get_uniq_sorted([@{$tags->{$key}}, $val]); |
|
1
|
|
|
|
|
9
|
|
75
|
|
|
|
|
|
|
} else { |
76
|
1
|
|
|
|
|
5
|
$tags->{$key} = get_uniq_sorted([$tags->{$key}, $val]); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} else { |
79
|
7
|
|
|
|
|
26
|
$tags->{$key} = $val; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
3
|
|
|
|
|
12
|
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
|
11
|
my($str) = @_; |
96
|
7
|
|
|
|
|
11
|
my $groups = []; |
97
|
7
|
50
|
|
|
|
29
|
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; |