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