line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix2::API::Item; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
7009
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
48
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
34
|
|
5
|
2
|
|
|
2
|
|
30
|
use 5.010; |
|
2
|
|
|
|
|
4
|
|
6
|
2
|
|
|
2
|
|
6
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
96
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
7
|
use Params::Validate qw/validate validate_with :types/; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
295
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
8
|
use Moo::Lax; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
11
|
|
11
|
|
|
|
|
|
|
extends qw/Exporter Zabbix2::API::CRUDE/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use constant { |
14
|
2
|
|
|
|
|
1165
|
ITEM_TYPE_ZABBIX => 0, |
15
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV1 => 1, |
16
|
|
|
|
|
|
|
ITEM_TYPE_TRAPPER => 2, |
17
|
|
|
|
|
|
|
ITEM_TYPE_SIMPLE => 3, |
18
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV2C => 4, |
19
|
|
|
|
|
|
|
ITEM_TYPE_INTERNAL => 5, |
20
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV3 => 6, |
21
|
|
|
|
|
|
|
ITEM_TYPE_ZABBIX_ACTIVE => 7, |
22
|
|
|
|
|
|
|
ITEM_TYPE_AGGREGATE => 8, |
23
|
|
|
|
|
|
|
ITEM_TYPE_HTTPTEST => 9, |
24
|
|
|
|
|
|
|
ITEM_TYPE_EXTERNAL => 10, |
25
|
|
|
|
|
|
|
ITEM_TYPE_DB_MONITOR => 11, |
26
|
|
|
|
|
|
|
ITEM_TYPE_IPMI => 12, |
27
|
|
|
|
|
|
|
ITEM_TYPE_SSH => 13, |
28
|
|
|
|
|
|
|
ITEM_TYPE_TELNET => 14, |
29
|
|
|
|
|
|
|
ITEM_TYPE_CALCULATED => 15, |
30
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_FLOAT => 0, |
31
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_STR => 1, |
32
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_LOG => 2, |
33
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_UINT64 => 3, |
34
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_TEXT => 4, |
35
|
|
|
|
|
|
|
ITEM_DATA_TYPE_DECIMAL => 0, |
36
|
|
|
|
|
|
|
ITEM_DATA_TYPE_OCTAL => 1, |
37
|
|
|
|
|
|
|
ITEM_DATA_TYPE_HEXADECIMAL => 2, |
38
|
|
|
|
|
|
|
ITEM_STATUS_ACTIVE => 0, |
39
|
|
|
|
|
|
|
ITEM_STATUS_DISABLED => 1, |
40
|
|
|
|
|
|
|
ITEM_STATUS_NOTSUPPORTED => 3 |
41
|
2
|
|
|
2
|
|
855
|
}; |
|
2
|
|
|
|
|
2
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
44
|
|
|
|
|
|
|
ITEM_TYPE_ZABBIX |
45
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV1 |
46
|
|
|
|
|
|
|
ITEM_TYPE_TRAPPER |
47
|
|
|
|
|
|
|
ITEM_TYPE_SIMPLE |
48
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV2C |
49
|
|
|
|
|
|
|
ITEM_TYPE_INTERNAL |
50
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV3 |
51
|
|
|
|
|
|
|
ITEM_TYPE_ZABBIX_ACTIVE |
52
|
|
|
|
|
|
|
ITEM_TYPE_AGGREGATE |
53
|
|
|
|
|
|
|
ITEM_TYPE_HTTPTEST |
54
|
|
|
|
|
|
|
ITEM_TYPE_EXTERNAL |
55
|
|
|
|
|
|
|
ITEM_TYPE_DB_MONITOR |
56
|
|
|
|
|
|
|
ITEM_TYPE_IPMI |
57
|
|
|
|
|
|
|
ITEM_TYPE_SSH |
58
|
|
|
|
|
|
|
ITEM_TYPE_TELNET |
59
|
|
|
|
|
|
|
ITEM_TYPE_CALCULATED |
60
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_FLOAT |
61
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_STR |
62
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_LOG |
63
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_UINT64 |
64
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_TEXT |
65
|
|
|
|
|
|
|
ITEM_DATA_TYPE_DECIMAL |
66
|
|
|
|
|
|
|
ITEM_DATA_TYPE_OCTAL |
67
|
|
|
|
|
|
|
ITEM_DATA_TYPE_HEXADECIMAL |
68
|
|
|
|
|
|
|
ITEM_STATUS_ACTIVE |
69
|
|
|
|
|
|
|
ITEM_STATUS_DISABLED |
70
|
|
|
|
|
|
|
ITEM_STATUS_NOTSUPPORTED/; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
73
|
|
|
|
|
|
|
item_types => [ |
74
|
|
|
|
|
|
|
qw/ITEM_TYPE_ZABBIX |
75
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV1 |
76
|
|
|
|
|
|
|
ITEM_TYPE_TRAPPER |
77
|
|
|
|
|
|
|
ITEM_TYPE_SIMPLE |
78
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV2C |
79
|
|
|
|
|
|
|
ITEM_TYPE_INTERNAL |
80
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV3 |
81
|
|
|
|
|
|
|
ITEM_TYPE_ZABBIX_ACTIVE |
82
|
|
|
|
|
|
|
ITEM_TYPE_AGGREGATE |
83
|
|
|
|
|
|
|
ITEM_TYPE_HTTPTEST |
84
|
|
|
|
|
|
|
ITEM_TYPE_EXTERNAL |
85
|
|
|
|
|
|
|
ITEM_TYPE_DB_MONITOR |
86
|
|
|
|
|
|
|
ITEM_TYPE_IPMI |
87
|
|
|
|
|
|
|
ITEM_TYPE_SSH |
88
|
|
|
|
|
|
|
ITEM_TYPE_TELNET |
89
|
|
|
|
|
|
|
ITEM_TYPE_CALCULATED/ |
90
|
|
|
|
|
|
|
], |
91
|
|
|
|
|
|
|
value_types => [ |
92
|
|
|
|
|
|
|
qw/ITEM_VALUE_TYPE_FLOAT |
93
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_STR |
94
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_LOG |
95
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_UINT64 |
96
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_TEXT/ |
97
|
|
|
|
|
|
|
], |
98
|
|
|
|
|
|
|
data_types => [ |
99
|
|
|
|
|
|
|
qw/ITEM_DATA_TYPE_DECIMAL |
100
|
|
|
|
|
|
|
ITEM_DATA_TYPE_OCTAL |
101
|
|
|
|
|
|
|
ITEM_DATA_TYPE_HEXADECIMAL/ |
102
|
|
|
|
|
|
|
], |
103
|
|
|
|
|
|
|
status_types => [ |
104
|
|
|
|
|
|
|
qw/ITEM_STATUS_ACTIVE |
105
|
|
|
|
|
|
|
ITEM_STATUS_DISABLED |
106
|
|
|
|
|
|
|
ITEM_STATUS_NOTSUPPORTED/ |
107
|
|
|
|
|
|
|
] |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
has 'graphs' => (is => 'ro', |
111
|
|
|
|
|
|
|
lazy => 1, |
112
|
|
|
|
|
|
|
builder => '_fetch_graphs'); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
has 'host' => (is => 'ro', |
115
|
|
|
|
|
|
|
lazy => 1, |
116
|
|
|
|
|
|
|
builder => '_fetch_host'); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub id { |
119
|
|
|
|
|
|
|
## mutator for id |
120
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
121
|
0
|
0
|
|
|
|
|
if (defined $value) { |
122
|
0
|
|
|
|
|
|
$self->data->{itemid} = $value; |
123
|
0
|
|
|
|
|
|
return $self->data->{itemid}; |
124
|
|
|
|
|
|
|
} else { |
125
|
0
|
|
|
|
|
|
return $self->data->{itemid}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _readonly_properties { |
130
|
|
|
|
|
|
|
## hash of item properties that cannot be updated; they will be |
131
|
|
|
|
|
|
|
## removed before pushing the item to the server |
132
|
|
|
|
|
|
|
return { |
133
|
0
|
|
|
0
|
|
|
itemid => 1, |
134
|
|
|
|
|
|
|
error => 1, |
135
|
|
|
|
|
|
|
flags => 1, |
136
|
|
|
|
|
|
|
lastclock => 1, |
137
|
|
|
|
|
|
|
lastns => 1, |
138
|
|
|
|
|
|
|
lastvalue => 1, |
139
|
|
|
|
|
|
|
prevvalue => 1, |
140
|
|
|
|
|
|
|
state => 1, |
141
|
|
|
|
|
|
|
templateid => 1, |
142
|
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub _prefix { |
146
|
0
|
|
|
0
|
|
|
my ($class, $suffix) = @_; |
147
|
0
|
0
|
|
|
|
|
if ($suffix) { |
148
|
0
|
|
|
|
|
|
return 'item'.$suffix; |
149
|
|
|
|
|
|
|
} else { |
150
|
0
|
|
|
|
|
|
return 'item'; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub _extension { |
155
|
0
|
|
|
0
|
|
|
return ( output => 'extend' ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub name { |
159
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
160
|
|
|
|
|
|
|
return sprintf('%s/%s', |
161
|
|
|
|
|
|
|
eval { $self->host->name } || '???', |
162
|
0
|
|
0
|
|
|
|
$self->data->{key_} || '???'); |
|
|
|
0
|
|
|
|
|
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _fetch_graphs { |
166
|
0
|
|
|
0
|
|
|
my $self = shift; |
167
|
0
|
|
|
|
|
|
my $graphs = $self->{root}->fetch('Graph', params => { itemids => [ $self->id ] }); |
168
|
0
|
|
|
|
|
|
return $graphs; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub _fetch_host { |
172
|
0
|
|
|
0
|
|
|
my $self = shift; |
173
|
0
|
|
|
|
|
|
my $host = $self->{root}->fetch_single('Host', params => { hostids => [ $self->data->{hostid} ] }); |
174
|
0
|
|
|
|
|
|
return $host; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub history { |
178
|
0
|
|
|
0
|
1
|
|
my ($self, %params) = @_; |
179
|
0
|
|
|
|
|
|
my $history = $self->{root}->query(method => 'history.get', |
180
|
|
|
|
|
|
|
params => { itemids => [ $self->id ], |
181
|
|
|
|
|
|
|
output => 'extend', |
182
|
|
|
|
|
|
|
%params }); |
183
|
0
|
|
|
|
|
|
return $history; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |
187
|
|
|
|
|
|
|
__END__ |