获取

Description 说明

integer/array trigger.get(object **parameters**)

The method allows to retrieve triggers according to the given parameters. 此方法允许根据指定的参数检索触发器。

Parameters 参数

(object) Parameters defining the desired output. (object)定义需要输出的参数。 The method supports the following parameters. 该方法支持以下参数。

Parameter 参数Type 类型Description 说明
triggeridsstring/array 字符串/数组Return only triggers with the given IDs. 仅返回指定ID的触发器。
groupidsstring/array 字符串/数组Return only triggers that belong to hosts from the given host groups. 仅返回来自指定主机组中所属主机的触发器。
templateidsstring/array 字符串/数组Return only triggers that belong to the given templates. 仅返回指定模板所属的触发器。
hostidsstring/array 字符串/数组Return only triggers that belong to the given hosts. 仅返回指定主机所属的触发器。
itemidsstring/array 字符串/数组Return only triggers that contain the given items. 仅返回包含指定监控项的触发器。
applicationidsstring/array 字符串/数组Return only triggers that contain items from the given applications. 仅返回来自指定应用集中包含监控项的触发器。
functionsstring/array 字符串/数组Return only triggers that use the given functions. 仅返回使用指定函数的触发器。

Refer to the supported trigger functions page for a list of supported functions. 有关支持的功能列表,请参阅supported trigger functions页面。
groupstring 字符串Return only triggers that belong to hosts from the host group with the given name. 仅返回来自指定名称的主机组中所属主机的触发器。
hoststring 字符串Return only triggers that belong to host with the given name. 仅返回指定名称的所属主机的触发器。
inheritedboolean 布尔值If set to true return only triggers inherited from a template. 仅返回从模板继承的触发器,如果设置为true
templatedboolean 布尔值If set to true return only triggers that belong to templates. 仅返回所属模板的触发器,如果设置为true
monitoredflag 标记Return only enabled triggers that belong to monitored hosts and contain only enabled items. 仅返回所属被监控主机的已启用触发器,并包含已启用的监控项。
activeflag 标记Return only enabled triggers that belong to monitored hosts. 仅返回所属被监控主机的已启用触发器。
maintenanceboolean 布尔值If set to true return only enabled triggers that belong to hosts in maintenance. 仅返回在维护中所属主机的已启用触发器,如果设置为true
withUnacknowledgedEventsflag 标记Return only triggers that have unacknowledged events. 仅返回事件未确认的触发器。
withAcknowledgedEventsflag 标记Return only triggers with all events acknowledged. 仅返回所有事件已确认的触发器。
withLastEventUnacknowledgedflag 标记Return only triggers with the last event unacknowledged. 仅返回最后一个未确认事件的触发器。
skipDependentflag 标记Skip triggers in a problem state that are dependent on other triggers. 依赖其他触发器的触发器处在故障状态时就跳过。Note that the other triggers are ignored if disabled, have disabled items or disabled item hosts. 请注意,如果依赖触发器被禁用,或监控项被禁用,或监控项主机被禁用,那么触发将被忽略。
lastChangeSincetimestamp 时间戳Return only triggers that have changed their state after the given time. 仅返回指定时间之后变更状态的触发器。
lastChangeTilltimestamp 时间戳Return only triggers that have changed their state before the given time. 仅返回指定时间之前变更状态的触发器。
only_trueflag 标记Return only triggers that have recently been in a problem state. 仅返回最近处于故障状态的触发器。
min_severityinteger 整数型Return only triggers with severity greater or equal than the given severity. 仅返回严重级别大于或等于指定严重级别的触发器。
expandCommentflag 标记Expand macros in the trigger description. 展开触发器描述中的宏。
expandDescriptionflag 标记Expand macros in the name of the trigger. 展开触发器名称中的宏。
expandExpressionflag 标记Expand functions and macros in the trigger expression. 展开在触发器表达式中的函数和宏。
selectGroupsquery 查询Return the host groups that the trigger belongs to in the groups property. 返回在groups属性中触发器所属的主机组。
selectHostsquery 查询Return the hosts that the trigger belongs to in the hosts property. 返回在hosts属性中触发器所属的主机。
selectItemsquery 查询Return items contained by the trigger in the items property. 返回在items属性中触发器所包含的监控项。
selectFunctionsquery 查询Return functions used in the trigger in the functions property. 返回在functions属性中在触发器中使用的函数。

The function objects represents the functions used in the trigger expression and has the following properties: 函数对象代表使用在触发器表达式中的函数,并具有以下属性:
functionid - (string 字符串) ID of the function; 函数的ID;
itemid - (string 字符串) ID of the item used in the function; 使用在函数中的监控项ID。
function - (string 字符串) name of the function; 函数的名称;
parameter - (string 字符串) parameter passed to the function. 传递给函数的参数。
selectDependenciesquery 查询Return triggers that the trigger depends on in the dependencies property. 返回在dependencies属性中依赖触发的触发器。
selectDiscoveryRulequery 查询Return the low-level discovery rule that created the trigger. 返回创建了触发器的低级别发现规则。
selectLastEventquery 查询Return the last significant trigger event in the lastEvent property. 返回在lastEvent属性中最后一个重要触发事件。
selectTagsquery 查询Return the trigger tags in tags property. 返回在tags属性中触发器标签。
selectTriggerDiscoveryquery 查询Return the trigger discovery object in the triggerDiscovery property. 返回在triggerDiscovery属性中触发器发现对象。The trigger discovery objects links the trigger to a trigger prototype from which it was created. 触发器发现对象将触发器链接到创建它的触发器原型上。

It has the following properties: 触发器发现对象具有以下属性:
parent_triggerid - (string 字符串) ID of the trigger prototype from which the trigger has been created. 创建触发器的触发器原型ID。
filterobject 对象Return only those results that exactly match the given filter. 仅返回与指定筛选完全匹配的结果。

Accepts an array, where the keys are property names, and the values are either a single value or an array of values to match against. 接受一个数组,其中键为属性名称,值为单个值或要匹配值的数组。

Supports additional filters: 支持额外的筛选:
host - technical name of the host that the trigger belongs to; 触发器所属主机的正式名称。
hostid - ID of the host that the trigger belongs to. 触发器所属主机的ID。
limitSelectsinteger 整数型Limits the number of records returned by subselects. 限制子查询返回的记录数量。

Applies to the following subselects: 适用于以下子查询:
selectHosts - results will be sorted by host. 以host分类结果。
sortfieldstring/array 字符串/数组Sort the result by the given properties. 由指定属性分类结果。

Possible values are: triggerid, description, status, priority, lastchange and hostname. 许可值为:triggerid, description, status, priority, lastchangehostname
countOutputboolean 布尔值These parameters being common for all get methods are described in detail in the reference commentary page. 这些参数十分普遍,适用于所有get方法,详情可参考reference commentary
editableboolean 布尔值
excludeSearchboolean 布尔值
limitinteger 整数型
outputquery 查询
preservekeysboolean 布尔值
searchobject 对象
searchByAnyboolean 布尔值
searchWildcardsEnabledboolean 布尔值
sortorderstring/array 字符串/数组
startSearchboolean 布尔值

Return values 返回值

(integer/array) Returns either: 返回两者其中任一:

  • an array of objects; 一组对象;

  • the count of retrieved objects, if the countOutput parameter has been used. 如果已经使用了countOutput参数,则检索对象的计数。

Examples 范例

Retrieving data by trigger ID 根据触发器ID检索数据

Retrieve all data and the functions used in trigger “14062”. 检索触发器“14062”中使用的所有数据和功能。

Request 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "trigger.get",
  4. "params": {
  5. "triggerids": "14062",
  6. "output": "extend",
  7. "selectFunctions": "extend"
  8. },
  9. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  10. "id": 1
  11. }

Response 响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "functions": [
  6. {
  7. "functionid": "13513",
  8. "itemid": "24350",
  9. "function": "diff",
  10. "parameter": "0"
  11. }
  12. ],
  13. "triggerid": "14062",
  14. "expression": "{13513}>0",
  15. "description": "/etc/passwd has been changed on {HOST.NAME}",
  16. "url": "",
  17. "status": "0",
  18. "value": "0",
  19. "priority": "2",
  20. "lastchange": "0",
  21. "comments": "",
  22. "error": "",
  23. "templateid": "10016",
  24. "type": "0",
  25. "state": "0",
  26. "flags": "0",
  27. "recovery_mode": "0",
  28. "recovery_expression": "",
  29. "correlation_mode": "0",
  30. "correlation_tag": "",
  31. "manual_close": "0"
  32. }
  33. ],
  34. "id": 1
  35. }

Retrieving triggers in problem state 检索在故障状态的触发器

Retrieve the ID, name and severity of all triggers in problem state and sort them by severity in descending order. 检索在问题状态下的所有触发器的ID,名称和严重性,并按严重性级别按降序分类。

Request 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "trigger.get",
  4. "params": {
  5. "output": [
  6. "triggerid",
  7. "description",
  8. "priority"
  9. ],
  10. "filter": {
  11. "value": 1
  12. },
  13. "sortfield": "priority",
  14. "sortorder": "DESC"
  15. },
  16. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  17. "id": 1
  18. }

Response 响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "triggerid": "13907",
  6. "description": "Zabbix self-monitoring processes < 100% busy",
  7. "priority": "4"
  8. },
  9. {
  10. "triggerid": "13824",
  11. "description": "Zabbix discoverer processes more than 75% busy",
  12. "priority": "3"
  13. }
  14. ],
  15. "id": 1
  16. }

Retrieving a specific trigger with tags 使用标签检索特定的触发器

Retrieve a specific trigger with tags. 使用标签检索特定的触发器。

Request 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "trigger.get",
  4. "params": {
  5. "output": [
  6. "triggerid",
  7. "description"
  8. ],
  9. "selectTags": "extend",
  10. "triggerids": [
  11. "17578"
  12. ]
  13. },
  14. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  15. "id": 1
  16. }

Response 响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "triggerid": "17370",
  6. "description": "Service status",
  7. "tags": [
  8. {
  9. "tag": "service",
  10. "value": "{{ITEM.VALUE}.regsub(\"Service (.*) has stopped\", \"\\1\")}"
  11. },
  12. {
  13. "tag": "error",
  14. "value": ""
  15. }
  16. ]
  17. }
  18. ],
  19. "id": 1
  20. }

See also 参考

Source 源码

CTrigger::get() in frontends/php/include/classes/api/services/CTrigger.php. CTrigger::get()方法可在frontends/php/include/classes/api/services/CTrigger.php中参考。