[ZBXNEXT-1193] Support of trends.get method for API Created: 2012 Apr 20  Updated: 2018 Jan 12  Resolved: 2016 Jan 19

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: API (A)
Affects Version/s: None
Fix Version/s: 3.0.0alpha5

Type: New Feature Request Priority: Minor
Reporter: Alexey Pustovalov Assignee: Unassigned
Resolution: Fixed Votes: 43
Labels: api, patch, trends
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File 0001-Initial-support-for-Trends-API.patch     Zip Archive CTrend_for_Zabbix_2_4_4.zip     File Initial-support-for-Trends-API-zbx-2.2.patch     File zbxNext1193-2.2.8.patch    
Issue Links:
Causes
causes ZBX-13325 Trend.get doesn't work properly for ... Closed
Duplicate
is duplicated by ZBXNEXT-1270 API to fetch history and/or trends gi... Open

 Description   

Zabbix API should support trends.get method like history.get.



 Comments   
Comment by Noah Leaman [ 2012 Jun 15 ]

I need this in order to create a custom dashboard. Related, but a different reqest would be to have an API call returns values from both history and/or trends based on the date range requested and what the retention settings are.

Comment by Łukasz Jernaś [ 2013 Jul 22 ]

Any ETA on this maybe?

Comment by richlv [ 2013 Jul 22 ]

it's currently not on the roadmap. there have been some discussions about financing such development, but nothing specific

Comment by D.Spindel Ljungmark [ 2013 Oct 08 ]

This is a patch against Zabbix 2.0.8 PHP frontend that implements trends API.

CTrends.php is originally a copy of CHistory.php.

trends API retains the same API as history.

cp CHistory.php CTrends.php
git apply 0001-Initial-support-for-Trends-API.patch

Comment by A B [ 2014 Feb 20 ]

Updated patch for zabbix 2.2.2.

Comment by Mattias Geniar [ 2014 Aug 07 ]

Both patches in this issue are confirmed to be working. Would there be any reason not to implement them?

Comment by Alexei Vladishev [ 2015 Feb 11 ]

It will be implemented on Zabbix Server side, depends on ZBXNEXT-2519.

Comment by Yannick Moussette [ 2015 Feb 18 ]

I know that you guys are really busy, but does this have to wait on ZBXNEXT-2519? As it's only a new file added (doesn't break anything) and 3 new lines in API.php...?

That being said, no disrespect intended, we do appreciate all your hard work!

Comment by Marc [ 2015 Mar 01 ]

The file zbxNext1193-2.2.8.patch is a refactored version of Initial-support-for-Trends-API-zbx-2.2.patch.

Comment by jaseywang [ 2015 Mar 06 ]

trends.get api is quite useful for users to custom their own dashboard, now, We have to get trends from MySQL

Comment by Michel Marinho [ 2015 Apr 30 ]

This patch will work on Zabbix 2.4.x ? someone tried?

I do not have access to the mysql database .

Comment by Yannick Moussette [ 2015 Apr 30 ]

I have one that works with 2.4.4, the 2.2 patch hadn't worked for me, so I made the manual changes, partially based on what was in the Patch.

Interested?

G.

Comment by Michel Marinho [ 2015 Apr 30 ]

of course yes,

Could You send it to me ? I updated to 2.4.5 , and will test .

thank you

Comment by Yannick Moussette [ 2015 Apr 30 ]

CTrend_for_Zabbix_2_4_4.zip --> Frontend new CTrend.php, modified API.php and CApiServiceFactory, for Zabbix 2.4.4 "Trend API".

Comment by Yannick Moussette [ 2015 Apr 30 ]

Hi Michel,

here's a zip file (CTrend_for_Zabbix_2_4_4.zip) containing the 3 php files I modified under Zabbix 2.4.4 to have the "Trend" API implemented.

G.

Comment by Holger Gruber [ 2015 May 03 ]

Hi Yannick,

thanks for the patch, it's working fine for me. One thing:
the 2.2 patch provides trends.get() while yours provides trend.get().
As my project https://github.com/hgruber/zabbix-d3js-widgets uses trends.get() I would appreciate some consistency.

Comment by Yannick Moussette [ 2015 May 03 ]

Hi Holger,

Well, considering that all the Zabbix API Classes are in singular format (host.get, hostgroup.get, history.get) and not plural, it made sense to me to follow the Zabbix SIA standard and name it "trend.get" instead of "trends.get"...

However, since you have access to the modifications I uploaded, you can go ahead and change it to trends.get if you'd like, that's what Open source is all about.

Please note that I'm not in any way part of the Zabbix SIA company, and that the patch I provided here is the one I use at my company for Zabbix 2.4.4, and shared here to help a fellow Zabbix User.

G.

Comment by Marc [ 2015 May 03 ]

Considering the fact that the corresponding database table holds trends (min/max/avg) per item, the plural form sounds valid to me:

zabbix=# \x
Expanded display is on.
zabbix=# SELECT * FROM trends LIMIT 1;
-[ RECORD 1 ]---------
itemid    | 616279
clock     | 1398873600
num       | 4
value_min | 781.0000
value_avg | 12338.7500
value_max | 16440.0000

zabbix=#

Edit:
Well, min/max/avg are actually no trends.by themselves. Anyway, since the table and everywhere else the term "trends" is used, I'd still vote for the plural form.
Nevertheless, thanks a lot for porting the patch to 2.4!

Comment by Yannick Moussette [ 2015 May 03 ]

Hi Marc,

well, the "item_s_" table has a singular "host.get" API call, so does the "hosts" table, "groups" table, and the API calls are all singular...

In any case, the main point is that there is now a "workaround", and that if the naming of the API items doesn't match your requirements, you can make the changes you need.

Ultimately, this naming convention will be resolved when the guys from Zabbix SIA come up with the official Trend(s) API.

Have a nice day!

G.

Comment by Diwahar [ 2015 May 28 ]

Hi all,

Can anyone provide an example for using "trends.get" api in zabbix?

Thanks for the help.

Comment by Marc [ 2015 May 28 ]

Actually the same way as history.get().

Comment by John Green [ 2015 Jun 16 ]

In the comment above by D.Spindel Ljungmark, there is a reference to Zabbix 2.0.8 PHP frontend and the CHistory.php in that version. Where can I find that source code, or alternatively, is it possible to get a final version of the CTrends.php file rather than patches, please?

Update: On reviewing the attachment, zbxNext1193-2.2.8.patch, I found that it describes the final CTrends.php file and the change needed to API.php, and they compare well with the version I'm testing against which is 2.2.2, so I no longer require the final files. I have also installed and tested the changes and they work. I thought I'd leave this post to help anyone else struggling to work out what to use.

Comment by julian [ 2015 Nov 09 ]

Hi all,

Im using the PhpZabbixApi https://github.com/confirm/PhpZabbixApi library to use the API with PHP, now I need to get trends from the Api
so installed the CTrend Patch. At the moment it isn't working, I don't know how to add the trend to
the PHPApi Library can someone help me?

Comment by Jim Druce [ 2015 Nov 11 ]

I know this is going to sound like a stupid question, but i'm running Zabbix 2.2.7 and would like to install this patch... I'm just not quite clear on how.. Do i put in the Zabbix_2.4.4 files i'm assuming not as i'm not on that version unless they are backward compatible... Can anyone give me some simple pointers... I'm trying to get Trend data through Grafana and get all the other bits other than this element...

Comment by Yannick Moussette [ 2015 Nov 15 ]

Hi Jim,

before making any changes, make sure you take a good backup of the "/usr/share/zabbix" directory (where the web/php/api files reside).
tar cvfz ~/zabbix_www_backup.20151114.tar.gz /usr/share/zabbix

next, download the zbxNext1193-2.2.8.patch, copy it to the /usr/share/zabbix directory, and apply the patch as follows:

"patch -p0 < zbxNext1193-2.2.8.patch"

This should make the necessary modifications to your files, and exposed a new Trend API.

Notes: 1- the patch mentioned above is for 2.2.8. Might work for 2.2.7 as is, hence the backup procedure.
2- you probably need to use "sudo" with the above commands, since the default package installation have the files belonging to root:root.

I've set up a quick, 2.2.10 environment to test the above (can't download 2.2.7 anymore), but hopefully this should work.

Good Luck!

G.

Comment by Jim Druce [ 2015 Nov 15 ]

Many thanks Yannick patch installed happily... and both files updated ok...

Strangely now getting this error when enabling trends in Grafana in the graphs... I'm assuming i might need to upgrade the Zabbix environment to 2.2.8 as a minimum...

Message:
Cannot read property 'itemid' of undefined

Stack trace:
TypeError: Cannot read property 'itemid' of undefined

Comment by Ivo Kurzemnieks [ 2015 Nov 24 ]

Specification

Comment by Ivo Kurzemnieks [ 2015 Nov 24 ]

RESOLVED in svn://svn.zabbix.com/branches/dev/ZBXNEXT-1193

Comment by Daniel Nhoque Ruffato [ 2015 Dec 07 ]

Hi Yannick, please, could make the file available to me? I did not find for download ..

Thank you!

Comment by Yannick Moussette [ 2015 Dec 07 ]

Hi Daniel,

the files are at the top of this ZBXNEXT request, in the "Attachments" section.

G.

Comment by Daniel Nhoque Ruffato [ 2015 Dec 07 ]

Thank you for quick response and work! Found the files ... Now I must put them in the / usr / share / zabbix / include / classes / api #?

Comment by Yannick Moussette [ 2015 Dec 07 ]

I'm guessing you're installing for Zabbix 2.4.4? If so, replace the files with the ones in the 2.4.4 zip file, only the CTrend.php file is new, and must be put in the same directory as CItem.php.

As always, it's good practice to keep a backup/copy of the original files you will be replacing, just in case.

G.

Comment by Alexander Vladishev [ 2015 Dec 09 ]

Successfully tested! Take a look at my changes in r57101.

Comment by Ivo Kurzemnieks [ 2015 Dec 09 ]

(1) No translation string changes.

sasha CLOSED

Comment by Ivo Kurzemnieks [ 2015 Dec 09 ]

(2) As of r57101 when no parameters are given, no values are returned.

sasha RESOLVED in r57112

iivs Thanks!
CLOSED

Comment by Ivo Kurzemnieks [ 2015 Dec 09 ]

Implemented in pre-3.0.0alpha5 (trunk) r57114

Comment by Ivo Kurzemnieks [ 2015 Dec 09 ]

(3) API documentation updated:

sasha CLOSED

glebs.ivanovskis Line "Return 10 latest values received from a numeric(float) item." here looks suspicious.

sasha Thanks! I've removed the sentence. CLOSED

Comment by Alexander Vladishev [ 2015 Dec 22 ]

(4) Documentation:

sasha RESOLVED

martins-v Reviewed. CLOSED.

Comment by clems94 [ 2015 Dec 29 ]

Hi all

I installed the patch but i can not see the trends via Grafana 2.5.0.

Could you help me ?

Comment by Andrei Gushchin (Inactive) [ 2018 Jan 12 ]

This implementation doesn't work with Oracle DB backend, reported in ZBX-13325

Generated at Thu Mar 28 21:33:43 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.