Sidebar

获取

描述

integer/array action.get(object parameters)

该方法允许根据给定的参数检索动作。

此方法对于任何用户可用。可以在用户角色设置中撤销调用该方法的权限。更多信息请查看 用户角色

参数

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

该方法支持以下参数。

参数 类型 描述
actionids string/array 只返回给定 ID 的动作。
groupids string/array 只返回使用动作条件指定主机组的动作。
hostids string/array 只返回使用动作条件指定主机的动作。
triggerids string/array 只返回使用动作条件指定触发器的动作。
mediatypeids string/array 只返回使用动作条件指定媒介类型的动作。
usrgrpids string/array 只返回配置为发送消息给指定用户组的动作。
userids string/array 只返回配置为发送消息给指定用户的动作。
scriptids string/array 只返回配置为运行指定脚本的动作。
selectFilter query 返回 filter 属性中的动作条件 filter。
selectOperations query 返回 operations 属性中的动作条件。
selectRecoveryOperations query 返回 recovery_operations 属性中的 动作恢复操作。
selectUpdateOperations query 返回 update_operations 属性中的动作更新操作。
sortfield string/array 根据给定的属性排序结果。

可用值:actionid, namestatus
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 参数,则检索对象的计数。

示例

检索触发器动作

检索所有已配置的触发器动作以及它们的动作条件和操作。

请求:

{
           "jsonrpc": "2.0",
           "method": "action.get",
           "params": {
               "output": "extend",
               "selectOperations": "extend",
               "selectRecoveryOperations": "extend",
               "selectUpdateOperations": "extend",
               "selectFilter": "extend",
               "filter": {
                   "eventsource": 0
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "actionid": "3",
                   "name": "Report problems to Zabbix administrators",
                   "eventsource": "0",
                   "status": "1",
                   "esc_period": "1h",
                   "pause_suppressed": "1",
                   "filter": {
                       "evaltype": "0",
                       "formula": "",
                       "conditions": [],
                       "eval_formula": ""
                   },
                   "operations": [
                       {
                           "operationid": "3",
                           "actionid": "3",
                           "operationtype": "0",
                           "esc_period": "0",
                           "esc_step_from": "1",
                           "esc_step_to": "1",
                           "evaltype": "0",
                           "opconditions": [],
                           "opmessage": [
                               {
                                   "default_msg": "1",
                                   "subject": "",
                                   "message": "",
                                   "mediatypeid" => "0"
                               }
                           ],
                           "opmessage_grp": [
                               {
                                   "usrgrpid": "7"
                               }
                           ]
                       }
                   ],
                   "recovery_operations": [
                       {
                           "operationid": "7",
                           "actionid": "3",
                           "operationtype": "11",
                           "evaltype": "0",
                           "opconditions": [],
                           "opmessage": {
                               "default_msg": "0",
                               "subject": "{TRIGGER.STATUS}: {TRIGGER.NAME}",
                               "message": "Trigger: {TRIGGER.NAME}\r\nTrigger status: {TRIGGER.STATUS}\r\nTrigger severity: {TRIGGER.SEVERITY}\r\nTrigger URL: {TRIGGER.URL}\r\n\r\nItem values:\r\n\r\n1. {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}\r\n2. {ITEM.NAME2} ({HOST.NAME2}:{ITEM.KEY2}): {ITEM.VALUE2}\r\n3. {ITEM.NAME3} ({HOST.NAME3}:{ITEM.KEY3}): {ITEM.VALUE3}\r\n\r\nOriginal event ID: {EVENT.ID}",
                               "mediatypeid": "0"
                           }
                       }
                   ],
                   "update_operations": [
                       {
                           "operationid": "31",
                           "operationtype": "12",
                           "evaltype": "0",
                           "opmessage": {
                               "default_msg": "1",
                               "subject": "",
                               "message": "",
                               "mediatypeid": "0"
                           }
                       },
                       {
                           "operationid": "32",
                           "operationtype": "0",
                           "evaltype": "0",
                           "opmessage": {
                               "default_msg": "0",
                               "subject": "Updated: {TRIGGER.NAME}",
                               "message": "{USER.FULLNAME} updated problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME} with the following message:\r\n{EVENT.UPDATE.MESSAGE}\r\n\r\nCurrent problem status is {EVENT.STATUS}",
                               "mediatypeid": "1"
                           },
                           "opmessage_grp": [
                               {
                                   "usrgrpid": "7"
                               }
                           ],
                           "opmessage_usr": []
                       },
                       {
                           "operationid": "33",
                           "operationtype": "1",
                           "evaltype": "0",
                           "opcommand": {
                               "scriptid": "3"
                           },
                           "opcommand_hst": [
                               {
                                   "hostid": "10084"
                               }
                           ],
                           "opcommand_grp": []
                       }
                   ]
               }
           ],
           "id": 1
       }

检索发现动作

检索所有已配置的发现动作以及它们的动作条件和操作。Filter 使用 "and" 计算类型,所以 formula 属性为空且eval_formula 将自动生成。

请求:

{
           "jsonrpc": "2.0",
           "method": "action.get",
           "params": {
               "output": "extend",
               "selectOperations": "extend"
               "selectFilter": "extend",
               "filter": {
                   "eventsource": 1
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "actionid": "2",
                   "name": "Auto discovery. Linux servers.",
                   "eventsource": "1",
                   "status": "1",
                   "esc_period": "0s",
                   "pause_suppressed": "1",
                   "filter": {
                       "evaltype": "0",
                       "formula": "",
                       "conditions": [
                           {
                               "conditiontype": "10",
                               "operator": "0",
                               "value": "0",
                               "value2": "",
                               "formulaid": "B"
                           },
                           {
                               "conditiontype": "8",
                               "operator": "0",
                               "value": "9",
                               "value2": "",
                               "formulaid": "C"
                           },
                           {
                               "conditiontype": "12",
                               "operator": "2",
                               "value": "Linux",
                               "value2": "",
                               "formulaid": "A"
                           }
                       ],
                       "eval_formula": "A and B and C"
                   },
                   "operations": [
                       {
                           "operationid": "1",
                           "actionid": "2",
                           "operationtype": "6",
                           "esc_period": "0s",
                           "esc_step_from": "1",
                           "esc_step_to": "1",
                           "evaltype": "0",
                           "opconditions": [],
                           "optemplate": [
                               {
                                   "templateid": "10001"
                               }
                           ]
                       },
                       {
                           "operationid": "2",
                           "actionid": "2",
                           "operationtype": "4",
                           "esc_period": "0s",
                           "esc_step_from": "1",
                           "esc_step_to": "1",
                           "evaltype": "0",
                           "opconditions": [],
                           "opgroup": [
                               {
                                   "groupid": "2"
                               }
                           ]
                       }
                   ]
               }
           ],
           "id": 1
       }

参见

来源

ui/include/classes/api/services/CAction.php 中的 CAction::get()。