Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Source code analysis of Zabbix trigger

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The trigger of Zabbix is used to set the monitoring alarm conditions. If the monitoring project is based on a template, you can directly set the trigger of the corresponding item when creating the template. If the monitoring project is not based on the template but added separately, then you have to use the program to add the corresponding trigger for multiple servers.

Create trigger-related source code

Frontends/php/include/triggers.inc.php

Frontends/php/triggers.php

The triggers table is used to record the details of each trigger

Mysql > desc triggers +-+ | Field | Type | Null | Key | Default | Extra | +-+- -+ | triggerid | bigint (20) unsigned | NO | PRI | NULL | | expression | varchar (2048) | NO | | description | varchar | NO | | url | varchar | | 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 | 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)

The functions table records the functions related to each trigger

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) |

The trigger_depends table records the dependencies of different trigger

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.01sec)

Triggers table is associated with functions table through triggerid, functions table is associated with items table through itemid, and items table can be associated with hosts table through hostid.

Find trigger information according to triggerid

SELECT t.* FROM triggers t WHERE t.triggerid=13073

Find hosts according to triggerid

Select distinct h.* from hosts hjime items I where i.itemid=f.itemid and h.hostid=i.hostid and triggerid=13073\ G

Find all triggers according to hostid

Select distinct t. * from triggers t where f.itemid=i.itemid and f.triggerid=t.triggerid and i.hostid=10309 I items

Get all triggers based on trigger description and host name

Select t. * from triggers t and t.description='Processor load is too high on and t.description='Processor load is too high on items I, hosts h where i.hostid=h.hostid and f.itemid=i.itemid and t.triggerid=f.triggerid and h. Hostwatch games xxxxxx 'and t.description='Processor load is too high on {HOST.NAME}' items I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report