| 1 | package Monitoring::TT::Utils; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | ▶ | my($list) = @_; | ||||||||
|
Subroutine
get_uniq_sorted: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 28 | 4 | my $hash = list2hash($list); | |||||||||
| 29 | 4 | my $uniq; | |||||||||
| 30 | 4 | @{$uniq} = sort keys %{$hash}; | |||||||||
| 31 | 4 | 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 | ▶ | my($list) = @_; | ||||||||
|
Subroutine
list2hash: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 45 | 4 | my $hash = {}; | |||||||||
| 46 | 4 | for my $i (@{$list}) { | |||||||||
| 47 | 9 | ▶ | if(!defined $i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | confess("undef:".Dumper($list)); | |||||||||
| 49 | } | ||||||||||
| 50 | 9 | $hash->{$i} = 1; | |||||||||
| 51 | } | ||||||||||
| 52 | 4 | 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 | ▶ | my($str) = @_; | ||||||||
|
Subroutine
parse_tags: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||
| 66 | 15 | my $tags = {}; | |||||||||
| 67 | 15 | ▶ | return $tags unless defined $str; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 3 | for my $s (split(/\s*,\s*/mx, $str)) { | |||||||||
| 69 | 9 | my($key,$val) = split(/\s*=\s*/mx,$s,2); | |||||||||
| 70 | 9 | $key = lc $key; | |||||||||
| 71 | 9 | ▶ | $val = '' unless defined $val; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 9 | ▶ | if(defined $tags->{$key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 2 | ▶ | if(ref $tags->{$key} eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 1 | $tags->{$key} = get_uniq_sorted([@{$tags->{$key}}, $val]); | |||||||||
| 75 | } else { | ||||||||||
| 76 | 1 | $tags->{$key} = get_uniq_sorted([$tags->{$key}, $val]); | |||||||||
| 77 | } | ||||||||||
| 78 | } else { | ||||||||||
| 79 | 7 | $tags->{$key} = $val; | |||||||||
| 80 | } | ||||||||||
| 81 | } | ||||||||||
| 82 | 3 | 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 | ▶ | my($str) = @_; | ||||||||
|
Subroutine
parse_groups: called CC=3 SCAR=15.1
Pod
documented
| |||||||||||
| 96 | 7 | my $groups = []; | |||||||||
| 97 | 7 | ▶ | return $groups unless defined $str; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | for my $s (split(/\s*,\s*/mx, $str)) { | |||||||||
| 99 | 0 | push @{$groups}, $s; | |||||||||
| 100 | } | ||||||||||
| 101 | 0 | return $groups; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | ##################################################################### | ||||||||||
| 106 | |||||||||||
| 107 | =head1 AUTHOR | ||||||||||
| 108 | |||||||||||
| 109 | Sven Nierlein, 2013, <sven.nierlein@consol.de> | ||||||||||
| 110 | |||||||||||
| 111 | =cut | ||||||||||
| 112 | |||||||||||
| 113 | 4 | 1; | |||||||||