Zabbix的trigger就是用來設置監控報警條件的,若是監控項目是基於模板的,那麼直接在建立模板的時候設置相應item的trigger便可,若是監控項目不是基於模板的而是單獨添加的,那麼對於多臺服務器添加相應的trigger就得使用程序處理了。
php
建立trigger相關的源代碼mysql
frontends/php/include/triggers.inc.phpsql
frontends/php/triggers.phpexpress
triggers表用於記錄每一個trigger的詳細信息
服務器
mysql> desc triggers; +-------------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+---------------------+------+-----+---------+-------+ | triggerid | bigint(20) unsigned | NO | PRI | NULL | | | expression | varchar(2048) | NO | | | | | description | varchar(255) | NO | | | | | url | varchar(255) | NO | | | | | status | int(11) | NO | MUL | 0 | | | value | int(11) | NO | MUL | 0 | | | priority | int(11) | NO | | 0 | | | lastchange | int(11) | NO | | 0 | | | comments | text | NO | | NULL | | | error | varchar(128) | NO | | | | | templateid | bigint(20) unsigned | YES | MUL | NULL | | | type | int(11) | NO | | 0 | | | state | int(11) | NO | | 0 | | | flags | int(11) | NO | | 0 | | +-------------+---------------------+------+-----+---------+-------+ 14 rows in set (0.12 sec)
functions表記錄每一個trigger相關的函數frontend
mysql> desc functions; +------------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------------+------+-----+---------+-------+ | functionid | bigint(20) unsigned | NO | PRI | NULL | | | itemid | bigint(20) unsigned | NO | MUL | NULL | | | triggerid | bigint(20) unsigned | NO | MUL | NULL | | | function | varchar(12) | NO | | | | | parameter | varchar(255) | NO | | 0 | | +------------+---------------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
trigger_depends表記錄不一樣trigger的依賴關係ide
mysql> desc trigger_depends; +----------------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+---------------------+------+-----+---------+-------+ | triggerdepid | bigint(20) unsigned | NO | PRI | NULL | | | triggerid_down | bigint(20) unsigned | NO | MUL | NULL | | | triggerid_up | bigint(20) unsigned | NO | MUL | NULL | | +----------------+---------------------+------+-----+---------+-------+ 3 rows in set (0.01 sec)
triggers表經過triggerid與functions表關聯,functions表經過itemid與items表關聯,而items表能夠經過hostid與hosts表關聯函數
根據triggerid查找trigger信息url
SELECT t.* FROM triggers t WHERE t.triggerid=13073;
根據triggerid查找hostsip
select distinct h.* from hosts h,functions f,items i where i.itemid=f.itemid and h.hostid=i.hostid and triggerid=13073\G
根據hostid查找全部的triggers
select distinct t.* from triggers t,functions f,items i where f.itemid=i.itemid and f.triggerid=t.triggerid and i.hostid=10309;
根據trigger描述和host名稱獲取全部的triggers
select t.* from triggers t,functions f,items i ,hosts h where i.hostid=h.hostid and f.itemid=i.itemid and t.triggerid=f.triggerid and h.host='tw-xxxxxx' and t.description='Processor load is too high on {HOST.NAME}' order by t.triggerid desc;