/usr/share/perl5/Zabbix/API/Screen.pm is in libzabbix-api-perl 0.009-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | package Zabbix::API::Screen;
use strict;
use warnings;
use 5.010;
use Carp;
use parent qw/Exporter Zabbix::API::CRUDE/;
use List::Util qw/max/;
# extracted from frontends/php/include/defines.inc.php
use constant {
SCREEN_RESOURCE_GRAPH => 0,
SCREEN_RESOURCE_SIMPLE_GRAPH => 1,
SCREEN_RESOURCE_MAP => 2,
SCREEN_RESOURCE_PLAIN_TEXT => 3,
SCREEN_RESOURCE_HOSTS_INFO => 4,
SCREEN_RESOURCE_TRIGGERS_INFO => 5,
SCREEN_RESOURCE_SERVER_INFO => 6,
SCREEN_RESOURCE_CLOCK => 7,
SCREEN_RESOURCE_SCREEN => 8,
SCREEN_RESOURCE_TRIGGERS_OVERVIEW => 9,
SCREEN_RESOURCE_DATA_OVERVIEW => 10,
SCREEN_RESOURCE_URL => 11,
SCREEN_RESOURCE_ACTIONS => 12,
SCREEN_RESOURCE_EVENTS => 13,
SCREEN_RESOURCE_HOSTGROUP_TRIGGERS => 14,
SCREEN_RESOURCE_SYSTEM_STATUS => 15,
SCREEN_RESOURCE_HOST_TRIGGERS => 16,
};
our @EXPORT_OK = qw/SCREEN_RESOURCE_GRAPH SCREEN_RESOURCE_SIMPLE_GRAPH SCREEN_RESOURCE_MAP SCREEN_RESOURCE_PLAIN_TEXT SCREEN_RESOURCE_HOSTS_INFO SCREEN_RESOURCE_TRIGGERS_INFO SCREEN_RESOURCE_SERVER_INFO SCREEN_RESOURCE_CLOCK SCREEN_RESOURCE_SCREEN SCREEN_RESOURCE_TRIGGERS_OVERVIEW SCREEN_RESOURCE_DATA_OVERVIEW SCREEN_RESOURCE_URL SCREEN_RESOURCE_ACTIONS SCREEN_RESOURCE_EVENTS SCREEN_RESOURCE_HOSTGROUP_TRIGGERS SCREEN_RESOURCE_SYSTEM_STATUS SCREEN_RESOURCE_HOST_TRIGGERS/;
our %EXPORT_TAGS = (
resources => [ qw/SCREEN_RESOURCE_GRAPH SCREEN_RESOURCE_SIMPLE_GRAPH SCREEN_RESOURCE_MAP SCREEN_RESOURCE_PLAIN_TEXT SCREEN_RESOURCE_HOSTS_INFO SCREEN_RESOURCE_TRIGGERS_INFO SCREEN_RESOURCE_SERVER_INFO SCREEN_RESOURCE_CLOCK SCREEN_RESOURCE_SCREEN SCREEN_RESOURCE_TRIGGERS_OVERVIEW SCREEN_RESOURCE_DATA_OVERVIEW SCREEN_RESOURCE_URL SCREEN_RESOURCE_ACTIONS SCREEN_RESOURCE_EVENTS SCREEN_RESOURCE_HOSTGROUP_TRIGGERS SCREEN_RESOURCE_SYSTEM_STATUS SCREEN_RESOURCE_HOST_TRIGGERS/ ]
);
sub new {
my ($class, %args) = @_;
my $self = $class->SUPER::new(%args);
$self->data->{screenitems} = [] unless defined $self->data->{screenitems};
return $self;
}
sub id {
## mutator for id
my ($self, $value) = @_;
if (defined $value) {
$self->data->{screenid} = $value;
return $self->data->{screenid};
} else {
return $self->data->{screenid};
}
}
sub prefix {
my (undef, $suffix) = @_;
if ($suffix) {
return 'screen'.$suffix;
} else {
return 'screen';
}
}
sub extension {
return ( output => 'extend',
select_screenitems => 'extend' );
}
sub collides {
my $self = shift;
return @{$self->{root}->query(method => $self->prefix('.get'),
params => { filter => { name => $self->data->{name} } })};
}
sub items {
## mutator for items
my ($self, $value) = @_;
if (defined $value) {
if (@{$value}) {
# *some* validation, at least
croak 'Some screen items did not specify all their coordinates'
if grep { not exists $_->{'x'}
or not exists $_->{'y'} } @{$value};
# compute screen hsize and vsize from the screenitems max coordinates
my $hsize = max(map { $_->{'x'} } @{$value})+1;
my $vsize = max(map { $_->{'y'} } @{$value})+1;
$self->data->{hsize} = $hsize;
$self->data->{vsize} = $vsize;
} else {
# $value is an empty arrayref
$self->data->{hsize} = 0;
$self->data->{vsize} = 0;
}
$self->data->{screenitems} = $value;
return $self->data->{screenitems};
} else {
return $self->data->{screenitems};
}
}
sub push {
# override CRUDE's push()
my $self = shift;
foreach my $item (@{$self->data->{screenitems}}) {
if (exists $item->{graph}) {
if (eval { $item->{graph}->isa('Zabbix::API::Graph') }) {
$item->{graph}->push;
$item->{resourcetype} = SCREEN_RESOURCE_GRAPH;
$item->{resourceid} = $item->{graph}->id;
delete $item->{graph};
} else {
croak 'Type mismatch: graph attribute should be an instance of Zabbix::API::Graph';
}
} elsif (exists $item->{simplegraph}) {
if (eval { $item->{simplegraph}->isa('Zabbix::API::Item') }) {
$item->{simplegraph}->push;
$item->{resourcetype} = SCREEN_RESOURCE_SIMPLE_GRAPH;
$item->{resourceid} = $item->{simplegraph}->id;
delete $item->{simplegraph};
} else {
croak 'Type mismatch: graph attribute should be an instance of Zabbix::API::Item';
}
}
}
return $self->SUPER::push;
}
1;
__END__
=pod
=head1 NAME
Zabbix::API::Screen -- Zabbix screen objects
=head1 SYNOPSIS
use Zabbix::API::Screen;
# TODO write the rest
=head1 DESCRIPTION
Handles CRUD for Zabbix screen objects.
This is a subclass of C<Zabbix::API::CRUDE>.
=head1 METHODS
=over 4
=item items([ITEMS])
Mutator for the screenitems array. Setting the screenitems through this means
you won't have to set the C<hsize> and C<vsize> data attributes accordingly, as
that will be done for you. It also checks that the C<x> and C<y> attributes
have been specified for all the screenitems and throws an exception otherwise.
=item push()
This method handles extraneous C<< graph => Zabbix::API::Graph >> attributes in
the screenitems array, transforming them into C<resourceid> and C<resourcetype>
attributes, and pushing the graphs to the server if they don't exist already.
This means you can put C<Zabbix::API::Graph> objects in your data and the module
will Do The Right Thing (assuming you agree with my definition of the Right
Thing). Graphs that have been created this way will not be removed from the
server if they are removed from the screen, however.
Since graphs do the same thing with their C<Item> graphitems, you can create a
bunch of items, put them in a bunch of graphs, put those in a screen, push the
screen, sit back and enjoy the fireworks.
Overriden from C<Zabbix::API::CRUDE>.
=back
=head1 EXPORTS
A bunch of constants:
SCREEN_RESOURCE_GRAPH
SCREEN_RESOURCE_SIMPLE_GRAPH
SCREEN_RESOURCE_MAP
SCREEN_RESOURCE_PLAIN_TEXT
SCREEN_RESOURCE_HOSTS_INFO
SCREEN_RESOURCE_TRIGGERS_INFO
SCREEN_RESOURCE_SERVER_INFO
SCREEN_RESOURCE_CLOCK
SCREEN_RESOURCE_SCREEN
SCREEN_RESOURCE_TRIGGERS_OVERVIEW
SCREEN_RESOURCE_DATA_OVERVIEW
SCREEN_RESOURCE_URL
SCREEN_RESOURCE_ACTIONS
SCREEN_RESOURCE_EVENTS
SCREEN_RESOURCE_HOSTGROUP_TRIGGERS
SCREEN_RESOURCE_SYSTEM_STATUS
SCREEN_RESOURCE_HOST_TRIGGERS
These are used to specify the type of resource to use in a screenitem. They are
not exported by default, only on request; or you could import the C<:resources>
tag.
=head1 SEE ALSO
L<Zabbix::API::CRUDE>.
=head1 AUTHOR
Fabrice Gabolde <fabrice.gabolde@uperto.com>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2011 SFR
This library is free software; you can redistribute it and/or modify it under
the terms of the GPLv3.
=cut
|