我想通过2监控系统创建事件的自定义报告。
我知道Zabbix API,但请想一想 如果我通过API请求数据,那么如果我直接对数据库Zabbix执行查询,性能将不会相同。
我找到了一张包含事件信息的表格,
SELECT eventid, source, object, objectid, clock, value, acknowledged, ns
FROM zabbix.events
找到zabbix.hosts和zabbix.host_inventory。
zabbix.events
如何与zabbix.hosts
相关联?
答案 0 :(得分:1)
objectid
触发事件(source=0
)是触发器ID,后者又具有功能ID,而功能ID又具有项ID,而ID又具有主机ID。
答案 1 :(得分:1)
您可以在Zabbix分享上查看此链接: https://share.zabbix.com/databases/mysql/zabbix-database-model
Alain为每个新版本都快速更新它,如果你想做一些SQL查询,这是必须的。
答案 2 :(得分:0)
数据库架构未正式记录,但您可能会找到一些社区资源 - http://zabbix.org/wiki/Database_Schemas。请记住2.4.3版本。这可能足以为你的案件寻找关系。
答案 3 :(得分:0)
信息确实在这个选择中合并:
SELECT * FROM events
JOIN triggers ON events.objectid = triggers.triggerid
JOIN functions ON functions.triggerid = triggers.triggerid
JOIN items ON items.itemid = functions.itemid
JOIN hosts ON items.hostid = hosts.hostid
WHERE events.source = 0
AND
LOWER(hosts.host) like 'mysql%'
AND events.clock>=unix_timestamp('2017-09-25 09:55:00')
AND events.clock<=unix_timestamp('2017-09-25 11:00:00')
ORDER BY events.clock DESC
;
答案 4 :(得分:0)
这是我创建的针对zabbix db运行的查询。它加入主机和主机组,然后离开加入已确认或未确认的事件。一旦事件得到解决,它将放弃此查询。它用于启用或无法访问的主机。
select
h.name as hostname,
h.status as hoststatus,
g.name as groupname,
hi.alias as hostalias,
hi.location as hostlocation,
hi.os as hostos,
dt.idescription as itemdescription,
dt.ikey as itemkey_,
dt.iname as itemname,
dt.hsurl as httpstepurl,
dt.hsname as httpstepname,
dt.tcomments as triggercomments,
dt.tdescription as triggerdescription,
dt.tpriority as triggerpriority,
dt.eventclock as eventclock,
dt.eacknowledged as eventacknowledged
from
hosts h
inner join hosts_groups hg on h.hostid=hg.hostid
inner join groups g on hg.groupid = g.groupid
left join host_inventory hi on h.hostid=hi.hostid
LEFT JOIN
(SELECT
i.hostid as ihostid,
i.itemid as iitemid,
i.description as idescription,
i.key_ as ikey,
i.name as iname,
hs.url as hsurl,
hs.name as hsname,
t.description as tdescription,
t.url as turl,
t.comments as tcomments,
t.priority as tpriority,
from_unixtime(e.clock) as eventclock,
e.acknowledged as eacknowledged
from items i
left join functions f on i.itemid = f.itemid
left join triggers t on f.triggerid = t.triggerid
right join events e on t.triggerid = e.objectid
left join httpstepitem hsi on i.itemid = hsi.itemid
left join httpstep hs on hsi.httpstepid = hs.httpstepid
inner join problem p on e.eventid = p.eventid
WHERE
((e.acknowledged='0' AND i.status='0' AND r_clock='0') OR (e.acknowledged='1' AND i.status='0' AND r_clock='0'))
) dt ON h.hostid = dt.ihostid
where (h.status='2' or h.status='0');