line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix2::API::Item;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
11434
|
use strict;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
48
|
|
5
|
2
|
|
|
2
|
|
36
|
use 5.010;
|
|
2
|
|
|
|
|
8
|
|
6
|
2
|
|
|
2
|
|
10
|
use Carp;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
135
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
14
|
use Params::Validate qw/validate validate_with :types/;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
498
|
|
9
|
2
|
|
|
2
|
|
1037
|
use Text::ParseWords;
|
|
2
|
|
|
|
|
2772
|
|
|
2
|
|
|
|
|
136
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
15
|
use Moo;
|
|
2
|
|
|
|
|
28
|
|
|
2
|
|
|
|
|
11
|
|
12
|
|
|
|
|
|
|
extends qw/Exporter Zabbix2::API::CRUDE/;
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use constant {
|
15
|
2
|
|
|
|
|
1999
|
ITEM_TYPE_ZABBIX => 0,
|
16
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV1 => 1,
|
17
|
|
|
|
|
|
|
ITEM_TYPE_TRAPPER => 2,
|
18
|
|
|
|
|
|
|
ITEM_TYPE_SIMPLE => 3,
|
19
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV2C => 4,
|
20
|
|
|
|
|
|
|
ITEM_TYPE_INTERNAL => 5,
|
21
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV3 => 6,
|
22
|
|
|
|
|
|
|
ITEM_TYPE_ZABBIX_ACTIVE => 7,
|
23
|
|
|
|
|
|
|
ITEM_TYPE_AGGREGATE => 8,
|
24
|
|
|
|
|
|
|
ITEM_TYPE_HTTPTEST => 9,
|
25
|
|
|
|
|
|
|
ITEM_TYPE_EXTERNAL => 10,
|
26
|
|
|
|
|
|
|
ITEM_TYPE_DB_MONITOR => 11,
|
27
|
|
|
|
|
|
|
ITEM_TYPE_IPMI => 12,
|
28
|
|
|
|
|
|
|
ITEM_TYPE_SSH => 13,
|
29
|
|
|
|
|
|
|
ITEM_TYPE_TELNET => 14,
|
30
|
|
|
|
|
|
|
ITEM_TYPE_CALCULATED => 15,
|
31
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_FLOAT => 0,
|
32
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_STR => 1,
|
33
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_LOG => 2,
|
34
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_UINT64 => 3,
|
35
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_TEXT => 4,
|
36
|
|
|
|
|
|
|
ITEM_DATA_TYPE_DECIMAL => 0,
|
37
|
|
|
|
|
|
|
ITEM_DATA_TYPE_OCTAL => 1,
|
38
|
|
|
|
|
|
|
ITEM_DATA_TYPE_HEXADECIMAL => 2,
|
39
|
|
|
|
|
|
|
ITEM_STATUS_ACTIVE => 0,
|
40
|
|
|
|
|
|
|
ITEM_STATUS_DISABLED => 1,
|
41
|
|
|
|
|
|
|
ITEM_STATUS_NOTSUPPORTED => 3
|
42
|
2
|
|
|
2
|
|
951
|
};
|
|
2
|
|
|
|
|
5
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
our @EXPORT_OK = qw/
|
45
|
|
|
|
|
|
|
ITEM_TYPE_ZABBIX
|
46
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV1
|
47
|
|
|
|
|
|
|
ITEM_TYPE_TRAPPER
|
48
|
|
|
|
|
|
|
ITEM_TYPE_SIMPLE
|
49
|
|
|
|
|
|
|
ITEM_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M_TYPE_SIMPLE
|
79
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV2C
|
80
|
|
|
|
|
|
|
ITEM_TYPE_INTERNAL
|
81
|
|
|
|
|
|
|
ITEM_TYPE_SNMPV3
|
82
|
|
|
|
|
|
|
ITEM_TYPE_ZABBIX_ACTIVE
|
83
|
|
|
|
|
|
|
ITEM_TYPE_AGGREGATE
|
84
|
|
|
|
|
|
|
ITEM_TYPE_HTTPTEST
|
85
|
|
|
|
|
|
|
ITEM_TYPE_EXTERNAL
|
86
|
|
|
|
|
|
|
ITEM_TYPE_DB_MONITOR
|
87
|
|
|
|
|
|
|
ITEM_TYPE_IPMI
|
88
|
|
|
|
|
|
|
ITEM_TYPE_SSH
|
89
|
|
|
|
|
|
|
ITEM_TYPE_TELNET
|
90
|
|
|
|
|
|
|
ITEM_TYPE_CALCULATED/
|
91
|
|
|
|
|
|
|
],
|
92
|
|
|
|
|
|
|
value_types => [
|
93
|
|
|
|
|
|
|
qw/ITEM_VALUE_TYPE_FLOAT
|
94
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_STR
|
95
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_LOG
|
96
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_UINT64
|
97
|
|
|
|
|
|
|
ITEM_VALUE_TYPE_TEXT/
|
98
|
|
|
|
|
|
|
],
|
99
|
|
|
|
|
|
|
data_types => [
|
100
|
|
|
|
|
|
|
qw/ITEM_DATA_TYPE_DECIMAL
|
101
|
|
|
|
|
|
|
ITEM_DATA_TYPE_OCTAL
|
102
|
|
|
|
|
|
|
ITEM_DATA_TYPE_HEXADECIMAL/
|
103
|
|
|
|
|
|
|
],
|
104
|
|
|
|
|
|
|
status_types => [
|
105
|
|
|
|
|
|
|
qw/ITEM_STATUS_ACTIVE
|
106
|
|
|
|
|
|
|
ITEM_STATUS_DISABLED
|
107
|
|
|
|
|
|
|
ITEM_STATUS_NOTSUPPORTED/
|
108
|
|
|
|
|
|
|
]
|
109
|
|
|
|
|
|
|
);
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
has 'graphs' => (is => 'ro',
|
112
|
|
|
|
|
|
|
lazy => 1,
|
113
|
|
|
|
|
|
|
builder => '_fetch_graphs');
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
has 'host' => (is => 'ro',
|
116
|
|
|
|
|
|
|
lazy => 1,
|
117
|
|
|
|
|
|
|
builder => '_fetch_host');
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub id {
|
120
|
|
|
|
|
|
|
## mutator for id
|
121
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_;
|
122
|
0
|
0
|
|
|
|
|
if (defined $value) {
|
123
|
0
|
|
|
|
|
|
$self->data->{itemid} = $value;
|
124
|
0
|
|
|
|
|
|
return $self->data->{itemid};
|
125
|
|
|
|
|
|
|
} else {
|
126
|
0
|
|
|
|
|
|
return $self->data->{itemid};
|
127
|
|
|
|
|
|
|
}
|
128
|
|
|
|
|
|
|
}
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _readonly_properties {
|
131
|
|
|
|
|
|
|
## hash of item properties that cannot be updated; they will be
|
132
|
|
|
|
|
|
|
## removed before pushing the item to the server
|
133
|
|
|
|
|
|
|
return {
|
134
|
0
|
|
|
0
|
|
|
itemid => 1,
|
135
|
|
|
|
|
|
|
error => 1,
|
136
|
|
|
|
|
|
|
flags => 1,
|
137
|
|
|
|
|
|
|
lastclock => 1,
|
138
|
|
|
|
|
|
|
lastns => 1,
|
139
|
|
|
|
|
|
|
lastvalue => 1,
|
140
|
|
|
|
|
|
|
prevvalue => 1,
|
141
|
|
|
|
|
|
|
state => 1,
|
142
|
|
|
|
|
|
|
templateid => 1,
|
143
|
|
|
|
|
|
|
};
|
144
|
|
|
|
|
|
|
}
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub _prefix {
|
147
|
0
|
|
|
0
|
|
|
my ($class, $suffix) = @_;
|
148
|
0
|
0
|
|
|
|
|
if ($suffix) {
|
149
|
0
|
|
|
|
|
|
return 'item'.$suffix;
|
150
|
|
|
|
|
|
|
} else {
|
151
|
0
|
|
|
|
|
|
return 'item';
|
152
|
|
|
|
|
|
|
}
|
153
|
|
|
|
|
|
|
}
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub _extension {
|
156
|
0
|
|
|
0
|
|
|
return ( output => 'extend' );
|
157
|
|
|
|
|
|
|
}
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub name {
|
160
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
161
|
0
|
|
|
|
|
|
return $self->data->{name};
|
162
|
|
|
|
|
|
|
}
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub expanded_name {
|
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# we are not expanding hostmacros or globalmacros, those are problematic
|
169
|
0
|
|
|
|
|
|
my $key = $self->data->{key_};
|
170
|
0
|
|
|
|
|
|
my $token_re = qr/[0-9a-zA-Z_.-]+/;
|
171
|
0
|
|
|
|
|
|
$key =~ m/^$token_re\[(.*)\]$/;
|
172
|
0
|
|
|
|
|
|
my $arg_list = $1;
|
173
|
|
|
|
|
|
|
|
174
|
0
|
0
|
|
|
|
|
return $self->name unless $arg_list;
|
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
my @args = parse_line(',', 0, $arg_list);
|
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my $name = $self->data->{name};
|
179
|
0
|
|
|
|
|
|
$name =~ s/\$(\d)/$args[$1 -1]/e;
|
|
0
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# if ($name =~ m/\{\$[A-Z0-9_.]+\}/) {
|
182
|
|
|
|
|
|
|
# die "there are macro names in this name, can't expand them";
|
183
|
|
|
|
|
|
|
# }
|
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
return $name;
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
}
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub _fetch_graphs {
|
190
|
0
|
|
|
0
|
|
|
my $self = shift;
|
191
|
0
|
|
|
|
|
|
my $graphs = $self->{root}->fetch('Graph', params => { itemids => [ $self->id ] });
|
192
|
0
|
|
|
|
|
|
return $graphs;
|
193
|
|
|
|
|
|
|
}
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _fetch_host {
|
196
|
0
|
|
|
0
|
|
|
my $self = shift;
|
197
|
0
|
|
|
|
|
|
my $host = $self->{root}->fetch_single('Host', params => { hostids => [ $self->data->{hostid} ] });
|
198
|
0
|
|
|
|
|
|
return $host;
|
199
|
|
|
|
|
|
|
}
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub history {
|
202
|
0
|
|
|
0
|
1
|
|
my ($self, %params) = @_;
|
203
|
|
|
|
|
|
|
my $history = $self->{root}->query(method => 'history.get',
|
204
|
|
|
|
|
|
|
params => { itemids => [ $self->id ],
|
205
|
|
|
|
|
|
|
output => 'extend',
|
206
|
|
|
|
|
|
|
history => $self->data->{value_type},
|
207
|
0
|
|
|
|
|
|
%params });
|
208
|
0
|
|
|
|
|
|
return $history;
|
209
|
|
|
|
|
|
|
}
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
1;
|
212
|
|
|
|
|
|
|
__END__
|