line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix2::API::Host;
|
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1051
|
use strict;
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
117
|
|
4
|
3
|
|
|
3
|
|
20
|
use warnings;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
86
|
|
5
|
3
|
|
|
3
|
|
56
|
use 5.010;
|
|
3
|
|
|
|
|
14
|
|
6
|
3
|
|
|
3
|
|
19
|
use Carp;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
171
|
|
7
|
3
|
|
|
3
|
|
20
|
use autodie;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
22
|
|
8
|
3
|
|
|
3
|
|
16503
|
use utf8;
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
31
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
87
|
use Moo;
|
|
3
|
|
|
|
|
37
|
|
|
3
|
|
|
|
|
18
|
|
11
|
|
|
|
|
|
|
extends qw/Zabbix2::API::CRUDE/;
|
12
|
3
|
|
|
3
|
|
3058
|
use Zabbix2::API::HostInterface;
|
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
163
|
|
13
|
3
|
|
|
3
|
|
1309
|
use Zabbix2::API::Template;
|
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
2730
|
|
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
|
|
|
|
|
|
|
auto_compress => 1,
|
45
|
|
|
|
|
|
|
disable_until => 1,
|
46
|
|
|
|
|
|
|
error => 1,
|
47
|
|
|
|
|
|
|
errors_from => 1,
|
48
|
|
|
|
|
|
|
flags => 1,
|
49
|
|
|
|
|
|
|
ipmi_available => 1,
|
50
|
|
|
|
|
|
|
ipmi_disable_until => 1,
|
51
|
|
|
|
|
|
|
ipmi_error => 1,
|
52
|
|
|
|
|
|
|
ipmi_errors_from => 1,
|
53
|
|
|
|
|
|
|
jmx_available => 1,
|
54
|
|
|
|
|
|
|
jmx_error => 1,
|
55
|
|
|
|
|
|
|
jmx_errors_from => 1,
|
56
|
|
|
|
|
|
|
maintenance_from => 1,
|
57
|
|
|
|
|
|
|
maintenance_status => 1,
|
58
|
|
|
|
|
|
|
maintenance_type => 1,
|
59
|
|
|
|
|
|
|
maintenanceid => 1,
|
60
|
|
|
|
|
|
|
snmp_available => 1,
|
61
|
|
|
|
|
|
|
snmp_disable_until => 1,
|
62
|
|
|
|
|
|
|
snmp_error => 1,
|
63
|
|
|
|
|
|
|
snmp_errors_from => 1,
|
64
|
|
|
|
|
|
|
};
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _prefix {
|
68
|
0
|
|
|
0
|
|
|
my (undef, $suffix) = @_;
|
69
|
0
|
0
|
|
|
|
|
if ($suffix) {
|
70
|
0
|
|
|
|
|
|
return 'host'.$suffix;
|
71
|
|
|
|
|
|
|
} else {
|
72
|
0
|
|
|
|
|
|
return 'host';
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _extension {
|
77
|
0
|
|
|
0
|
|
|
return (output => 'extend',
|
78
|
|
|
|
|
|
|
selectMacros => 'extend',
|
79
|
|
|
|
|
|
|
selectInterfaces => 'extend');
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub name {
|
83
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
84
|
0
|
|
0
|
|
|
|
return $self->data->{name} || '???';
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _fetch_items {
|
88
|
0
|
|
|
0
|
|
|
my $self = shift;
|
89
|
0
|
|
|
|
|
|
my $items = $self->{root}->fetch('Item', params => { hostids => [ $self->data->{hostid} ] });
|
90
|
0
|
|
|
|
|
|
return $items;
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _fetch_hostgroups {
|
94
|
0
|
|
|
0
|
|
|
my $self = shift;
|
95
|
0
|
|
|
|
|
|
my $items = $self->{root}->fetch('HostGroup', params => { hostids => [ $self->data->{hostid} ] });
|
96
|
0
|
|
|
|
|
|
return $items;
|
97
|
|
|
|
|
|
|
}
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _fetch_templates {
|
100
|
0
|
|
|
0
|
|
|
my $self = shift;
|
101
|
0
|
|
|
|
|
|
my $items = $self->{root}->fetch('Template', params => { hostids => [ $self->data->{hostid} ] });
|
102
|
0
|
|
|
|
|
|
return $items;
|
103
|
|
|
|
|
|
|
}
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _fetch_graphs {
|
106
|
0
|
|
|
0
|
|
|
my $self = shift;
|
107
|
0
|
|
|
|
|
|
my $graphs = $self->{root}->fetch('Graph', params => { hostids => [ $self->data->{hostid} ] });
|
108
|
0
|
|
|
|
|
|
return $graphs;
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _map_interfaces_to_property {
|
112
|
0
|
|
|
0
|
|
|
my ($self) = @_;
|
113
|
0
|
|
|
|
|
|
$self->data->{interfaces} = [ map { $_->data } @{$self->interfaces} ];
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return;
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _map_property_to_interfaces {
|
118
|
0
|
|
|
0
|
|
|
my ($self) = @_;
|
119
|
0
|
|
|
|
|
|
my @interfaces = map { Zabbix2::API::HostInterface->new(root => $self->root,
|
120
|
0
|
|
|
|
|
|
data => $_) } @{$self->data->{interfaces}};
|
|
0
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$self->interfaces(\@interfaces);
|
122
|
0
|
|
|
|
|
|
return;
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
before 'create' => \&_map_interfaces_to_property;
|
126
|
|
|
|
|
|
|
before 'update' => \&_map_interfaces_to_property;
|
127
|
|
|
|
|
|
|
after 'pull' => \&_map_property_to_interfaces;
|
128
|
|
|
|
|
|
|
around 'new' => sub {
|
129
|
|
|
|
|
|
|
my ($orig, @rest) = @_;
|
130
|
|
|
|
|
|
|
my $host = $orig->(@rest);
|
131
|
|
|
|
|
|
|
$host->_map_property_to_interfaces;
|
132
|
|
|
|
|
|
|
return $host;
|
133
|
|
|
|
|
|
|
};
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1;
|
136
|
|
|
|
|
|
|
__END__
|