I have tried to integrate trends into my PDF report, and I believe I am querying the way I should, but it looks like trend.get ignores the time_from and time_till values and just return the value from one record instead.
For example, I have some hosts/gateways that have had some unscheduled downtime. Some of them a few days ago, but it I ask for trend data for say a week, it just says that no pings were ever lost.
If I have a host that is still down, I at least get a value that is not zero, but typically much higher than what the period it covers would lead to.
Example:Report from 2016.09.25 22:33 until 2016.10.02 22:33.
Ping loss is shown as 0%?!
Looking at the graph, it is clear that the actual ping loss in that period is 37.12%
If I manually query the trend database the way I would expect the API to, I get a value matches this pretty well:
mysql> select AVG(value_avg) AS trend_avg from trends WHERE itemid=52391 and clock BETWEEN 1474835627 and 1475440427; +-------------+ | trend_avg | +-------------+ | 37.11576826 | +-------------+ 1 row in set (0.00 sec)
Datapoints:
mysql> select clock,value_avg AS trend_avg from trends WHERE itemid=52391 and clock BETWEEN 1474835627 and 1475440427; +------------+-----------+ | clock | trend_avg | +------------+-----------+ | 1474837200 | 0.0000 | | 1474840800 | 0.0000 | | 1474844400 | 0.0000 | | 1474848000 | 0.0000 | | 1474851600 | 0.0000 | | 1474855200 | 0.0000 | | 1474858800 | 0.0000 | | 1474862400 | 0.0000 | | 1474866000 | 0.0000 | | 1474869600 | 0.0000 | | 1474873200 | 0.0000 | | 1474876800 | 0.0000 | | 1474880400 | 0.0000 | | 1474884000 | 0.0000 | | 1474887600 | 0.0000 | | 1474891200 | 0.0000 | | 1474894800 | 0.0000 | | 1474898400 | 0.0000 | | 1474902000 | 0.0000 | | 1474905600 | 0.0000 | | 1474909200 | 0.0000 | | 1474912800 | 0.0000 | | 1474916400 | 0.0000 | | 1474920000 | 0.0000 | | 1474923600 | 0.0000 | | 1474927200 | 0.0000 | | 1474930800 | 0.0000 | | 1474934400 | 0.0000 | | 1474938000 | 0.0000 | | 1474941600 | 0.0000 | | 1474945200 | 0.0000 | | 1474948800 | 0.0000 | | 1474952400 | 0.0000 | | 1474956000 | 0.0000 | | 1474959600 | 0.0000 | | 1474963200 | 0.0000 | | 1474966800 | 0.0000 | | 1474970400 | 0.0000 | | 1474974000 | 0.0000 | | 1474977600 | 0.0000 | | 1474981200 | 0.0000 | | 1474984800 | 0.0000 | | 1474988400 | 0.0000 | | 1474992000 | 0.0000 | | 1474995600 | 0.0000 | | 1474999200 | 0.0000 | | 1475002800 | 0.0000 | | 1475006400 | 0.0000 | | 1475010000 | 0.0000 | | 1475013600 | 0.0000 | | 1475017200 | 0.0000 | | 1475020800 | 0.0000 | | 1475024400 | 0.0000 | | 1475028000 | 0.0000 | | 1475031600 | 0.0000 | | 1475035200 | 0.0000 | | 1475038800 | 0.0000 | | 1475042400 | 0.0000 | | 1475046000 | 0.0000 | | 1475049600 | 0.0000 | | 1475053200 | 0.0000 | | 1475056800 | 0.0000 | | 1475060400 | 0.0000 | | 1475064000 | 0.0000 | | 1475067600 | 0.0000 | | 1475071200 | 0.0000 | | 1475074800 | 0.0000 | | 1475078400 | 0.0000 | | 1475082000 | 0.0000 | | 1475085600 | 0.0000 | | 1475089200 | 0.0000 | | 1475092800 | 0.0000 | | 1475096400 | 0.0000 | | 1475100000 | 0.0000 | | 1475103600 | 0.0000 | | 1475107200 | 0.0000 | | 1475110800 | 0.0000 | | 1475114400 | 0.0000 | | 1475118000 | 0.0000 | | 1475121600 | 0.0000 | | 1475125200 | 0.0000 | | 1475128800 | 0.0000 | | 1475132400 | 0.0000 | | 1475136000 | 0.0000 | | 1475139600 | 0.0000 | | 1475143200 | 0.0000 | | 1475146800 | 0.0000 | | 1475150400 | 0.0000 | | 1475154000 | 0.0000 | | 1475157600 | 0.0000 | | 1475161200 | 0.0000 | | 1475164800 | 0.0000 | | 1475168400 | 0.0000 | | 1475172000 | 0.0000 | | 1475175600 | 0.0000 | | 1475179200 | 0.0000 | | 1475182800 | 0.0000 | | 1475186400 | 0.0000 | | 1475190000 | 0.0000 | | 1475193600 | 0.0000 | | 1475197200 | 0.0000 | | 1475200800 | 0.0000 | | 1475204400 | 0.0000 | | 1475208000 | 0.0000 | | 1475211600 | 0.0000 | | 1475215200 | 98.3333 | | 1475218800 | 100.0000 | | 1475222400 | 100.0000 | | 1475226000 | 100.0000 | | 1475229600 | 100.0000 | | 1475233200 | 100.0000 | | 1475236800 | 100.0000 | | 1475240400 | 100.0000 | | 1475244000 | 100.0000 | | 1475247600 | 100.0000 | | 1475251200 | 100.0000 | | 1475254800 | 100.0000 | | 1475258400 | 100.0000 | | 1475262000 | 100.0000 | | 1475265600 | 100.0000 | | 1475269200 | 100.0000 | | 1475272800 | 100.0000 | | 1475276400 | 100.0000 | | 1475280000 | 100.0000 | | 1475283600 | 100.0000 | | 1475287200 | 100.0000 | | 1475290800 | 100.0000 | | 1475294400 | 100.0000 | | 1475298000 | 100.0000 | | 1475301600 | 100.0000 | | 1475305200 | 100.0000 | | 1475308800 | 100.0000 | | 1475312400 | 100.0000 | | 1475316000 | 100.0000 | | 1475319600 | 100.0000 | | 1475323200 | 100.0000 | | 1475326800 | 100.0000 | | 1475330400 | 100.0000 | | 1475334000 | 100.0000 | | 1475337600 | 100.0000 | | 1475341200 | 100.0000 | | 1475344800 | 100.0000 | | 1475348400 | 100.0000 | | 1475352000 | 100.0000 | | 1475355600 | 100.0000 | | 1475359200 | 100.0000 | | 1475362800 | 100.0000 | | 1475366400 | 100.0000 | | 1475370000 | 100.0000 | | 1475373600 | 100.0000 | | 1475377200 | 100.0000 | | 1475380800 | 100.0000 | | 1475384400 | 100.0000 | | 1475388000 | 100.0000 | | 1475391600 | 100.0000 | | 1475395200 | 100.0000 | | 1475398800 | 100.0000 | | 1475402400 | 100.0000 | | 1475406000 | 100.0000 | | 1475409600 | 100.0000 | | 1475413200 | 100.0000 | | 1475416800 | 100.0000 | | 1475420400 | 100.0000 | | 1475424000 | 100.0000 | | 1475427600 | 100.0000 | | 1475431200 | 100.0000 | | 1475434800 | 100.0000 | +------------+-----------+ 167 rows in set (0.00 sec)
What I see in my report (DEBUG stage):
Trend item search for: ICMP loss of type number
Array ( [0] => Array ( [itemid] => 52391 [name] => ICMP loss [key_] => icmppingloss [description] => [units] => % [lastclock] => 1475439806 [lastvalue] => 100.0000 ) )
Trend data for ICMP loss:
Array ( [0] => Array ( [itemid] => 52391 [num] => 60 [value_min] => 0.0000 [value_avg] => 0.0000 [value_max] => 0.0000 ) )
In this case, it looks like only the first value in the set is used.
I would expect that num would be SUM()'ed, value_min, MIN()'ed, value_avg AVG()'ed, and value_max MAX()'ed over the entire period and then returned.
This is tested on Zabbix 3.0.4. I expect it is also an issue in 3.2, but I have not had time to test it.
It does not look like 3.0.5 is available as a package for my CentOS base yet, but I doubt the issue is fixed, since the release notes make no mention of it.