Zabbix2::API::Graph -- Zabbix graph objects
use Zabbix2::API::Graph; my $graph = $zabbix->fetch_single('Graph', params => { ... }); my $items = $zabbix->fetch('Item', params => { ... }); $graph->add_items(@{$items}); $graph->update; $graph->delete;
Handles CRUD for Zabbix graph objects.
This is a subclass of Zabbix2::API::CRUDE.
Zabbix2::API::CRUDE
(read-only coderef, with predicate and clearer)
This attribute is used to generate hex triplets representing colors. See make_color_wheel for a complete usage explanation.
make_color_wheel
(read-write arrayref of Zabbix2::API::GraphItem instances)
This attribute is populated automatically when the Perl object is updated from the "gitems" server property (i.e. when the pull method is called).
pull
Likewise, it is automatically used to populate the "gitems" property before either create or update are called.
create
update
my $items = $zabbix->fetch('Item', ...); $graph->add_items(@{$items});
This method is a shortcut to create graphs with the least hassle. It pushes new graph items in the graph's graphitems attribute, providing only the corresponding item ID and a color generated from the graph's color_wheel.
graphitems
color_wheel
Returns the Zabbix2::API::GraphItem objects created.
my $color_wheel = Zabbix2::API::Graph->make_color_wheel([ qw/1C1CCC 1CCC1C CC1C1C/ ... ]);
This class method returns an iterator over its argument. This makes it easy to repeatedly generate colors for graph items. Once the last element in the color array is reached, the iterator wraps around.
The default color wheel in the color_wheel attribute is
[qw/1C1CCC 1CCC1C CC1C1C FDFD49 9A1C9A 1CCCCC FD8C1C/] # royal blue, green, dark red, yellow, purple, turquoise, orange
which is a decently contrasted set of not-too-flashy colors, and happens to be the set of colors used in a CPU utilization graph at work.
my $url = $graph->url(width => $width, height => $height, period => $period, start_time => $start_time);
This method returns a URL to an image on the Zabbix server. The image of width width and height height will represent the current graph, plotted for data starting at start_time (a UNIX timestamp) over period seconds. (Note that the height and width parameters describe the plotting area; Zabbix will then make the final image bigger so that the legend and title can fit.) It uses the current connection's host name to guess what path to base the URL on.
width
height
start_time
period
All parameters are optional.
If the current user agent has cookies enabled, you can even fetch the image directly, since your API session is completely valid for all regular requests:
my $zabbix = Zabbix2::API->new(server => ..., ua => LWP::UserAgent->new(cookie_jar => { file => 'cookie.jar' }), ...); my $graph = $zabbix->fetch_single('Graph', ...); my $response = $zabbix->useragent->get($graph->url); open my $image, '>', 'graph.png' or die $!; $image->print($response->decoded_content); $image->close;
Some constants:
GRAPH_TYPE_NORMAL GRAPH_TYPE_STACKED GRAPH_TYPE_PIE GRAPH_TYPE_EXPLODED
They are not exported by default, only on request; or you could import the :graphtypes tag.
:graphtypes
A bunch of constants (graphitem types, axis stuff, ...) are not defined. If you need them, send me a feature request (or better, a pull request).
Zabbix2::API::CRUDE.
Fabrice Gabolde <fga@cpan.org>
Copyright (C) 2011, 2014 SFR
This library is free software; you can redistribute it and/or modify it under the terms of the GPLv3.
To install Zabbix2::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Zabbix2::API
CPAN shell
perl -MCPAN -e shell install Zabbix2::API
For more information on module installation, please visit the detailed CPAN module installation guide.