[comment]: # ({2293b018-2293b018})
# 获取

[comment]: # ({/2293b018-2293b018})

[comment]: # ({4ef8f0ed-42834e1b})
### 描述

`integer/array action.get(object parameters)`

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

::: noteclassic
此方法对所有类型的用户都可用。可以在用户角色设置中撤销调用此方法的权限。更多信息请参阅[用户角色](/manual/web_interface/frontend_sections/users/user_roles)。
:::

[comment]: # ({/4ef8f0ed-42834e1b})

[comment]: # ({5a2121c5-f6c19c90})
### 参数

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

该方法支持以下参数。

|参数|[类型](/manual/api/reference_commentary#data-types)|描述|
|--|--|------|
|actionids|ID/array|仅返回具有给定 ID 的动作。|
|groupids|ID/array|仅返回在动作条件中使用给定主机组的动作。|
|hostids|ID/array|仅返回在动作条件中使用给定主机的动作。|
|triggerids|ID/array|仅返回在动作条件中使用给定触发器的动作。|
|mediatypeids|ID/array|仅返回使用给定媒介类型发送消息的动作。|
|usrgrpids|ID/array|仅返回配置为向给定用户组发送消息的动作。|
|userids|ID/array|仅返回配置为向给定用户发送消息的动作。|
|scriptids|ID/array|仅返回配置为运行给定脚本的动作。|
|selectFilter|query|返回包含动作条件过滤器的 [`filter`](/manual/api/reference/action/object#action-filter) 属性。|
|selectOperations|query|返回包含动作操作的 [`operations`](/manual/api/reference/action/object#action-operation) 属性。|
|selectRecoveryOperations|query|返回包含动作恢复操作的 [`recovery_operations`](/manual/api/reference/action/object#action-recovery-operation) 属性。|
|selectUpdateOperations|query|返回包含动作更新操作的 [`update_operations`](/manual/api/reference/action/object#action-update-operation) 属性。|
|sortfield|string/array|按给定属性对结果进行排序。<br><br>可选值：`actionid`、`name`、`status`。|
|countOutput|boolean|这些参数在[参考说明](/manual/api/reference_commentary#common-get-method-parameters)中进行了说明。|
|excludeSearch|boolean|^|
|filter|object|^|
|limit|integer|^|
|output|query|^|
|preservekeys|boolean|^|
|search|object|^|
|searchByAny|boolean|^|
|searchWildcardsEnabled|boolean|^|
|sortorder|string/array|^|
|startSearch|boolean|^|

[comment]: # ({/5a2121c5-f6c19c90})

[comment]: # ({7223bab1-7223bab1})
### 返回值

`(整数/数组)` 返回以下之一：

-   一个对象数组；
-   如果使用了`countOutput`参数，则返回检索到的对象数量。

[comment]: # ({/7223bab1-7223bab1})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({dabc835c-f7d2e806})
#### 检索触发器动作

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

[请求](/manual/api#performing-requests)：

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

响应：

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "actionid": "3",
            "name": "向 Zabbix 管理员报告问题",
            "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.NAME}\r\n触发器状态：{TRIGGER.STATUS}\r\n触发器严重性：{TRIGGER.SEVERITY}\r\n触发器 URL：{TRIGGER.URL}\r\n\r\n监控项值：\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\n原始事件 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": "已更新：{TRIGGER.NAME}",
                        "message": "{USER.FULLNAME} 于 {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME} 更新了问题，并附带以下消息：\r\n{EVENT.UPDATE.MESSAGE}\r\n\r\n当前问题状态为 {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
}
```

[comment]: # ({/dabc835c-f7d2e806})

[comment]: # ({931fc05d-d96da9cf})
#### 检索发现动作

从发现配置中检索动作，同时返回动作操作对象和动作过滤对象。该过滤使用“和”评估类型，因此`formula`属性为空，而`eval_formula`则自动生成。

[请求](/manual/api#执行请求):

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

响应:

```json
{
    "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
}
```

[comment]: # ({/931fc05d-d96da9cf})

[comment]: # ({7ab40057-755496f7})
### 另请参见

-   [动作过滤器](object#action-filter)
-   [动作操作](object#action-operation)

[comment]: # ({/7ab40057-755496f7})

[comment]: # ({025b824e-025b824e})
### 源码位置

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

[comment]: # ({/025b824e-025b824e})
