Hi,
I need to extract historical data from events along with their closing time (durration time) for a given host_group and selected tag. I wrote a SQL query, that pulls all the data, for me but I can't calculate the durration time against the e.clock column.
I know, I should do diffdate on e.clock if e.value changes from 1 to 0 then subtract e.clock for r_eventid - eclock for source eventid.
I tried to use API but also don't know how to calculate durration time for resolved event.
How zabbix calculates the duration time for resolved event?
Does anyone know how to modify my query to get 3 additional column: start problem time, resolve problem time and duration time?
For workaround problem, I use GUI: Problems-> History-> Export to csv (button) but I want to automate this task. Can I somehow schedule this export?
I need to extract historical data from events along with their closing time (durration time) for a given host_group and selected tag. I wrote a SQL query, that pulls all the data, for me but I can't calculate the durration time against the e.clock column.
I know, I should do diffdate on e.clock if e.value changes from 1 to 0 then subtract e.clock for r_eventid - eclock for source eventid.
I tried to use API but also don't know how to calculate durration time for resolved event.
How zabbix calculates the duration time for resolved event?
Does anyone know how to modify my query to get 3 additional column: start problem time, resolve problem time and duration time?
For workaround problem, I use GUI: Problems-> History-> Export to csv (button) but I want to automate this task. Can I somehow schedule this export?
Code:
select h.hostid, i.itemid, i.NAME AS iname, f.triggerid, FROM_UNIXTIME(e.clock)AS eclock, e.eventid, e.objectid, e.VALUE, er1.r_eventid
#h.NAME, a.subject, FROM_UNIXTIME(a.clock) AS aclock
from hosts h join items i on i.hostid = h.hostid
join functions f on f.itemid = i.itemid
join events e on e.objectid = f.triggerid
join triggers t on f.triggerid = t.triggerid
join hosts_groups hg On h.hostid = hg.hostid
JOIN item_tag it ON i.itemid = it.itemid
left JOIN alerts a ON a.eventid = e.eventid
left JOIN event_recovery er1 ON e.eventid=er1.eventid
WHERE
e.clock > UNIX_TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL 6 MONTH)) AND
hg.groupid = 252 AND
it.value IN ('ICMP', 'Zabbix agent') AND
i.NAME IN ('Agent ping', 'ICMP ping') AND
e.value in ('0','1')
#AND a.eventid = e.eventid
order BY
e.clock DESC
LIMIT 200;
Comment