blib/lib/Zabbix/Sender.pm

filter: Statementstmt 53.3% 112 / 210 Branchbran 23.7% 19 / 80 Conditioncond 45.7% 16 / 35 MC/DCmcdc 15.0% 3 / 20 Subroutinesub 72.0% 18 / 25 Podpod 100% 5 / 5 totaltotal 46.1% 173 / 375 CC 57 SCAR 40.5
CC
57
Cov
45%
_decode_answer
156.0
_send
156.0
bulk_send
42.0
CRAP 57.4
↑ Summary
1 package Zabbix::Sender;
2 # ABSTRACT: A pure-perl implementation of zabbix-sender.
3 4 $Zabbix::Sender::VERSION = '0.06';
4 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Net::Domain;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 4 has 'server' => (
15 'is' => 'rw',
16 'isa' => 'Str',
17 'required' => 1,
18 );
19  
20 4 has 'port' => (
21 'is' => 'rw',
22 'isa' => 'Int',
23 'default' => 10051,
24 );
25  
26 4 has 'timeout' => (
27 'is' => 'rw',
28 'isa' => 'Int',
29 'default' => 30,
30 );
31  
32 4 has 'hostname' => (
33 'is' => 'rw',
34 'isa' => 'Str',
35 'lazy' => 1,
36 'builder' => '_init_hostname',
37 );
38  
39 4 has 'interval' => (
40 'is' => 'rw',
41 'isa' => 'Int',
42 'default' => 1,
43 );
44  
45 4 has 'retries' => (
46 'is' => 'rw',
47 'isa' => 'Int',
48 'default' => 3,
49 );
50  
51 4 has 'keepalive' => (
52 'is' => 'rw',
53 'isa' => 'Bool',
54 'default' => 0,
55 );
56  
57 4 has '_json' => (
58 'is' => 'rw',
59 'isa' => 'JSON',
60 'lazy' => 1,
61 'builder' => '_init_json',
62 );
63  
64 4 has '_last_sent' => (
65 'is' => 'rw',
66 'isa' => 'Int',
67 'default' => 0,
68 );
69  
70 4 has '_socket' => (
71 'is' => 'rw',
72 'isa' => 'Maybe[IO::Socket]',
73 );
74  
75 has 'response' => (
76 'is' => 'rw',
77 'isa' => 'HashRef',
78 2 ▶ 'default' => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
79 4 );
80  
81 has 'bulk_buf' => (
82 'is' => 'rw',
83 'isa' => 'ArrayRef',
84 2 ▶ 'default' => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
85 4 );
86  
87 4 has '_info' => (
88 'is' => 'rw',
89 'isa' => 'Str',
90 );
91  
92 4 has 'strict' => (
93 'is' => 'rw',
94 'isa' => 'Bool',
95 'default' => 0,
96 );
97  
98  
99  
100 sub _init_json {
101 1 ▶ my $self = shift;
Subroutine _init_json: called CC=1 SCAR=0.0
102  
103 1 my $JSON = JSON::->new->utf8();
104  
105 1 return $JSON;
106 }
107  
108  
109 sub _init_hostname {
110 0 ▶ my $self = shift;
Subroutine _init_hostname: not called CC=1 SCAR=6.9
111  
112 0 return Net::Domain::hostname() . '.' . Net::Domain::hostdomain();
113 }
114  
115  
116 4 has 'zabbix_template_1_8' => (
117 'is' => 'ro',
118 'isa' => 'Str',
119 'default' => "a4 b V V a*",
120 );
121  
122  
123 sub _encode_request {
124 2 ▶ my $self = shift;
Subroutine _encode_request: called CC=3 SCAR=11.0
125 2 my $values = shift;
126  
127 2 my @data;
128 2 for my $ref (@{$values}) {
129 2 my %data = (
130 'host' => $ref->[0],
131 'key' => $ref->[1],
132 'value' => $ref->[2],
133 );
134 2 ▶ $data{'clock'} = $ref->[3]
Branch: 1 branch
BranchTrueFalseTotal
if $ref->[3] 0 2 2
135 if $ref->[3];
136 2 push @data, \%data;
137 }
138  
139 2 my $data = {
140 'request' => 'sender data',
141 'data' => \@data,
142 };
143  
144 2 my $output = '';
145 2 my $json = $self->_json()->encode($data);
146  
147 # turn on byte semantics to get the real length of the string
148 4 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
149 2 my $length = length($json);
150 4 ▶ no bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
151  
152 ## no critic (ProhibitBitwiseOperators)
153 2 $output = pack(
154 $self->zabbix_template_1_8(),
155 "ZBXD", 0x01,
156 $length, 0x00,
157 $json
158 );
159 ## use critic
160  
161 2 return $output;
162 }
163  
164  
165 sub _check_info {
166 0 ▶ my $self = shift;
Subroutine _check_info: not called CC=4 SCAR=30.0
167 0 ▶ if($self->_info() !~ /^Processed:?\s+(\d+);?\s+Failed:?\s+(\d+);?\s+Total:?\s+(\d+);?\s+Seconds\s+spent:?\s+\d+.\d+$/i )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_info =~ /^Processed:?\s+(\d+);?\s+Failed:?\s+(\d+);?\s+Total:?\s+(\d+);?\s+Seconds\s+spent:?\s+\d+.\d+$/i) 0 0 0
168 {
169 0 return "Failed to parse info from zabbix server: ", $self->_info();
170 }
171 0 my($processed, $failed, $total) = (int($1), int($2), int($3));
172 0 ▶ return if $processed eq $total and $failed eq 0;
Branch: 1 branch
BranchTrueFalseTotal
if $processed eq $total and $failed eq 0 0 0 0
Condition0%0/3
$processed eq $total and $failed eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
$processed eq $total and $failed eq 0
$processed eq $total $failed eq 0
Truth table0%0/3
A and B
A= $processed eq $totalB= $failed eq 0
ABresult
0X0
100
111
173 0 return "(Processed, failed, total) != (x, 0, x) in info from zabbix server: ", $self->_info()
174 }
175  
176  
177 sub _decode_answer {
178 0 ▶ my $self = shift;
Subroutine _decode_answer: not called CC=12 SCAR=50.5
179 0 my $data = shift;
180  
181 0 $self->_info('');
182 0 my ( $ident, $answer );
183 0 ▶ $ident = substr( $data, 0, 4 ) if length($data) > 3;
Branch: 1 branch
BranchTrueFalseTotal
if length $data > 3 0 0 0
184 0 ▶ if ($ident and $ident eq 'ZBXD') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ident and $ident eq 'ZBXD') { } 0 0 0
Condition0%0/3
$ident and $ident eq "ZBXD"
!ll&&!rl&&r
000
MC/DC0%0/2
$ident and $ident eq "ZBXD"
$ident $ident eq "ZBXD"
Truth table0%0/3
A and B
A= $identB= $ident eq "ZBXD"
ABresult
0X0
100
111
185 # Headers are optional since Zabbix 2.0.8 and 2.1.7
186 0 ▶ if (length($data) > 12) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data > 12) { } 0 0 0
187 0 $answer = substr( $data, 13 );
188 } else {
189 0 carp "Invalid response header received: '$data' (length: ", length($data), ")";
190 0 return;
191 }
192 } else {
193 0 $answer = $data;
194 }
195  
196 0 ▶ if ( $answer ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($answer) 0 0 0
197 0 my $ref = $self->_json()->decode($answer);
198 0 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 0 0 0
199 0 $self->response($ref);
200 0 ▶ if ( $ref->{'response'} eq 'success' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{"response"} eq "success") 0 0 0
201 0 $self->_info($ref->{'info'});
202 0 ▶ if($self->strict())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->strict) 0 0 0
203 {
204 0 my $msg = $self->_check_info();
205 0 ▶ carp $msg if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 0 0
206 0 ▶ return 0 if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 0 0
207 }
208 0 return 1;
209 }
210 0 ▶ return $ref->{'response'} eq 'success' ? 1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'response'} eq 'success' ? : 0 0 0
211 } else {
212 0 $self->response(undef);
213 }
214 }
215 0 return;
216 }
217  
218  
219 # DGR: Anything but send just doesn't makes sense here. And since this is a pure-OO module
220 # and if the implementor avoids indirect object notation you should be fine.
221 ## no critic (ProhibitBuiltinHomonyms)
222 sub send {
223 ## use critic
224 0 ▶ my $self = shift;
Subroutine send: not called CC=5 SCAR=34.0
Pod documented
225 0 my $item = shift;
226 0 my $value = shift;
227 0 ▶ my $clock = shift || time;
Condition0%0/3
shift() || time
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || time
shift() time
Truth table0%0/3
A || B
A= shift()B= time
ABresult
1X1
011
000
228  
229 0 my $data = $self->_encode_request( [ [ $self->hostname(), $item, $value, $clock ] ] );
230 0 my $status = 0;
231 0 foreach my $i ( 1 .. $self->retries() ) {
232 0 ▶ if ( $self->_send( $data ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_send($data)) 0 0 0
233 0 $status = 1;
234 0 last;
235 }
236 }
237  
238 0 ▶ if ($status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) { } 0 0 0
239 0 return $self->response;
240 }
241 else { ## Should this die/croak/warn? Is this for timeout?
242 0 return;
243 }
244  
245 }
246  
247 sub _send {
248 0 ▶ my $self = shift;
Subroutine _send: not called CC=12 SCAR=50.5
249 0 my $data = shift;
250  
251 0 ▶ if ( time() - $self->_last_sent() < $self->interval() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (time - $self->_last_sent < $self->interval) 0 0 0
252 0 my $sleep = $self->interval() - ( time() - $self->_last_sent() );
253 0 ▶ $sleep ||= 0;
Condition0%0/2
$sleep ||= 0
l!l
00
MC/DC0%0/1
$sleep ||= 0
$sleep
Truth table0%0/2
A
A= $sleep
Aresult
11
00
254 0 sleep $sleep;
255 }
256  
257 0 ▶ unless ($self->_socket()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_socket) 0 0 0
258 return
259 0 ▶ unless $self->_connect();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_connect 0 0 0
260 }
261 0 $self->_socket()->send( $data );
262 0 my $Select = IO::Select::->new($self->_socket());
263 0 my $status = 0;
264 0 my $recvstarttime = time;
265 0 my $reply = '';
266 0 ▶ while($recvstarttime + $self->timeout() > time)
Branch: 1 branch
BranchTrueFalseTotal
if ($recvstarttime + $self->timeout > time) 0 0 0
267 {
268 0 my @Handles = $Select->can_read( $self->timeout() );
269  
270 0 ▶ if ( scalar(@Handles) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @Handles > 0) 0 0 0
271 0 my $result;
272 0 $self->_socket()->recv( $result, 1024 );
273 0 $reply .= $result;
274 0 ▶ next if length($reply) < 13;
Branch: 1 branch
BranchTrueFalseTotal
if length $reply < 13 0 0 0
275 # we need to recv until we have read either as much data as indicated
276 # in the header or there is an error. so we have to decode the header
277 # here, before calling _decode_answer.
278 0 my($ZBXD, $one, $len1, $len2, $json) = unpack 'A4 C V2 A*', $reply;
279 0 my $expected_length = 13 + $len1 + ($len2 << 32);
280 0 ▶ next if length($reply) < $expected_length;
Branch: 1 branch
BranchTrueFalseTotal
if length $reply < $expected_length 0 0 0
281 0 ▶ if ( $self->_decode_answer($reply) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_decode_answer($reply)) 0 0 0
282 0 $status = 1;
283 }
284 0 last;
285 }
286 }
287 0 ▶ $self->_disconnect() unless $self->keepalive();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->keepalive 0 0 0
288 0 ▶ if ($status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) { } 0 0 0
289 0 return $status;
290 }
291 else {
292 0 return;
293 }
294 }
295  
296 sub _connect {
297 0 ▶ my $self = shift;
Subroutine _connect: not called CC=2 SCAR=17.9
298  
299 0 ▶ my $Socket = IO::Socket::INET::->new(
Branch: 1 branch
BranchTrueFalseTotal
my $Socket = "IO::Socket::INET"->new("PeerAddr", $self->server, "PeerPort", $self->port, "Proto", "tcp", "Timeout", $self->timeout) or return 0 0 0
300 PeerAddr => $self->server(),
301 PeerPort => $self->port(),
302 Proto => 'tcp',
303 Timeout => $self->timeout(),
304 ) or return;
305  
306 0 $self->_socket($Socket);
307  
308 0 return 1;
309 }
310  
311 sub _disconnect {
312 2 ▶ my $self = shift;
Subroutine _disconnect: called CC=2 SCAR=9.2
313  
314 2 ▶ if(!$self->_socket()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_socket) 2 0 2
315 2 return;
316 }
317  
318 0 $self->_socket()->close();
319 0 $self->_socket(undef);
320  
321 0 return 1;
322 }
323  
324  
325 sub bulk_buf_add {
326 9 ▶ my $self = shift;
Subroutine bulk_buf_add: called CC=19 SCAR=29.9
Pod documented
327  
328 9 my @values;
329 9 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 12 3 15
330 12 my $arg = shift;
331 12 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) { } 12 0 12
332 12 ▶ if (ref $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg) { } 5 7 12
333 5 ▶ if (ref $arg eq 'ARRAY' and (@{$arg} == 2 or @{$arg} == 3)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY' and @{$arg;} == 2 || @{$arg;} == 3) { } 2 3 5
Condition83%5/6
ref $arg eq "ARRAY" and @{$arg;} == 2 || @{$arg;} == 3
!ll&&!rl&&r
122
@{$arg;} == 2 or @{$arg;} == 3
l!l&&r!l&&!r
022
MC/DC66%2/3
ref $arg eq "ARRAY" and @{$arg;} == 2 || @{$arg;} == 3
ref $arg eq "ARRAY" @{$arg;} == 2 @{$arg;} == 3
Truth table75%3/4
A and B or C
A= ref $arg eq "ARRAY"B= @{$arg;} == 2C= @{$arg;} == 3
ABCresult
0XX0
1000
11X1
1011
334 # Array of (key, value[, clock])
335 2 ▶ push @values, [ $self->hostname(),
Condition66%2/3
$arg->[2] || time
l!l&&r!l&&!r
110
MC/DC0%0/2
$arg->[2] || time
$arg->[2] time
Truth table66%2/3
A || B
A= $arg->[2]B= time
ABresult
1X1
011
000
336 $arg->[0], $arg->[1], $arg->[2] || time ];
337 } else {
338 3 carp "Invalid argument: Expected ARRAY with 2 or 3 elements";
339 3 return;
340 }
341 } else {
342 7 my $arg2 = shift;
343 7 ▶ if ($arg2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg2) { } 6 1 7
344 6 ▶ if (ref $arg2) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg2) { } 4 2 6
345 4 ▶ unless (ref $arg2 eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $arg2 eq "ARRAY") 1 3 4
346 1 carp "Invalid argument: Expected ARRAY";
347 1 return;
348 }
349 3 my $hostname = $arg;
350 3 for my $ref (@{$arg2}) {
351 5 ▶ if (ref $ref and ref $ref eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref and ref $ref eq 'ARRAY' and @{$ref;} == 2 || @{$ref;} == 3) { } 4 1 5
Condition66%6/9
ref $ref and ref $ref eq "ARRAY" and @{$ref;} == 2 || @{$ref;} == 3
!ll&&!rl&&r
104
ref $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
104
@{$ref;} == 2 or @{$ref;} == 3
l!l&&r!l&&!r
130
MC/DC25%1/4
ref $ref and ref $ref eq "ARRAY" and @{$ref;} == 2 || @{$ref;} == 3
ref $ref ref $ref eq "ARRAY" @{$ref;} == 2 @{$ref;} == 3
Truth table60%3/5
A and B and C or D
A= ref $refB= ref $ref eq "ARRAY"C= @{$ref;} == 2D= @{$ref;} == 3
ABCDresult
0XXX0
10XX0
11000
111X1
11011
352 4 and (@{$ref} == 2 or @{$ref} == 3)) {
353 # (key, value[, clock])
354 4 ▶ $ref->[2] = time
Branch: 1 branch
BranchTrueFalseTotal
unless $ref->[2] 2 2 4
355 unless $ref->[2];
356 4 ▶ push @values, [ $hostname, $ref->[0],
Condition33%1/3
$ref->[2] || time
l!l&&r!l&&!r
400
MC/DC0%0/2
$ref->[2] || time
$ref->[2] time
Truth table33%1/3
A || B
A= $ref->[2]B= time
ABresult
1X1
011
000
357 $ref->[1], $ref->[2] || time ];
358 } else {
359 1 carp "Invalid argument: ARRAY had not 2 or 3 elements";
360 1 return;
361 }
362 }
363 } else {
364 # (key, value[, clock])
365 2 my $key = $arg;
366 2 my $value = $arg2;
367 2 ▶ my $clock = shift || time;
Condition66%2/3
shift() || time
l!l&&r!l&&!r
110
MC/DC0%0/2
shift() || time
shift() time
Truth table66%2/3
A || B
A= shift()B= time
ABresult
1X1
011
000
368 2 push @values, [ $self->hostname(), $key, $value, $clock ];
369 }
370 } else {
371 1 carp "Insufficient number of arguments";
372 1 return;
373 }
374 }
375 } else {
376 0 carp "Insufficient number of arguments";
377 0 return;
378 }
379 }
380  
381 3 push @{$self->bulk_buf()}, @values;
382 3 return 1;
383 }
384  
385  
386 sub bulk_buf_clear {
387 1 ▶ my $self = shift;
Subroutine bulk_buf_clear: called CC=1 SCAR=0.0
Pod documented
388  
389 1 $self->bulk_buf([]);
390 }
391  
392  
393 sub bulk_send {
394 0 ▶ my $self = shift;
Subroutine bulk_send: not called CC=6 SCAR=37.4
Pod documented
395  
396 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
397 0 ▶ $self->bulk_buf_add(@_)
Branch: 1 branch
BranchTrueFalseTotal
$self->bulk_buf_add(@_) or return 0 0 0
398 or return;
399 }
400  
401 0 my $data = $self->_encode_request( $self->bulk_buf() );
402 0 my $status = 0;
403 0 foreach my $i ( 1 .. $self->retries() ) {
404 0 ▶ if ( $self->_send( $data ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_send($data)) 0 0 0
405 0 $status = 1;
406 0 last;
407 }
408 }
409  
410 0 ▶ if ($status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) { } 0 0 0
411 0 $self->bulk_buf_clear();
412 0 return 1;
413 }
414 else {
415 0 return;
416 }
417  
418 }
419  
420  
421 sub DEMOLISH {
422 2 ▶ my $self = shift;
Subroutine DEMOLISH: called CC=1 SCAR=0.0
Pod documented
423  
424 2 $self->_disconnect();
425  
426 2 return 1;
427 }
428  
429 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
430 4 __PACKAGE__->meta->make_immutable;
431  
432  
433 4 1; # End of Zabbix::Sender
434  
435 __END__
436  
437 =pod
438  
439 =encoding UTF-8
440  
441 =head1 NAME
442  
443 Zabbix::Sender - A pure-perl implementation of zabbix-sender.
444  
445 =head1 VERSION
446  
447 version 0.06
448  
449 =head1 SYNOPSIS
450  
451 This code snippet shows how to send the value "OK" for the item "my.zabbix.item"
452 to the zabbix server/proxy at "my.zabbix.server.example" on port "10055".
453  
454 use Zabbix::Sender;
455  
456 my $Sender = Zabbix::Sender->new({
457 'server' => 'my.zabbix.server.example',
458 'port' => 10055,
459 });
460 $Sender->send('my.zabbix.item','OK');
461  
462 =head1 NAME
463  
464 Zabbix::Sender - A pure-perl implementation of zabbix-sender.
465  
466 =head1 SUBROUTINES/METHODS
467  
468 =head2 hostname
469  
470 Name of the host for which to submit items to Zabbix. Initialized by _init_hostname. You can set it either using
471  
472 $Sender->hostname('another.hostname');
473  
474 or during creation time of Zabbix::Sender
475  
476 my $Sender = Zabbix::Sender->new({
477 'server' => 'my.zabbix.server.example',
478 'hostname' => 'another.hostname',
479 });
480  
481 You can also query the current setting using
482  
483 my $current_hostname = $Sender->hostname();
484  
485 =head2 strict
486  
487 Use the strict setting to make Zabbix::Sender check the return values from
488 Zabbix:
489  
490 $Sender->strict(1);
491  
492 You can also query the current setting using
493  
494 my $is_strict = $Sender->strict();
495  
496 =head2 _init_json
497  
498 Zabbix 1.8 uses a JSON encoded payload after a custom Zabbix header.
499 So this initializes the JSON object.
500  
501 =head2 _init_hostname
502  
503 The hostname of the sending instance may be given in the constructor.
504  
505 If not it is detected here.
506  
507 =head2 zabbix_template_1_8
508  
509 ZABBIX 1.8 TEMPLATE
510  
511 a4 - ZBXD
512 b - 0x01
513 V - Length of Request in Bytes (64-bit integer), aligned left, padded with 0x00, low 32 bits
514 V - High 32 bits of length (always 0 in Zabbix::Sender)
515 a* - JSON encoded request
516  
517 This may be changed to a HashRef if future version of zabbix change the header template.
518  
519 =head2 _encode_request
520  
521 This method encodes values as a json string and creates
522 the required header according to the template defined above.
523  
524 =head2 _check_info
525  
526 Checks the return value from the Zabbix server (or Zabbix proxy),
527 which states the number of processed, failed and total values.
528 Returns undef if everything is alright, a message otherwise.
529  
530 This method is called when the strict setting of Zabbix::Sender
531 is active:
532  
533 my $Sender = Zabbix::Sender->new({
534 'server' => 'my.zabbix.server.example',
535 'strict' => 1,
536 });
537  
538 =head2 _decode_answer
539  
540 This method tries to decode the answer received from the server.
541  
542 Returns true if response indicates success, false if response indicates
543 failure, undefined value if response was empty or cannot be decoded.
544  
545 Method "response" may be used to return decoded response.
546  
547 =head2 send
548  
549 Send the given item with the given value to the server.
550  
551 Takes two or three scalar arguments: item key, value and clock (clock is
552 optional).
553  
554 =head2 bulk_buf_add
555  
556 Adds values to the stack of values to bulk_send.
557  
558 It accepts arguments in forms:
559  
560 $sender->bulk_buf_add($key, $value, $clock, ...);
561 $sender->bulk_buf_add([$key, $value, $clock], ...);
562 $sender->bulk_buf_add($hostname, [ [$key, $value, $clock], ...], ...);
563  
564 Last form allows to add values for several hosts at once.
565  
566 $clock is optional and may be undef, empty or omitted.
567  
568 Returns true if successful or undef if invalid arguments are specified.
569  
570 =head2 bulk_buf_clear
571  
572 Clear bulk_send buffer.
573  
574 =head2 bulk_send
575  
576 Send accumulated values to the server.
577  
578 It accepts the same arguments as bulk_buf_add. If arguments are specified,
579 they are added to the buffer before sending.
580  
581 =head2 DEMOLISH
582  
583 Disconnects any open sockets on destruction.
584  
585 =head1 AUTHOR
586  
587 "Dominik Schulz", C<< <"lkml at ds.gauner.org"> >>
588  
589 =head1 BUGS
590  
591 Please report any bugs or feature requests to C<bug-zabbix-sender at rt.cpan.org>, or through
592 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Zabbix-Sender>. I will be notified, and then you'll
593 automatically be notified of progress on your bug as I make changes.
594  
595 =head1 SUPPORT
596  
597 You can find documentation for this module with the perldoc command.
598  
599 perldoc Zabbix::Sender
600  
601 You can also look for information at:
602  
603 =over 4
604  
605 =item * RT: CPAN's request tracker
606  
607 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Zabbix-Sender>
608  
609 =item * AnnoCPAN: Annotated CPAN documentation
610  
611 L<http://annocpan.org/dist/Zabbix-Sender>
612  
613 =item * CPAN Ratings
614  
615 L<http://cpanratings.perl.org/d/Zabbix-Sender>
616  
617 =item * Search CPAN
618  
619 L<http://search.cpan.org/dist/Zabbix-Sender/>
620  
621 =back
622  
623 =head1 ACKNOWLEDGEMENTS
624  
625 This code is based on the documentation and sample code found at:
626  
627 =over 4
628  
629 =item http://www.zabbix.com/documentation/1.8/protocols
630  
631 =back
632  
633 =head1 LICENSE AND COPYRIGHT
634  
635 Copyright 2011 Dominik Schulz.
636  
637 This program is free software; you can redistribute it and/or modify it
638 under the terms of either: the GNU General Public License as published
639 by the Free Software Foundation; or the Artistic License.
640  
641 See http://dev.perl.org/licenses/ for more information.
642  
643 =head1 AUTHOR
644  
645 Dominik Schulz <dominik.schulz@gauner.org>
646  
647 =head1 COPYRIGHT AND LICENSE
648  
649 This software is copyright (c) 2016 by Dominik Schulz.
650  
651 This is free software; you can redistribute it and/or modify it under
652 the same terms as the Perl 5 programming language system itself.
653  
654 =cut
↑ Summary