line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix::API::Graph; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
780
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
31
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
88
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Params::Validate qw/validate :types/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
250
|
|
9
|
1
|
|
|
1
|
|
929
|
use parent qw/Zabbix::API::CRUDE/; |
|
1
|
|
|
|
|
338
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
1
|
|
my ($class, %args) = @_; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(%args); |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
$self->data->{gitems} = [] unless defined $self->data->{gitems}; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub id { |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
## mutator for id |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if (defined $value) { |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$self->data->{graphid} = $value; |
31
|
0
|
|
|
|
|
|
return $self->data->{graphid}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} else { |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return $self->data->{graphid}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub prefix { |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
1
|
|
my (undef, $suffix) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ($suffix) { |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return 'graph'.$suffix; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} else { |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return 'graph'; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub extension { |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
0
|
1
|
|
return ( output => 'extend', |
60
|
|
|
|
|
|
|
select_graph_items => 'extend' ); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub collides { |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return @{$self->{root}->query(method => $self->prefix('.get'), |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
params => { filter => { name => $self->data->{name} }, |
70
|
|
|
|
|
|
|
$self->extension })}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub items { |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
## mutator for graph_items |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if (defined $value) { |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->data->{gitems} = $value; |
83
|
0
|
|
|
|
|
|
return $self->data->{gitems}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} else { |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $self->data->{gitems}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub url { |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
## return url for a graph |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $base_url = $self->{root}->{server}; |
100
|
0
|
|
|
|
|
|
$base_url =~ s{(?:/api_jsonrpc\.php)?$}{}; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my %args = validate(@_, { width => { type => SCALAR, optional => 1, regex => qr/^\d+$/ }, |
103
|
|
|
|
|
|
|
period => { type => SCALAR, optional => 1, regex => qr/^\d+$/ }, |
104
|
|
|
|
|
|
|
start_time => { type => SCALAR, optional => 1, regex => qr/^\d{14}$/ } }); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $url = $base_url.'/chart2.php?graphid='.$self->id; |
107
|
0
|
0
|
|
|
|
|
$url .= '&width='.$args{width} if $args{width}; |
108
|
0
|
0
|
|
|
|
|
$url .= '&period='.$args{period} if $args{period}; |
109
|
0
|
0
|
|
|
|
|
$url .= '&stime='.$args{start_time} if $args{start_time}; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $url; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub push { |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# override CRUDE's push() |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
0
|
1
|
|
my ($self, $data) = @_; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
0
|
|
|
|
$data //= $self->data; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
foreach my $item (@{$data->{gitems}}) { |
|
0
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
if (exists $item->{item}) { |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
if (eval { $item->{item}->isa('Zabbix::API::Item') }) { |
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
$item->{item}->push; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
$item->{itemid} = $item->{item}->id; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} else { |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
croak 'Type mismatch: item attribute should be an instance of Zabbix::API::Item'; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# copying the anonymous hashes so we can delete stuff without touching the |
144
|
|
|
|
|
|
|
# originals |
145
|
0
|
|
|
|
|
|
my $gitems_copy = [ map { { %{$_} } } @{$data->{gitems}} ]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
foreach my $item (@{$gitems_copy}) { |
|
0
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
delete $item->{item}; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# copying the data hashref so we can replace its gitems with the fake |
154
|
0
|
|
|
|
|
|
my $data_copy = { %{$data} }; |
|
0
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# the old switcheroo |
157
|
0
|
|
|
|
|
|
$data_copy->{gitems} = $gitems_copy; |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
return $self->SUPER::push($data_copy); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub pull { |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# override CRUDE's pull() |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
0
|
1
|
|
my ($self, $data) = @_; |
168
|
|
|
|
|
|
|
|
169
|
0
|
0
|
|
|
|
|
if (defined $data) { |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
$self->{data} = $data; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
} else { |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
my %stash = map { $_->id => $_ } grep { eval { $_->isa('Zabbix::API::Item') } } @{$self->items}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
$self->SUPER::pull; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
## no critic (ProhibitCommaSeparatedStatements) |
180
|
|
|
|
|
|
|
# restore stashed items that have been removed by pulling |
181
|
0
|
|
|
|
|
|
$self->items( |
182
|
|
|
|
|
|
|
[map { |
183
|
0
|
|
0
|
|
|
|
{ %{$_}, |
|
0
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
item => |
185
|
|
|
|
|
|
|
$stash{$_->{itemid}} // Zabbix::API::Item->new(root => $self->{root}, |
186
|
|
|
|
|
|
|
data => { itemid => $_->{itemid} })->pull |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
0
|
|
|
|
|
|
@{$self->items}] |
190
|
|
|
|
|
|
|
); |
191
|
|
|
|
|
|
|
## use critic |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
return $self; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
1; |
200
|
|
|
|
|
|
|
__END__ |