| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Zabbix::API::CRUDE; |
|
2
|
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
4077
|
use strict; |
|
|
6
|
|
|
|
|
14
|
|
|
|
6
|
|
|
|
|
193
|
|
|
4
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
13415
|
|
|
5
|
6
|
|
|
6
|
|
123
|
use 5.010; |
|
|
6
|
|
|
|
|
19
|
|
|
|
6
|
|
|
|
|
260
|
|
|
6
|
6
|
|
|
6
|
|
35
|
use Carp; |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
6712
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
|
9
|
|
|
|
|
|
|
|
|
10
|
0
|
|
|
0
|
1
|
|
my ($class, %args) = @_; |
|
11
|
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $self = \%args; |
|
13
|
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
bless $self, $class; |
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
return $self; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub id { |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
0
|
1
|
|
croak 'Class '.(ref shift).' does not implement required mutator id()'; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub node_id { |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if (defined $value) { |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
croak 'Accessor node_id() called as mutator'; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
return unless $self->id; |
|
37
|
0
|
0
|
|
|
|
|
return unless $self->id > 100000000000000; |
|
38
|
|
|
|
|
|
|
# this is how Zabbix operates, don't blame me |
|
39
|
0
|
|
|
|
|
|
return int($self->id/100000000000000); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub prefix { |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
1
|
|
croak 'Class '.(ref shift).' does not implement required method prefix()'; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub extension { |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
0
|
1
|
|
croak 'Class '.(ref shift).' does not implement required method extension()'; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub name { |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
1
|
|
croak 'Class '.(ref shift).' does not implement required method name()'; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub data { |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
## accessor for data |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if (defined $value) { |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
croak 'Accessor data() called as mutator'; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} else { |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
$self->{data} = {} unless exists $self->{data}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return $self->{data}; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub pull { |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
1
|
|
my ($self, $data) = @_; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if (defined $data) { |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->{data} = $data; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} else { |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
croak sprintf('Cannot pull data from server into a %s without ID', $self->prefix) |
|
92
|
|
|
|
|
|
|
unless $self->id; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
$self->{data} = $self->{root}->query(method => $self->prefix('.get'), |
|
95
|
|
|
|
|
|
|
params => { |
|
96
|
|
|
|
|
|
|
$self->prefix('ids') => [ $self->id ], |
|
97
|
|
|
|
|
|
|
$self->extension |
|
98
|
|
|
|
|
|
|
})->[0]; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
return $self; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub created { |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
return $self->id if $self->{root}->{lazy}; |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return @{$self->{root}->query(method => $self->prefix('.get'), |
|
|
0
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
params => { |
|
114
|
|
|
|
|
|
|
$self->prefix('ids') => [$self->id], |
|
115
|
|
|
|
|
|
|
$self->extension |
|
116
|
|
|
|
|
|
|
})}; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub collides { |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
1
|
|
croak 'Class '.(ref shift).' does not implement required method collides()'; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub push { |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
0
|
1
|
|
my ($self, $data) = @_; |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
0
|
|
|
|
$data //= $self->data; |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my @colliders; |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
0
|
0
|
|
|
|
if ($self->id and $self->created) { |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
say sprintf('Updating %s %s', $self->prefix, $self->id) |
|
137
|
|
|
|
|
|
|
if $self->{root}->{verbosity}; |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$self->{root}->query(method => $self->prefix('.update'), |
|
140
|
|
|
|
|
|
|
params => $data); |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
$self->pull unless $self->{root}->{lazy}; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
} elsif ($self->id) { |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
croak sprintf('%s has a %s but does not exist on server', $self->id, $self->prefix('id')); |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} elsif (@colliders = $self->collides and $colliders[0]) { |
|
149
|
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
say sprintf('Updating %s (match by collisions)', $self->prefix) |
|
151
|
|
|
|
|
|
|
if $self->{root}->{verbosity}; |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
if (@colliders > 1) { |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
croak sprintf('Cannot push %s: too many possible targets', $self->prefix); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
my $class = ref $self; |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# not referenced! and that's the way we want it |
|
162
|
0
|
|
|
|
|
|
my $collider = $class->new(root => $self->{root}, data => $colliders[0]); |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$self->id($collider->id); |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
$self->push; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
} else { |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
|
say 'Creating '.$self->prefix |
|
171
|
|
|
|
|
|
|
if $self->{root}->{verbosity}; |
|
172
|
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
my $id = $self->{root}->query(method => $self->prefix('.create'), |
|
174
|
|
|
|
|
|
|
params => $data)->{$self->prefix('ids')}->[0]; |
|
175
|
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
$self->id($id); |
|
177
|
|
|
|
|
|
|
|
|
178
|
0
|
0
|
|
|
|
|
$self->pull unless $self->{root}->{lazy}; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
return $self; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub delete { |
|
187
|
|
|
|
|
|
|
|
|
188
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
189
|
|
|
|
|
|
|
|
|
190
|
0
|
0
|
|
|
|
|
if ($self->id) { |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
0
|
|
|
|
|
say sprintf('Deleting %s %s', $self->prefix, $self->id) |
|
193
|
|
|
|
|
|
|
if $self->{root}->{verbosity}; |
|
194
|
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
$self->{root}->query(method => $self->prefix('.delete'), |
|
196
|
|
|
|
|
|
|
params => [ $self->id ]); |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
} else { |
|
199
|
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
carp sprintf(q{Useless call of delete() on a %s that does not have a %s}, $self->prefix, $self->prefix('id')); |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
return $self; |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |
|
209
|
|
|
|
|
|
|
__END__ |