Skip to content

Instantly share code, notes, and snippets.

@v-zhuravlev
Last active June 12, 2023 12:46
Show Gist options
  • Save v-zhuravlev/7a216c7e5f42c3747acd98dd426a8f39 to your computer and use it in GitHub Desktop.
Save v-zhuravlev/7a216c7e5f42c3747acd98dd426a8f39 to your computer and use it in GitHub Desktop.
Zabbix SQL queries collection
select count(*) FROM (select distinct h.hostid, h.host, t.description from triggers t
join functions f on f.triggerid = t.triggerid
join items i on i.itemid = f.itemid
join hosts h on h.hostid = i.hostid
join hosts_groups hg on h.hostid = hg.hostid
join hstgrp hg2 on hg2.groupid = hg.groupid
where
-- value=1 - trigger is in problem state
t.value = 1 and
-- t.status=0 - trigger is enabled
t.status = 0 and
-- h.status=0 - host is enabled
h.status = 0
-- host name filter. Can be changed to hostid instead
and h.host = "somehost"
-- host group name filter
-- and hg2.name = "somegroupname"
-- optional severity filter where 0 - not classified, 1 - normal, 2 - warning, 3 - average, 4 - high, 5 - disaster
-- and t.priority > 3
-- optional extra filter on trigger description...
-- and t.description like '%Trigger name'
--
) as subq
select distinct h.hostid, h.host, t.description from triggers t
join functions f on f.triggerid = t.triggerid
join items i on i.itemid = f.itemid
join hosts h on h.hostid = i.hostid
join hosts_groups hg on h.hostid = hg.hostid
join hstgrp hg2 on hg2.groupid = hg.groupid
where
-- value=1 - trigger is in problem state
t.value = 1 and
-- t.status=0 - trigger is enabled
t.status = 0 and
-- h.status=0 - host is enabled
h.status = 0
-- host name filter. Can be changed to hostid instead
and h.host = "somehost"
-- host group name filter
-- and hg2.name = "somegroupname"
-- optional severity filter where 0 - not classified, 1 - normal, 2 - warning, 3 - average, 4 - high, 5 - disaster
-- and t.priority > 3
-- optional extra filter on trigger description...
-- and t.description like '%Trigger name'
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment