[ZBXNEXT-562] Get PNG graph image via API Created: 2010 Nov 18 Updated: 2023 Feb 20 |
|
Status: | Open |
Project: | ZABBIX FEATURE REQUESTS |
Component/s: | API (A) |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | New Feature Request | Priority: | Major |
Reporter: | azurIt | Assignee: | Unassigned |
Resolution: | Unresolved | Votes: | 132 |
Labels: | api, export, graphs, png | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Issue Links: |
|
Description |
Can you please add API function which will return graph as an PNG image ? We would like to integrate graphs to our application but we don't want to draw them from graph items (Zabbix is doing this very fine so i don't see a point in it). Thx. |
Comments |
Comment by azurIt [ 2012 Oct 11 ] |
What 'Zabbix ID: NMR' means? |
Comment by Mattias Geniar [ 2012 Dec 30 ] |
NMR = Needs More Research Since the current work-around to get the graphs involves faking a POST form submit to the frontpage and re-using that sessionID to get the graph itself is pretty annoying, a simple PNG return of the image would be much welcomed as an API request. |
Comment by Oleksii Zagorskyi [ 2012 Dec 31 ] |
|
Comment by Karim GUEDIDER [ 2013 Apr 09 ] |
Hi |
Comment by Thierry Sallé [ 2013 Oct 04 ] |
Yo can directly convert images url to png format using the Perl Zabbix::API. |
Comment by azurIt [ 2013 Oct 04 ] |
Thierry Sallé: I don't see a point in implementing the whole graph drawing as Zabbix is able to do it very fine. |
Comment by Eric VdB [ 2014 Jan 14 ] |
Well, there is a point here. It would be super handy if we can retrieve graph images from the api for automated reporting features |
Comment by Linus Brimstedt [ 2014 Sep 24 ] |
The point of implementing in this in the API rather than accessing the php-pages is that the API is a stable and documented interface. The chart2.php is an internal implementation that should not be used by external resources. |
Comment by Darrin Chambers [ 2017 Sep 22 ] |
Hi all, since the last comment in 2014, has this been resolved? I/we would greatly appreciate it. |
Comment by Stoyan Stoyanov [ 2018 May 02 ] |
Yes, is there any update on the request? |
Comment by Dawid Mos [ 2018 May 02 ] |
Maybe in delayed 4.0? |
Comment by Stoyan Stoyanov [ 2018 May 02 ] |
It will be nice if there is an official statement. |
Comment by Alexander Nesterov [ 2019 Feb 04 ] |
my solution: ... use strict; use warnings; use LWP::UserAgent; use HTTP::Request; use MIME::Lite; use MIME::Base64; ... sub zabbix_get_graph { my ($graphid, $period) = @_; my $ua = create_ua(); my $url = "$ZABBIX_SERVER/chart2.php?graphid=$graphid&period=$period&isNow=1&width=" . IMAGE_WIDTH; my $req = HTTP::Request->new('POST' => $url); $req->content_type('image/png'); $req->header('Cookie' => "tab=0; zbx_sessionid=$ZABBIX_AUTH_ID"); my $res = $ua->request($req); my $tmp = substr($res->content, 1, 4); #The first eight bytes of a PNG file always contain the following values: #(decimal) 137 80 78 71 13 10 26 10 #(hexadecimal) 89 50 4e 47 0d 0a 1a 0a #(ASCII C notation) \211 P N G \r \n \032 \n #https://www.w3.org/TR/PNG-Rationale.html#R.PNG-file-signature if ($tmp =~ m/PNG/) { return $res->content; } return; } ... sub send_email { my ($email_body, $subject, $smtp, $email_from, $email_to) = @_; my $msg = MIME::Lite->new( From => $email_from, To => $email_to, Subject => $subject, Type => 'multipart/related' ); $msg->attach(Type => 'text/html', Data => $email_body); $msg->attach(Type => 'image/png', Filename => 'graph.png', Id => 'graph.png', Data => $DATA_GRAPH) if defined($DATA_GRAPH); $msg->attach(Type => 'image/png', Filename => 'logo.png', Id => 'logo.png', Data => decode_base64($LOGO)); $msg->replace('X-Mailer' => 'Zabbix'); $msg->add('X-Priority' => $PRIORITY{'Highest'}); $msg->send('smtp', $smtp, Debug => $DEBUG); } |
Comment by Dimitri Bellini [ 2019 Feb 04 ] |
@Alexander: Your solution is based on the old graphs or for the new vector graphs? |
Comment by Alexander Nesterov [ 2019 Feb 04 ] |
for the old (classic) graphs |
Comment by Dimitri Bellini [ 2019 Feb 04 ] |
@Alexander: Ok Thanks @ZabbixTeam: I will suggest to bring this improvement (RestAPI for Graphs) as soon as possible with the new Vector Graphs thanks |
Comment by Alexander Nesterov [ 2019 Feb 04 ] |
@Dimitri: You can also use http request, I think so |
Comment by Dimitri Bellini [ 2019 Feb 05 ] |
@Alexander: Yes! We have create a simple reporting tool for Zabbix and at the monent is based with the old graphs style... |
Comment by Mark Oudsen [ 2021 Mar 03 ] |
As this request is running for a very long time, I've decided to code and release a beta version of a Media type that is capable of presenting a graph embedded in an e-mail message while adding TWIG template facilities to allow for some nice customization of the outgoing message (including IF statements for example) and adding some smart way finding the direct or indirectly associated graphs to a trigger (from API perspective). Note that Chart2 only has the capability to present 'Normal' graphs - I'm also working to support the other types as well (scattered across the other chartX.php). Have a look at: https://github.com/moudsen/mailGraph Once the API extension is there, my code will be fully API based (currently logging in to Zabbix to use chartX.php with CURL). Official request to Zabbix developers to add my Media type to their repository: |
Comment by Kolunchik [ 2021 Aug 19 ] |
any news? |
Comment by Mark Oudsen [ 2021 Aug 19 ] |
I have developed code to pick up graphs from Zabbix. Recently split the "get image" from my mail code and can make this available beginning of next month. |
Comment by Peter Danko [ 2022 Aug 05 ] |
Hi, Or when it will be natively added? |
Comment by Evgeny Semerikov [ 2023 Feb 20 ] |
This is nice feature, but why this is not implamented yet? image.get method have a nice solution for this which returning "image" attribute with base64 encoded image. |