| 1 | package Monitoring::TT::Object; | ||||||||||||||||||||||||||||||||||
| 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 Monitoring::TT::Object::Contact; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Monitoring::TT::Object::Host; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | Monitoring::TT::Object - Object representation of a data item | ||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | contains generic methods which can be used in templates for each object | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | =head2 new | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | returns new object | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||||||||
| 31 | sub new { | ||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my( $class, $type, $data ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 33 | 0 | $type = substr($type, 0, -1); | |||||||||||||||||||||||||||||||||
| 34 | 0 | my $objclass = 'Monitoring::TT::Object::'.ucfirst($type); | |||||||||||||||||||||||||||||||||
| 35 | 0 | my $obj = \&{$objclass."::BUILD"}; | |||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | die("no such type: $type") unless defined &$obj; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 37 | 0 | $data->{'object_type'} = lc($type); | |||||||||||||||||||||||||||||||||
| 38 | 0 | my $current_object = &$obj($objclass, $data); | |||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $current_object->{'montt'}->{$type.'spossible_tags'} = {} unless defined $current_object->{'montt'}->{$type.'spossible_tags'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 40 | 0 | $current_object->{'possibletags'} = $current_object->{'montt'}->{$type.'spossible_tags'}; | |||||||||||||||||||||||||||||||||
| 41 | 0 | return $current_object; | |||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | =head2 has_tag | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | returns true if object has specific tag, false otherwise. | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||||||||
| 53 | sub has_tag { | ||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | my( $self, $tag, $val ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
has_tag: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 55 | 0 | $tag = lc($tag); | |||||||||||||||||||||||||||||||||
| 56 | 0 | $self->{'possibletags'}->{$tag} = 1; | |||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return &_has_something($self, 'conf', $tag, $val) || &_has_something($self, 'extra_tags', $tag, $val) || &_has_something($self, 'tags', $tag, $val); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
&_has_something($self, 'conf', $tag, $val) || &_has_something($self, 'extra_tags', $tag, $val) || &_has_something($self, 'tags', $tag, $val)
&_has_something($self, "conf", $tag, $val) or &_has_something($self, "extra_tags", $tag, $val)
MC/DC0%0/3
&_has_something($self, 'conf', $tag, $val) || &_has_something($self, 'extra_tags', $tag, $val) || &_has_something($self, 'tags', $tag, $val)
&_has_something($self, "conf", $tag, $val)
&_has_something($self, "extra_tags", $tag, $val)
&_has_something($self, 'tags', $tag, $val)
Truth table0%0/4
A or B || C
A= &_has_something($self, "conf", $tag, $val)B= &_has_something($self, "extra_tags", $tag, $val)C= &_has_something($self, 'tags', $tag, $val)
| |||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | =head2 tags | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | returns list of tags or empty list otherwise | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||||||||
| 67 | sub tags { | ||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my( $self ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
tags: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return $self->{'tags'} if exists $self->{'tags'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 70 | 0 | return []; | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | =head2 extra_tags | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | returns list of extra tags or empty list otherwise | ||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||||||||
| 80 | sub extra_tags { | ||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my( $self ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
extra_tags: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return $self->{'extra_tags'} if exists $self->{'extra_tags'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 83 | 0 | return []; | |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | =head2 tag | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | returns value of this tag or empty string if not set | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||||||||
| 93 | sub tag { | ||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my( $self, $tag, $val ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
tag: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | croak('tag() does not accept value, use has_tag() instead') if $val; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 96 | 0 | $tag = lc $tag; | |||||||||||||||||||||||||||||||||
| 97 | 0 | $self->{'montt'}->{$self->{'object_type'}.'spossible_tags'}->{$tag} = 1; | |||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if($self->{'extra_tags'}->{$tag} and $self->{'tags'}->{$tag}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"extra_tags"}{$tag} and $self->{"tags"}{$tag}
MC/DC0%0/2
$self->{"extra_tags"}{$tag} and $self->{"tags"}{$tag}
$self->{"extra_tags"}{$tag}
$self->{"tags"}{$tag}
Truth table0%0/3
A and B
A= $self->{"extra_tags"}{$tag}B= $self->{"tags"}{$tag}
| |||||||||||||||||||||||||||||||||||
| 99 | 0 | my @list = @{$self->{'extra_tags'}->{$tag}}; | |||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | push @list, ref $self->{'tags'}->{$tag} eq 'ARRAY' ? @{$self->{'tags'}->{$tag}} : $self->{'tags'}->{$tag}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 101 | 0 | return(Monitoring::TT::Utils::get_uniq_sorted(\@list)); | |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return $self->{'extra_tags'}->{$tag} if $self->{'extra_tags'}->{$tag}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return $self->{'tags'}->{$tag} if $self->{'tags'}->{$tag}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return $self->{'conf'}->{$tag} if $self->{'conf'}->{$tag}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 106 | 0 | return ""; | |||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | =head2 set_tag | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | set additional tag | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||||||||
| 116 | sub set_tag { | ||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my( $self, $tag, $val ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
set_tag: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 118 | 0 | return $self->_set_something('extra_tags', $tag, $val); | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 122 | # INTERNAL SUBS | ||||||||||||||||||||||||||||||||||
| 123 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 124 | sub _has_something { | ||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my( $self, $type, $tag, $val ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_has_something: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | return 0 unless exists $self->{$type}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | 0 | $tag = lc $tag; | |||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return 0 unless exists $self->{$type}->{$tag}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if(defined $val) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 130 | 0 | $val = lc $val; | |||||||||||||||||||||||||||||||||
| 131 | 0 | my $tags = $self->{$type}->{$tag}; | |||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if(ref $tags eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 133 | 0 | for my $a (@{$tags}) { | |||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return 1 if lc($a) eq $val; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||
| 136 | } else { | ||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return 1 if lc($tags) eq $val; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return 1 if exists $self->{$type}->{$tag}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||
| 142 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 146 | sub _set_something { | ||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | my( $self, $type, $tag, $val ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_set_something: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 148 | 0 | $tag = lc $tag; | |||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | $val = "" unless defined $val; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $self->{$type}->{$tag} = [] unless defined $self->{$type}->{$tag}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if(ref $self->{$type}->{$tag} ne 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 152 | 0 | $self->{$type}->{$tag} = Monitoring::TT::Utils::get_uniq_sorted([$self->{$type}->{$tag}, $val]); | |||||||||||||||||||||||||||||||||
| 153 | } else { | ||||||||||||||||||||||||||||||||||
| 154 | 0 | $self->{$type}->{$tag} = Monitoring::TT::Utils::get_uniq_sorted([@{$self->{$type}->{$tag}}, $val]); | |||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||
| 156 | 0 | return ""; | |||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | ##################################################################### | ||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | Sven Nierlein, 2013, <sven.nierlein@consol.de> | ||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 4 | 1; | |||||||||||||||||||||||||||||||||