line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix2::API::Host; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
408
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
35
|
|
5
|
2
|
|
|
2
|
|
28
|
use 5.010; |
|
2
|
|
|
|
|
6
|
|
6
|
2
|
|
|
2
|
|
6
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
89
|
|
7
|
2
|
|
|
2
|
|
7
|
use autodie; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
9
|
|
8
|
2
|
|
|
2
|
|
5646
|
use utf8; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
9
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
37
|
use Moo::Lax; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
extends qw/Zabbix2::API::CRUDE/; |
12
|
2
|
|
|
2
|
|
1573
|
use Zabbix2::API::HostInterface; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1145
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'items' => (is => 'ro', |
15
|
|
|
|
|
|
|
lazy => 1, |
16
|
|
|
|
|
|
|
builder => '_fetch_items'); |
17
|
|
|
|
|
|
|
has 'interfaces' => (is => 'rw'); |
18
|
|
|
|
|
|
|
has 'hostgroups' => (is => 'ro', |
19
|
|
|
|
|
|
|
lazy => 1, |
20
|
|
|
|
|
|
|
builder => '_fetch_hostgroups'); |
21
|
|
|
|
|
|
|
has 'graphs' => (is => 'ro', |
22
|
|
|
|
|
|
|
lazy => 1, |
23
|
|
|
|
|
|
|
builder => '_fetch_graphs'); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub id { |
26
|
|
|
|
|
|
|
## mutator for id |
27
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
28
|
0
|
0
|
|
|
|
|
if (defined $value) { |
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
|
|
|
0
|
|
|
hostid => 1, |
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
|
|
|
0
|
|
|
my (undef, $suffix) = @_; |
64
|
0
|
0
|
|
|
|
|
if ($suffix) { |
65
|
0
|
|
|
|
|
|
return 'host'.$suffix; |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
|
return 'host'; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _extension { |
72
|
0
|
|
|
0
|
|
|
return (output => 'extend', |
73
|
|
|
|
|
|
|
selectMacros => 'extend', |
74
|
|
|
|
|
|
|
selectInterfaces => 'extend'); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub name { |
78
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
79
|
0
|
|
0
|
|
|
|
return $self->data->{name} || '???'; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _fetch_items { |
83
|
0
|
|
|
0
|
|
|
my $self = shift; |
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
|
|
|
0
|
|
|
my $self = shift; |
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
|
|
|
0
|
|
|
my $self = shift; |
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
|
|
|
0
|
|
|
my ($self) = @_; |
102
|
0
|
|
|
|
|
|
$self->data->{interfaces} = [ map { $_->data } @{$self->interfaces} ]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _map_property_to_interfaces { |
107
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
108
|
0
|
|
|
|
|
|
my @interfaces = map { Zabbix2::API::HostInterface->new(root => $self->root, |
109
|
0
|
|
|
|
|
|
data => $_) } @{$self->data->{interfaces}}; |
|
0
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
$self->interfaces(\@interfaces); |
111
|
0
|
|
|
|
|
|
return; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
before 'create' => \&_map_interfaces_to_property; |
115
|
|
|
|
|
|
|
before 'update' => \&_map_interfaces_to_property; |
116
|
|
|
|
|
|
|
after 'pull' => \&_map_property_to_interfaces; |
117
|
|
|
|
|
|
|
around 'new' => sub { |
118
|
|
|
|
|
|
|
my ($orig, @rest) = @_; |
119
|
|
|
|
|
|
|
my $host = $orig->(@rest); |
120
|
|
|
|
|
|
|
$host->_map_property_to_interfaces; |
121
|
|
|
|
|
|
|
return $host; |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
__END__ |