| 1 | package Zabbix::API::Trigger; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use parent qw/Zabbix::API::CRUDE/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 0 | ▶ | sub id { | ||||||||
|
Subroutine
id: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 11 | |||||||||||
| 12 | ## mutator for id | ||||||||||
| 13 | |||||||||||
| 14 | 0 | my ($self, $value) = @_; | |||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | if (defined $value) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | |||||||||||
| 18 | 0 | $self->data->{triggerid} = $value; | |||||||||
| 19 | 0 | return $self->data->{triggerid}; | |||||||||
| 20 | |||||||||||
| 21 | } else { | ||||||||||
| 22 | |||||||||||
| 23 | 0 | return $self->data->{triggerid}; | |||||||||
| 24 | |||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | sub prefix { | ||||||||
|
Subroutine
prefix: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 30 | |||||||||||
| 31 | 0 | my (undef, $suffix) = @_; | |||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | if ($suffix) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | 0 | return 'trigger'.$suffix; | |||||||||
| 36 | |||||||||||
| 37 | } else { | ||||||||||
| 38 | |||||||||||
| 39 | 0 | return 'trigger'; | |||||||||
| 40 | |||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub extension { | ||||||||
|
Subroutine
extension: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 46 | |||||||||||
| 47 | 0 | return ( output => 'extend', | |||||||||
| 48 | select_hosts => 'refer', | ||||||||||
| 49 | select_items => 'refer', | ||||||||||
| 50 | select_functions => 'extend', | ||||||||||
| 51 | select_dependencies => 'refer' ); | ||||||||||
| 52 | |||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub collides { | ||||||||
|
Subroutine
collides: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 56 | |||||||||||
| 57 | 0 | my $self = shift; | |||||||||
| 58 | |||||||||||
| 59 | 0 | return @{$self->{root}->query(method => $self->prefix('.get'), | |||||||||
| 60 | 0 | params => { filter => { description => [ $self->data->{description} ] }, | |||||||||
| 61 | $self->extension })}; | ||||||||||
| 62 | |||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub name { | ||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 66 | |||||||||||
| 67 | 0 | my $self = shift; | |||||||||
| 68 | |||||||||||
| 69 | # can't think of a good name for triggers -- descriptions are too long | ||||||||||
| 70 | 0 | return $self->data->{description}; | |||||||||
| 71 | |||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | sub hosts { | ||||||||
|
Subroutine
hosts: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 75 | |||||||||||
| 76 | ## accessor for host | ||||||||||
| 77 | |||||||||||
| 78 | 0 | my ($self, $value) = @_; | |||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | if (defined $value) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | |||||||||||
| 82 | 0 | croak 'Accessor hosts called as mutator'; | |||||||||
| 83 | |||||||||||
| 84 | } else { | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | unless (exists $self->{hosts}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | |||||||||||
| 88 | 0 | $self->{hosts} = $self->{root}->fetch('Host', params => { hostids => [ map { $_->{hostid} } @{$self->data->{hosts}} ] }); | |||||||||
| 89 | |||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | return $self->{hosts}; | |||||||||
| 93 | |||||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 0 | ▶ | sub items { | ||||||||
|
Subroutine
items: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 99 | |||||||||||
| 100 | ## accessor for items | ||||||||||
| 101 | |||||||||||
| 102 | 0 | my ($self, $value) = @_; | |||||||||
| 103 | |||||||||||
| 104 | 0 | ▶ | if (defined $value) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | |||||||||||
| 106 | 0 | croak 'Accessor items called as mutator'; | |||||||||
| 107 | |||||||||||
| 108 | } else { | ||||||||||
| 109 | |||||||||||
| 110 | 0 | ▶ | unless (exists $self->{items}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | |||||||||||
| 112 | 0 | $self->{items} = $self->{root}->fetch('Item', params => { itemids => [ map { $_->{itemid} } @{$self->data->{items}} ] }); | |||||||||
| 113 | |||||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 0 | return $self->{items}; | |||||||||
| 117 | |||||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 0 | ▶ | sub add_dependency { | ||||||||
|
Subroutine
add_dependency: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 123 | |||||||||||
| 124 | 0 | my ($self, $dependency) = @_; | |||||||||
| 125 | |||||||||||
| 126 | $self->{root}->query(method => $self->prefix('.addDependencies'), | ||||||||||
| 127 | params => [ { triggerid => $self->id, | ||||||||||
| 128 | 0 | ▶ | dependsOnTriggerid => eval { $dependency->isa('Zabbix::API::Trigger') } ? $dependency->id : $dependency } ]); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | |||||||||||
| 130 | 0 | $self->pull; | |||||||||
| 131 | |||||||||||
| 132 | 0 | return $self; | |||||||||
| 133 | |||||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | 0 | ▶ | sub dependencies { | ||||||||
|
Subroutine
dependencies: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 137 | |||||||||||
| 138 | 0 | my ($self, $value) = @_; | |||||||||
| 139 | |||||||||||
| 140 | 0 | ▶ | if (defined $value) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | |||||||||||
| 142 | 0 | croak 'Accessor dependencies called as mutator'; | |||||||||
| 143 | |||||||||||
| 144 | } else { | ||||||||||
| 145 | |||||||||||
| 146 | 0 | ▶ | unless (exists $self->{dependencies}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 147 | |||||||||||
| 148 | 0 | $self->{dependencies} = $self->{root}->fetch('Trigger', params => { triggerids => [ map { $_->{triggerid} } @{$self->data->{dependencies}} ] }); | |||||||||
| 149 | |||||||||||
| 150 | } | ||||||||||
| 151 | |||||||||||
| 152 | 0 | return $self->{dependencies}; | |||||||||
| 153 | |||||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | 0 | ▶ | sub remove_dependency { | ||||||||
|
Subroutine
remove_dependency: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 159 | |||||||||||
| 160 | 0 | my ($self, $dependency) = @_; | |||||||||
| 161 | |||||||||||
| 162 | 0 | $self->pull; | |||||||||
| 163 | |||||||||||
| 164 | 0 | my %deps = map { $_->{triggerid} => $_->{triggerid} } @{$self->data->{dependencies}}; | |||||||||
| 165 | |||||||||||
| 166 | 0 | ▶ | if (eval { $dependency->isa('Zabbix::API::Trigger') }) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 167 | |||||||||||
| 168 | 0 | ▶ | return $self unless exists $deps{$dependency->id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 169 | 0 | delete $deps{$dependency->id}; | |||||||||
| 170 | |||||||||||
| 171 | } else { | ||||||||||
| 172 | |||||||||||
| 173 | 0 | ▶ | return $self unless exists $deps{$dependency}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 174 | 0 | delete $deps{$dependency}; | |||||||||
| 175 | |||||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | 0 | $self->{root}->query(method => $self->prefix('.deleteDependencies'), | |||||||||
| 179 | params => [ { triggerid => $self->id } ]); | ||||||||||
| 180 | |||||||||||
| 181 | $self->{root}->query(method => $self->prefix('.addDependencies'), | ||||||||||
| 182 | 0 | params => [ map { { triggerid => $self->id, | |||||||||
| 183 | dependsOnTriggerid => $_ } } keys %deps ]); | ||||||||||
| 184 | |||||||||||
| 185 | 0 | $self->pull; | |||||||||
| 186 | |||||||||||
| 187 | 0 | return $self; | |||||||||
| 188 | |||||||||||
| 189 | } | ||||||||||
| 190 | |||||||||||
| 191 | 0 | ▶ | sub pull { | ||||||||
|
Subroutine
pull: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 192 | |||||||||||
| 193 | # override CRUDE's pull | ||||||||||
| 194 | |||||||||||
| 195 | 0 | my ($self, @args) = @_; | |||||||||
| 196 | |||||||||||
| 197 | # because they might have been updated | ||||||||||
| 198 | 0 | delete $self->{hosts}; | |||||||||
| 199 | 0 | delete $self->{items}; | |||||||||
| 200 | |||||||||||
| 201 | # and now this will set the correct ids, and next time we access the hosts | ||||||||||
| 202 | # or items they will be up to date | ||||||||||
| 203 | 0 | $self->SUPER::pull(@args); | |||||||||
| 204 | |||||||||||
| 205 | 0 | return $self; | |||||||||
| 206 | |||||||||||
| 207 | } | ||||||||||
| 208 | |||||||||||
| 209 | 1 | 1; | |||||||||
| 210 | __END__ | ||||||||||