Difference between revisions of "Zabbix sql queries"
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
delete from items where hostid=(select hostid from hosts where host='www.example.com'); | delete from items where hostid=(select hostid from hosts where host='www.example.com'); | ||
delete from items where hostid=(select hostid from hosts where host='www.example.com') and itemid!=252623 and itemid!=253055; | delete from items where hostid=(select hostid from hosts where host='www.example.com') and itemid!=252623 and itemid!=253055; | ||
+ | ``` | ||
+ | |||
+ | |||
+ | # Not sure if work | ||
+ | ``` | ||
+ | SELECT DISTINCT host, f.triggerid, e.acknowledged, priority | ||
+ | FROM triggers t | ||
+ | INNER JOIN functions f ON ( f.triggerid = t.triggerid ) | ||
+ | INNER JOIN items i ON ( i.itemid = f.itemid ) | ||
+ | INNER JOIN hosts ON ( i.hostid = hosts.hostid ) | ||
+ | INNER JOIN events e ON ( e.objectid = t.triggerid ) | ||
+ | WHERE (e.eventid / 100000000000000) | ||
+ | IN (0) | ||
+ | AND e.object = 0 | ||
+ | AND t.value=1 | ||
+ | AND hosts.status = 0 | ||
+ | AND i.status = 0 | ||
+ | AND t.status = 0 | ||
+ | AND e.acknowledged = 0 | ||
+ | AND e.clock > (SELECT DISTINCT max(e.clock) | ||
+ | FROM triggers t | ||
+ | INNER JOIN functions f ON ( f.triggerid = t.triggerid ) | ||
+ | INNER JOIN items i ON ( i.itemid = f.itemid ) | ||
+ | INNER JOIN hosts ON ( i.hostid = hosts.hostid ) | ||
+ | INNER JOIN events e ON ( e.objectid = t.triggerid ) | ||
+ | WHERE (e.eventid / 100000000000000) | ||
+ | IN (0) | ||
+ | AND e.object = 0 | ||
+ | AND t.value=1 | ||
+ | AND hosts.status = 0 | ||
+ | AND i.status = 0 | ||
+ | AND t.status = 0 | ||
+ | AND e.acknowledged = 1 | ||
+ | ) | ||
+ | LIMIT 1; | ||
+ | -- ORDER BY priority DESC; | ||
+ | ``` | ||
+ | |||
+ | |||
+ | # Cleanup | ||
+ | ``` | ||
+ | select items.itemid, items.hostid, items.name, hosts.name, hosts.hostid from items inner join hosts on items.hostid = hosts.hostid join hosts_groups on items.hostid = hosts_groups.hostid where items.name='Physical disks discovery' and hosts_groups.groupid=293; | ||
+ | |||
+ | delete from items where itemid IN (select items.itemid from items inner join hosts on items.hostid = hosts.hostid join hosts_groups on items.hostid = hosts_groups.hostid where items.name='Physical disks discovery' and hosts_groups.groupid=293); | ||
+ | delete from items where itemid IN (select items.itemid from items inner join hosts on items.hostid = hosts.hostid join hosts_groups on items.hostid = hosts_groups.hostid where items.name='Network interfaces discovery' and hosts_groups.groupid=293); | ||
+ | |||
+ | delete from items where name like '%{#IFNAME}%' and hostid in (select hostid from hosts_groups where groupid=293); | ||
+ | delete from items where name like '%{#DEVNAME}%' and hostid in (select hostid from hosts_groups where groupid=293); | ||
``` | ``` |
Latest revision as of 02:07, 25 July 2023
delete from items where hostid=(select hostid from hosts where host='www.example.com'); delete from items where hostid=(select hostid from hosts where host='www.example.com') and itemid!=252623 and itemid!=253055;
Not sure if work
SELECT DISTINCT host, f.triggerid, e.acknowledged, priority FROM triggers t INNER JOIN functions f ON ( f.triggerid = t.triggerid ) INNER JOIN items i ON ( i.itemid = f.itemid ) INNER JOIN hosts ON ( i.hostid = hosts.hostid ) INNER JOIN events e ON ( e.objectid = t.triggerid ) WHERE (e.eventid / 100000000000000) IN (0) AND e.object = 0 AND t.value=1 AND hosts.status = 0 AND i.status = 0 AND t.status = 0 AND e.acknowledged = 0 AND e.clock > (SELECT DISTINCT max(e.clock) FROM triggers t INNER JOIN functions f ON ( f.triggerid = t.triggerid ) INNER JOIN items i ON ( i.itemid = f.itemid ) INNER JOIN hosts ON ( i.hostid = hosts.hostid ) INNER JOIN events e ON ( e.objectid = t.triggerid ) WHERE (e.eventid / 100000000000000) IN (0) AND e.object = 0 AND t.value=1 AND hosts.status = 0 AND i.status = 0 AND t.status = 0 AND e.acknowledged = 1 ) LIMIT 1; -- ORDER BY priority DESC;
Cleanup
select items.itemid, items.hostid, items.name, hosts.name, hosts.hostid from items inner join hosts on items.hostid = hosts.hostid join hosts_groups on items.hostid = hosts_groups.hostid where items.name='Physical disks discovery' and hosts_groups.groupid=293; delete from items where itemid IN (select items.itemid from items inner join hosts on items.hostid = hosts.hostid join hosts_groups on items.hostid = hosts_groups.hostid where items.name='Physical disks discovery' and hosts_groups.groupid=293); delete from items where itemid IN (select items.itemid from items inner join hosts on items.hostid = hosts.hostid join hosts_groups on items.hostid = hosts_groups.hostid where items.name='Network interfaces discovery' and hosts_groups.groupid=293); delete from items where name like '%{#IFNAME}%' and hostid in (select hostid from hosts_groups where groupid=293); delete from items where name like '%{#DEVNAME}%' and hostid in (select hostid from hosts_groups where groupid=293);