2022 Zabbix中国峰会
2022 Zabbix中国峰会

获取

描述

integer/array alert.get(object parameters)

该方法允许根据给定的参数检索告警。

此方法适用于任何类型的用户。可以在用户角色设置中撤销调用此方法的权限。更多信息请参见用户角色

参数

(object) 定义所需输出的参数。

该方法支持以下参数。

参数 类型 描述
alertids ID/array 根据给定的 alertids 返回告警。
actionids ID/array 根据给定的动作返回告警。
eventids ID/array 根据给定的事件返回告警。
groupids ID/array 根据给定的主机组对象返回告警。
hostids ID/array 根据给定的主机对象返回告警。
mediatypeids ID/array 根据给定的媒体类型返回告警。
objectids ID/array 根据给定的对象返回告警
userids ID/array 根据给定的用户返回告警。
eventobject integer 根据给定的事件对象回告警。

请参阅事件object以获取支持的对象类型列表。

默认值:0 - 触发器。
eventsource integer 根据给定的事件来源返回告警。

请参阅事件source以获取支持的事件类型列表。

默认值:0 - 触发器事件。
time_from timestamp 根据给定的时间之后返回告警。
time_till timestamp 根据给定的时间之前返回告警。
selectHosts query 返回一个 hosts 属性,包含触发动作操作的主机数据。
selectMediatypes query 返回一个 mediatypes 属性,包含一个用于消息告警的媒体类型数组。
selectUsers query 返回一个 users 属性,包含一个消息指向的用户数组。
sortfield string/array 根据给定的属性对结果进行排序。

可能的值包括:alertidclockeventidmediatypeidsendtostatus
countOutput boolean 这些参数是所有 get 方法的通用参数,具体描述请参见 参考注释
editable boolean
excludeSearch boolean
filter object
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

返回值

(integer/array) 返回以下两者之一:

  • 一个对象数组;
  • 如果使用了countOutput参数,则返回检索到的对象的数量。

示例

根据动作ID检索告警

检索由动作"3"生成的所有告警。

请求:

{
           "jsonrpc": "2.0",
           "method": "alert.get",
           "params": {
               "output": "extend",
               "actionids": "3"
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "alertid": "1",
                   "actionid": "3",
                   "eventid": "21243",
                   "userid": "1",
                   "clock": "1362128008",
                   "mediatypeid": "1",
                   "sendto": "[email protected]",
                   "subject": "PROBLEM: Zabbix agent on Linux server is unreachable for 5 minutes: ",
                   "message": "Trigger: Zabbix agent on Linux server is unreachable for 5 minutes: \nTrigger status: PROBLEM\nTrigger severity: Not classified",
                   "status": "0",
                   "retries": "3",
                   "error": "",
                   "esc_step": "1",
                   "alerttype": "0",
                   "p_eventid": "0",
                   "acknowledgeid": "0"
               }
           ],
           "id": 1
       }

另请参阅

源码位置

CAlert::get() 在 ui/include/classes/api/services/CAlert.php 文件中。