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