line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::TT::Utils; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
102
|
|
4
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
108
|
|
5
|
4
|
|
|
4
|
|
17
|
use utf8; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
14
|
|
6
|
4
|
|
|
4
|
|
65
|
use Carp; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
191
|
|
7
|
4
|
|
|
4
|
|
17
|
use Data::Dumper; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
1702
|
|
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
|
6
|
my($list) = @_; |
28
|
4
|
|
|
|
|
11
|
my $hash = list2hash($list); |
29
|
4
|
|
|
|
|
6
|
my $uniq; |
30
|
4
|
|
|
|
|
5
|
@{$uniq} = sort keys %{$hash}; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
13
|
|
31
|
4
|
|
|
|
|
14
|
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
|
8
|
my($list) = @_; |
45
|
4
|
|
|
|
|
8
|
my $hash = {}; |
46
|
4
|
|
|
|
|
5
|
for my $i (@{$list}) { |
|
4
|
|
|
|
|
7
|
|
47
|
9
|
50
|
|
|
|
18
|
if(!defined $i) { |
48
|
0
|
|
|
|
|
0
|
confess("undef:".Dumper($list)); |
49
|
|
|
|
|
|
|
} |
50
|
9
|
|
|
|
|
15
|
$hash->{$i} = 1; |
51
|
|
|
|
|
|
|
} |
52
|
4
|
|
|
|
|
8
|
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
|
684
|
my($str) = @_; |
66
|
15
|
|
|
|
|
25
|
my $tags = {}; |
67
|
15
|
100
|
|
|
|
42
|
return $tags unless defined $str; |
68
|
3
|
|
|
|
|
28
|
for my $s (split(/\s*,\s*/mx, $str)) { |
69
|
9
|
|
|
|
|
26
|
my($key,$val) = split(/\s*=\s*/mx,$s,2); |
70
|
9
|
|
|
|
|
13
|
$key = lc $key; |
71
|
9
|
100
|
|
|
|
19
|
$val = '' unless defined $val; |
72
|
9
|
100
|
|
|
|
15
|
if(defined $tags->{$key}) { |
73
|
2
|
100
|
|
|
|
5
|
if(ref $tags->{$key} eq 'ARRAY') { |
74
|
1
|
|
|
|
|
2
|
$tags->{$key} = get_uniq_sorted([@{$tags->{$key}}, $val]); |
|
1
|
|
|
|
|
3
|
|
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
|
11
|
my($str) = @_; |
96
|
7
|
|
|
|
|
10
|
my $groups = []; |
97
|
7
|
50
|
|
|
|
19
|
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; |