| 1 | package Zabbix2::API::Macro; | ||||||||||||||||||||||
| 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 | 1 | ▶ | use autodie; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | 1 | ▶ | use utf8; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 1 | ▶ | use Moo::Lax; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 1 | ▶ | use JSON; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 1 | extends qw/Zabbix2::API::CRUDE/; | |||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | sub id { | ||||||||||||||||||||||
| 15 | ## mutator for id | ||||||||||||||||||||||
| 16 | 0 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||
|
Subroutine
id: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||
| 17 | 0 | ▶ | if (defined $value) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 18 | 0 | ▶ | if ($self->globalp) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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 | ▶ | if ($self->globalp) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 29 | 0 | return $self->data->{globalmacroid}; | |||||||||||||||||||||
| 30 | } else { | ||||||||||||||||||||||
| 31 | 0 | return $self->data->{hostmacroid}; | |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | sub _prefix { | ||||||||||||||||||||||
| 37 | 0 | ▶ | my ($self, $suffix) = @_; | ||||||||||||||||||||
|
Subroutine
_prefix: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||
| 38 | 0 | ▶ | if ($suffix) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 39 | 0 | ▶ | if ($suffix =~ m/ids?/) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 40 | 0 | ▶ | return ($self->globalp?'globalmacro':'hostmacro').$suffix; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 41 | } elsif ($suffix eq '.delete') { | ||||||||||||||||||||||
| 42 | 0 | ▶ | return 'usermacro.'.($self->globalp?'deleteglobal':'delete'); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 43 | } elsif ($suffix eq '.create') { | ||||||||||||||||||||||
| 44 | 0 | ▶ | return 'usermacro.'.($self->globalp?'createglobal':'create'); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 45 | } elsif ($suffix eq '.update') { | ||||||||||||||||||||||
| 46 | 0 | ▶ | return 'usermacro.'.($self->globalp?'updateglobal':'update'); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||
| 48 | 0 | return 'usermacro'.$suffix; | |||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||
| 50 | 0 | return 'usermacro'; | |||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | sub _extension { | ||||||||||||||||||||||
| 55 | 0 | ▶ | return (output => 'extend'); | ||||||||||||||||||||
|
Subroutine
_extension: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | sub name { | ||||||||||||||||||||||
| 59 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 60 | 0 | return $self->data->{macro}; | |||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||
| 62 | |||||||||||||||||||||||
| 63 | sub value { | ||||||||||||||||||||||
| 64 | 0 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||
|
Subroutine
value: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 65 | 0 | ▶ | if (defined $value) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 66 | 0 | $self->data->{value} = $value; | |||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||
| 68 | 0 | return $self->data->{value}; | |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | sub globalp { | ||||||||||||||||||||||
| 72 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
globalp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 73 | 0 | return !exists($self->data->{hostid}); | |||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | # overridden from CRUDE to set the globalmacro flag | ||||||||||||||||||||||
| 77 | sub pull { | ||||||||||||||||||||||
| 78 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
pull: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||
| 79 | 0 | ▶ | croak(sprintf(q{Cannot pull data from server into a %s without ID}, $self->short_class)) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 80 | unless $self->id; | ||||||||||||||||||||||
| 81 | 0 | ▶ | my $data = $self->root->query(method => $self->_prefix('.get'), | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 82 | params => { $self->_prefix('ids') => [ $self->id ], | ||||||||||||||||||||||
| 83 | globalmacro => $self->globalp ? JSON::true : JSON::false, | ||||||||||||||||||||||
| 84 | $self->_extension })->[0]; | ||||||||||||||||||||||
| 85 | 0 | ▶ | croak(sprintf(q{%s class object has a local ID that does not appear to exist on the server}, | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 86 | $self->short_class)) unless $data; | ||||||||||||||||||||||
| 87 | 0 | $self->_set_data($data); | |||||||||||||||||||||
| 88 | 0 | return $self; | |||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | sub exists { | ||||||||||||||||||||||
| 92 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
exists: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 93 | 0 | ▶ | my $response = $self->root->query(method => $self->_prefix('.get'), | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||||