Professional Documents
Culture Documents
Zabbix DB-Reports 20100616.1
Zabbix DB-Reports 20100616.1
Information about the Zabbix Database – Version 1.8.1 – June, 2010 – by ChinaNetCloud
Sorry for format – this is printed from our Wiki
Hosts
The actual servers and devices
Status
• 0 - Active
• 1 - Disabled
• 3 - Template
/* Check for servers not in any group */
SELECT *
FROM hosts where status <> 3 /* Not template */ and not exists (select * from
hosts_groups where hosts.hostid = hosts_groups.hostid)
Items
TemplateId
• Points to parent ITEM, whose hostid points to the TEMPLATE
• So we know the parent item directly via template id and can compare/join to check for
differences
Types
• 0 = Agent
• 1 = ICMP ?
• 2=?
• 3 = Simple checks ?
• 4 = SNMP ?
• 5 = Zabbix internal ?
• 9 = Web checks
• 12 = IPMI ?
Status
• 0 = Active
• 1 = Disabled
• 3 = Error (error column has error)
mysql> select count(*), type from items group by type;
+----------+------+
| count(*) | type |
+----------+------+
| 41825 | 0 |
| 674 | 1 |
| 2421 | 2 |
| 18 | 3 |
| 4878 | 4 |
| 8 | 5 |
| 438 | 9 |
| 34 | 12 |
| 1 | 15 |
• Get active items for agents and active hosts, that have no template
select count(*) from items i join hosts h on i.hostid = h.hostid where i.status =
0 and h.status = 0 and i.templateid = 0 and i.type = 0;
• Get items whose Interval (delay), history, trends times do not match the item in their template
item
select i.itemid, h.host, t.host, ip.delay, i.delay, ip.history, i.history,
ip.trends, i.trends, i.description, i.key_
from hosts h join items i on h.hostid = i.hostid /* real host */
join items ip on i.templateid = ip.itemid /* items parent from template */
join hosts t on ip.hostid = t.hostid /* template */
where i.status = 0
and ip.status = 0
and i.type = 0 /* Agent item */
and h.status = 0 /* Active host */
and t.status = 3 /* Template */
and i.templateid <> 0 /* Item has a template */
and (i.delay <> ip.delay /* Mismatch with template */
or i.history <> ip.history
or i.trends <> i.trends)
• Get number of items for each Interval/delay, for active items and hosts
select count(*), delay
from items join hosts on items.hostid = hosts.hostid
where items.type = 0 and items.status = 0 and hosts.status = 0 group by delay;
Triggers
Status
0 - Active
1 - Disabled
URL
• URL - URL shown in UI
Error
• error - Error text, meaning unclear, as not tied to status
Type
• type - ? Always 0
• In theory this will show triggers that have 2+ hosts in their functions
select tz.triggerid, (select count(distinct h.hostid)
from triggers t1 join functions f on t1.triggerid = f.triggerid
join items i on f.itemid = i.itemid join hosts h on i.hostid = h.hostid
where t1.triggerid = tz.triggerid) cnt_diff_hosts
from triggers tz
where tz.status = 0
and tz.templateid <> 0
order by cnt_diff_hosts desc
limit 10
• Find triggers that don't match their parents from a template; only for single item expressions
right now
• All together, show main local trigger and templated trigger:
select t.triggerid, (select t2.triggerid
from triggers t2 join functions f2 on t2.triggerid = f2.triggerid
join items i2 on f2.itemid = i2.itemid join hosts h2 on i2.hostid = h2.hostid
where t.triggerid <> t2.triggerid /* Don't find self */
and (h.hostid = h2.hostid /* Match on hosts */
and i.itemid = i2.itemid) /* Match on items */
/* Differneces were are looking for */
/* Expression mismatch */
and (right(t.expression, length(t.expression) - INSTR(t.expression, '}') )
<> right(t2.expression, length(t2.expression) - INSTR(t2.expression, '}') )
OR /* Parameter mismatch - usually for time, # of samples, etc. */
f.parameter <> f2.parameter)
) trig2,
h.host, t.expression, f.function, f.parameter,
i.description, i.key_, t.description, i.itemid,t.status, h.status, t.templateid
from triggers t join functions f on t.triggerid = f.triggerid
join items i on f.itemid = i.itemid join hosts h on i.hostid = h.hostid
where
t.status = 0 /* Active */
and h.status = 0 /* For a host, not a template */
and t.templateid = 0 /* Not from template */
/* Can't have two } in expression; too complex */
and instr(right(t.expression, length(t.expression) - INSTR(t.expression, '}')),
'}') = 0
and exists
(select *
from triggers t2 join functions f2 on t2.triggerid = f2.triggerid
join items i2 on f2.itemid = i2.itemid join hosts h2 on i2.hostid = h2.hostid
where
t2.status = 1 /* Disabled, since it was cloned */
and t2.templateid <> 0 /* From a template */
/* Matches */
and (h.hostid = h2.hostid /* Match on hosts */
and i.itemid = i2.itemid) /* Match on items */
/* Differneces were are looking for */
/* Expression mismatch */
and (right(t.expression, length(t.expression) - INSTR(t.expression, '}') )
<> right(t2.expression, length(t2.expression) - INSTR(t2.expression, '}') )
• List all triggers without templates, so are connected to just one host
select t.triggerid, h.host, f.functionid, f.function, f.parameter, t.expression,
i.description, i.key_, t.description, i.itemid
from triggers t
join functions f on t.triggerid = f.triggerid
join items i on f.itemid = i.itemid
join hosts h on i.hostid = h.hostid
where t.status = 0
and t.templateid = 0 /* No template */
order by t.triggerid desc
Queue
• Query to check queue, mostly from queue.php
SELECT lastclock+delay-unix_timestamp() lag, from_unixtime(i.lastclock+i.delay)
nextcheck
,i.itemid, i.lastclock, i.description, i.key_, i.type, h.host, h.hostid,
h.proxy_hostid, i.delay, i.delay_flex
FROM items i JOIN hosts h on i.hostid=h.hostid
WHERE h.status=0
AND i.status=0
AND i.type=0
AND NOT i.lastclock IS NULL
AND from_unixtime(i.lastclock+i.delay+10) < now()
AND i.key_ <> 'status' AND key <> 'zabbix[log]' /* Skip these */
ORDER BY i.lastclock, h.host, i.description, i.key_
limit 100;