line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix::API::Trigger; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
747
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
5
|
1
|
|
|
1
|
|
24
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
93
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
663
|
use parent qw/Zabbix::API::CRUDE/; |
|
1
|
|
|
|
|
351
|
|
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub id { |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
## mutator for id |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
if (defined $value) { |
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
|
|
|
|
|
|
|
sub prefix { |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
1
|
|
my (undef, $suffix) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
if ($suffix) { |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return 'trigger'.$suffix; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} else { |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return 'trigger'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub extension { |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
1
|
|
return ( output => 'extend', |
48
|
|
|
|
|
|
|
select_hosts => 'refer', |
49
|
|
|
|
|
|
|
select_items => 'refer', |
50
|
|
|
|
|
|
|
select_functions => 'extend', |
51
|
|
|
|
|
|
|
select_dependencies => 'refer' ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub collides { |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub name { |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub hosts { |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
## accessor for host |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if (defined $value) { |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
croak 'Accessor hosts called as mutator'; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} else { |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
unless (exists $self->{hosts}) { |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$self->{hosts} = $self->{root}->fetch('Host', params => { hostids => [ map { $_->{hostid} } @{$self->data->{hosts}} ] }); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return $self->{hosts}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub items { |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
## accessor for items |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
if (defined $value) { |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
croak 'Accessor items called as mutator'; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} else { |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
unless (exists $self->{items}) { |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$self->{items} = $self->{root}->fetch('Item', params => { itemids => [ map { $_->{itemid} } @{$self->data->{items}} ] }); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return $self->{items}; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub add_dependency { |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
0
|
1
|
|
my ($self, $dependency) = @_; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$self->{root}->query(method => $self->prefix('.addDependencies'), |
127
|
|
|
|
|
|
|
params => [ { triggerid => $self->id, |
128
|
0
|
0
|
|
|
|
|
dependsOnTriggerid => eval { $dependency->isa('Zabbix::API::Trigger') } ? $dependency->id : $dependency } ]); |
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$self->pull; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return $self; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub dependencies { |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
if (defined $value) { |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
croak 'Accessor dependencies called as mutator'; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
} else { |
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
unless (exists $self->{dependencies}) { |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$self->{dependencies} = $self->{root}->fetch('Trigger', params => { triggerids => [ map { $_->{triggerid} } @{$self->data->{dependencies}} ] }); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return $self->{dependencies}; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub remove_dependency { |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
0
|
1
|
|
my ($self, $dependency) = @_; |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
$self->pull; |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my %deps = map { $_->{triggerid} => $_->{triggerid} } @{$self->data->{dependencies}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
if (eval { $dependency->isa('Zabbix::API::Trigger') }) { |
|
0
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
|
return $self unless exists $deps{$dependency->id}; |
169
|
0
|
|
|
|
|
|
delete $deps{$dependency->id}; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
} else { |
172
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
|
return $self unless exists $deps{$dependency}; |
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, |
|
0
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
dependsOnTriggerid => $_ } } keys %deps ]); |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
$self->pull; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return $self; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub pull { |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# override CRUDE's pull |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
0
|
1
|
|
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; |
210
|
|
|
|
|
|
|
__END__ |