| 1 | package Zabbix2::API::Host; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use 5.010; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use autodie; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 2 | ▶ | use Moo::Lax; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 2 | extends qw/Zabbix2::API::CRUDE/; | |||||||||||
| 12 | 2 | ▶ | use Zabbix2::API::HostInterface; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 2 | has 'items' => (is => 'ro', | |||||||||||
| 15 | lazy => 1, | ||||||||||||
| 16 | builder => '_fetch_items'); | ||||||||||||
| 17 | 2 | has 'interfaces' => (is => 'rw'); | |||||||||||
| 18 | 2 | has 'hostgroups' => (is => 'ro', | |||||||||||
| 19 | lazy => 1, | ||||||||||||
| 20 | builder => '_fetch_hostgroups'); | ||||||||||||
| 21 | 2 | has 'graphs' => (is => 'ro', | |||||||||||
| 22 | lazy => 1, | ||||||||||||
| 23 | builder => '_fetch_graphs'); | ||||||||||||
| 24 | |||||||||||||
| 25 | sub id { | ||||||||||||
| 26 | ## mutator for id | ||||||||||||
| 27 | 0 | ▶ | my ($self, $value) = @_; | ||||||||||
|
Subroutine
id: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 28 | 0 | ▶ | if (defined $value) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 0 | $self->data->{hostid} = $value; | |||||||||||
| 30 | 0 | return $self->data->{hostid}; | |||||||||||
| 31 | } else { | ||||||||||||
| 32 | 0 | return $self->data->{hostid}; | |||||||||||
| 33 | } | ||||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | sub _readonly_properties { | ||||||||||||
| 37 | return { | ||||||||||||
| 38 | 0 | ▶ | hostid => 1, | ||||||||||
|
Subroutine
_readonly_properties: not called CC=1 SCAR=6.9
| |||||||||||||
| 39 | available => 1, | ||||||||||||
| 40 | disable_until => 1, | ||||||||||||
| 41 | error => 1, | ||||||||||||
| 42 | errors_from => 1, | ||||||||||||
| 43 | flags => 1, | ||||||||||||
| 44 | ipmi_available => 1, | ||||||||||||
| 45 | ipmi_disable_until => 1, | ||||||||||||
| 46 | ipmi_error => 1, | ||||||||||||
| 47 | ipmi_errors_from => 1, | ||||||||||||
| 48 | jmx_available => 1, | ||||||||||||
| 49 | jmx_error => 1, | ||||||||||||
| 50 | jmx_errors_from => 1, | ||||||||||||
| 51 | maintenance_from => 1, | ||||||||||||
| 52 | maintenance_status => 1, | ||||||||||||
| 53 | maintenance_type => 1, | ||||||||||||
| 54 | maintenanceid => 1, | ||||||||||||
| 55 | snmp_available => 1, | ||||||||||||
| 56 | snmp_disable_until => 1, | ||||||||||||
| 57 | snmp_error => 1, | ||||||||||||
| 58 | snmp_errors_from => 1, | ||||||||||||
| 59 | }; | ||||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | sub _prefix { | ||||||||||||
| 63 | 0 | ▶ | my (undef, $suffix) = @_; | ||||||||||
|
Subroutine
_prefix: not called CC=2 SCAR=17.9
| |||||||||||||
| 64 | 0 | ▶ | if ($suffix) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 0 | return 'host'.$suffix; | |||||||||||
| 66 | } else { | ||||||||||||
| 67 | 0 | return 'host'; | |||||||||||
| 68 | } | ||||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | sub _extension { | ||||||||||||
| 72 | 0 | ▶ | return (output => 'extend', | ||||||||||
|
Subroutine
_extension: not called CC=1 SCAR=6.9
| |||||||||||||
| 73 | selectMacros => 'extend', | ||||||||||||
| 74 | selectInterfaces => 'extend'); | ||||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | sub name { | ||||||||||||
| 78 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 79 | 0 | ▶ | return $self->data->{name} || '???'; | ||||||||||
|
Condition0%0/2
$self->data->{'name'} || '???'
MC/DC0%0/1
$self->data->{'name'} || '???'
$self->data->{'name'}
Truth table0%0/2
A
A= $self->data->{'name'}
| |||||||||||||
| 80 | } | ||||||||||||
| 81 | |||||||||||||
| 82 | sub _fetch_items { | ||||||||||||
| 83 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_fetch_items: not called CC=1 SCAR=6.9
| |||||||||||||
| 84 | 0 | my $items = $self->{root}->fetch('Item', params => { hostids => [ $self->data->{hostid} ] }); | |||||||||||
| 85 | 0 | return $items; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | sub _fetch_hostgroups { | ||||||||||||
| 89 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_fetch_hostgroups: not called CC=1 SCAR=6.9
| |||||||||||||
| 90 | 0 | my $items = $self->{root}->fetch('HostGroup', params => { hostids => [ $self->data->{hostid} ] }); | |||||||||||
| 91 | 0 | return $items; | |||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | sub _fetch_graphs { | ||||||||||||
| 95 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_fetch_graphs: not called CC=1 SCAR=6.9
| |||||||||||||
| 96 | 0 | my $graphs = $self->{root}->fetch('Graph', params => { hostids => [ $self->data->{hostid} ] }); | |||||||||||
| 97 | 0 | return $graphs; | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | sub _map_interfaces_to_property { | ||||||||||||
| 101 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
_map_interfaces_to_property: not called CC=1 SCAR=6.9
| |||||||||||||
| 102 | 0 | $self->data->{interfaces} = [ map { $_->data } @{$self->interfaces} ]; | |||||||||||
| 103 | 0 | return; | |||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | sub _map_property_to_interfaces { | ||||||||||||
| 107 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
_map_property_to_interfaces: not called CC=1 SCAR=6.9
| |||||||||||||
| 108 | 0 | my @interfaces = map { Zabbix2::API::HostInterface->new(root => $self->root, | |||||||||||
| 109 | 0 | data => $_) } @{$self->data->{interfaces}}; | |||||||||||
| 110 | 0 | $self->interfaces(\@interfaces); | |||||||||||
| 111 | 0 | return; | |||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | 2 | before 'create' => \&_map_interfaces_to_property; | |||||||||||
| 115 | 2 | before 'update' => \&_map_interfaces_to_property; | |||||||||||
| 116 | 2 | after 'pull' => \&_map_property_to_interfaces; | |||||||||||
| 117 | around 'new' => sub { | ||||||||||||
| 118 | 0 | ▶ | my ($orig, @rest) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 119 | 0 | my $host = $orig->(@rest); | |||||||||||
| 120 | 0 | $host->_map_property_to_interfaces; | |||||||||||
| 121 | 0 | return $host; | |||||||||||
| 122 | 2 | }; | |||||||||||
| 123 | |||||||||||||
| 124 | 2 | 1; | |||||||||||
| 125 | __END__ | ||||||||||||