line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix2::API::Macro; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22247
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
5
|
1
|
|
|
1
|
|
16
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
72
|
|
7
|
1
|
|
|
1
|
|
5
|
use autodie; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
3487
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
19
|
use Moo::Lax; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
11
|
1
|
|
|
1
|
|
735
|
use JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
12
|
|
|
|
|
|
|
extends qw/Zabbix2::API::CRUDE/; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub id { |
15
|
|
|
|
|
|
|
## mutator for id |
16
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
17
|
0
|
0
|
|
|
|
|
if (defined $value) { |
18
|
0
|
0
|
|
|
|
|
if ($self->globalp) { |
19
|
0
|
|
|
|
|
|
$self->data->{globalmacroid} = $value; |
20
|
0
|
|
|
|
|
|
delete $self->data->{hostmacroid}; |
21
|
0
|
|
|
|
|
|
return $self->data->{globalmacroid}; |
22
|
|
|
|
|
|
|
} else { |
23
|
0
|
|
|
|
|
|
$self->data->{hostmacroid} = $value; |
24
|
0
|
|
|
|
|
|
delete $self->data->{globalmacroid}; |
25
|
0
|
|
|
|
|
|
return $self->data->{hostmacroid}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} else { |
28
|
0
|
0
|
|
|
|
|
if ($self->globalp) { |
29
|
0
|
|
|
|
|
|
return $self->data->{globalmacroid}; |
30
|
|
|
|
|
|
|
} else { |
31
|
0
|
|
|
|
|
|
return $self->data->{hostmacroid}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _prefix { |
37
|
0
|
|
|
0
|
|
|
my ($self, $suffix) = @_; |
38
|
0
|
0
|
|
|
|
|
if ($suffix) { |
39
|
0
|
0
|
|
|
|
|
if ($suffix =~ m/ids?/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
return ($self->globalp?'globalmacro':'hostmacro').$suffix; |
41
|
|
|
|
|
|
|
} elsif ($suffix eq '.delete') { |
42
|
0
|
0
|
|
|
|
|
return 'usermacro.'.($self->globalp?'deleteglobal':'delete'); |
43
|
|
|
|
|
|
|
} elsif ($suffix eq '.create') { |
44
|
0
|
0
|
|
|
|
|
return 'usermacro.'.($self->globalp?'createglobal':'create'); |
45
|
|
|
|
|
|
|
} elsif ($suffix eq '.update') { |
46
|
0
|
0
|
|
|
|
|
return 'usermacro.'.($self->globalp?'updateglobal':'update'); |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
return 'usermacro'.$suffix; |
49
|
|
|
|
|
|
|
} else { |
50
|
0
|
|
|
|
|
|
return 'usermacro'; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _extension { |
55
|
0
|
|
|
0
|
|
|
return (output => 'extend'); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub name { |
59
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
60
|
0
|
|
|
|
|
|
return $self->data->{macro}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub value { |
64
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
65
|
0
|
0
|
|
|
|
|
if (defined $value) { |
66
|
0
|
|
|
|
|
|
$self->data->{value} = $value; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
return $self->data->{value}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub globalp { |
72
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
73
|
0
|
|
|
|
|
|
return !exists($self->data->{hostid}); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# overridden from CRUDE to set the globalmacro flag |
77
|
|
|
|
|
|
|
sub pull { |
78
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
79
|
0
|
0
|
|
|
|
|
croak(sprintf(q{Cannot pull data from server into a %s without ID}, $self->short_class)) |
80
|
|
|
|
|
|
|
unless $self->id; |
81
|
0
|
0
|
|
|
|
|
my $data = $self->root->query(method => $self->_prefix('.get'), |
82
|
|
|
|
|
|
|
params => { $self->_prefix('ids') => [ $self->id ], |
83
|
|
|
|
|
|
|
globalmacro => $self->globalp ? JSON::true : JSON::false, |
84
|
|
|
|
|
|
|
$self->_extension })->[0]; |
85
|
0
|
0
|
|
|
|
|
croak(sprintf(q{%s class object has a local ID that does not appear to exist on the server}, |
86
|
|
|
|
|
|
|
$self->short_class)) unless $data; |
87
|
0
|
|
|
|
|
|
$self->_set_data($data); |
88
|
0
|
|
|
|
|
|
return $self; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub exists { |
92
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
93
|
0
|
0
|
|
|
|
|
my $response = $self->root->query(method => $self->_prefix('.get'), |
94
|
|
|
|
|
|
|
params => { $self->_prefix('ids') => [$self->id], |
95
|
|
|
|
|
|
|
globalmacro => $self->globalp ? JSON::true : JSON::false, |
96
|
|
|
|
|
|
|
countOutput => 1 }); |
97
|
0
|
|
|
|
|
|
return !!$response; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |