[comment]: # translation:outdated

[comment]: # ({cd91b3fe-cd91b3fe})
# script.get

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

[comment]: # ({ce6433f5-96ec37bc})
### 描述

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

该方法允许根据给定的参数检索脚本。

::: noteclassic
此方法可供任何类型的用户使用。调用该方法的权限可以在用户角色设置中撤销。更多信息请参见 [User
roles](/manual/web_interface/frontend_sections/users/user_roles)。
:::

[comment]: # ({/ce6433f5-96ec37bc})

[comment]: # ({05a6c0a9-c425a65a})
### 参数

`(object)` 用于定义期望输出的参数。

该方法支持以下参数。

| 参数 | [数据类型](/manual/api/reference_commentary#数据类型) | 描述 |
|--|--|------|
| groupids | ID/array | 仅返回可在给定的主机组上run的脚本。 |
| hostids | ID/array | 仅返回可在给定的主机上run的脚本。 |
| scriptids | ID/array | 仅返回具有给定ID的脚本。 |
| usrgrpids | ID/array | 仅返回可被指定用户组中的用户run的脚本。 |
| selectHostGroups | query | 返回一个包含脚本可被run的主机组的[`hostgroups`](/manual/api/reference/hostgroup/object)属性。 |
| selectHosts | query | 返回一个包含脚本可被run的主机的[`hosts`](/manual/api/reference/host/object)属性。 |
| selectActions | query | 返回一个包含脚本关联动作的[`actions`](/manual/api/reference/action/object)属性。 |
| sortfield | string/array | 按照给定属性对结果进行排序。<br><br>可能的值：`scriptid`、`name`。 |
| countOutput | boolean | 这些参数在[通用get方法参数](/manual/api/reference_commentary#通用get方法参数)中进行了描述。 |
| editable | boolean | ^           |
| excludeSearch | boolean | ^           |
| filter | object | ^           |
| limit | integer | ^           |
| output | query | ^           |
| preservekeys | boolean | ^           |
| search | object | ^           |
| searchByAny | boolean | ^           |
| searchWildcardsEnabled | boolean | ^           |
| sortorder | string/array | ^           |
| startSearch | boolean | ^           |
| selectGroups<br>(deprecated) | query | 此参数已弃用，请改用`selectHostGroups`。<br>返回一个包含脚本可被run的主机组的[`groups`](/manual/api/reference/hostgroup/object)属性。 |

[comment]: # ({/05a6c0a9-c425a65a})

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

`(integer/array)` 返回以下之一：

-   objects 的 array；
-   如果使用了 `countOutput` 参数，则为检索到的 objects 的数量。

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

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

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

[comment]: # ({04ad24fc-6d428f32})
#### 检索所有脚本

获取所有已配置的脚本。

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

```json
{
    "jsonrpc": "2.0",
    "method": "script.get",
    "params": {
        "output": "extend"
    },
    "id": 1
}
```
响应：

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "scriptid": "1",
            "name": "Ping",
            "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
            "host_access": "2",
            "usrgrpid": "0",
            "groupid": "0",
            "description": "",
            "confirmation": "",
            "type": "0",
            "execute_on": "1",
            "timeout": "30s",
            "scope": "2",
            "port": "",
            "authtype": "0",
            "username": "",
            "password": "",
            "publickey": "",
            "privatekey": "",
            "menu_path": "",
            "url": "",
            "new_window": "1",
            "manualinput": "0",
            "manualinput_prompt": "",
            "manualinput_validator": "",
            "manualinput_validator_type": "0",
            "manualinput_default_value": "",
            "parameters": []
        },
        {
            "scriptid": "2",
            "name": "Traceroute",
            "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
            "host_access": "2",
            "usrgrpid": "0",
            "groupid": "0",
            "description": "",
            "confirmation": "",
            "type": "0",
            "execute_on": "1",
            "timeout": "30s",
            "scope": "2",
            "port": "",
            "authtype": "0",
            "username": "",
            "password": "",
            "publickey": "",
            "privatekey": "",
            "menu_path": "",
            "url": "",
            "new_window": "1",
            "manualinput": "0",
            "manualinput_prompt": "",
            "manualinput_validator": "",
            "manualinput_validator_type": "0",
            "manualinput_default_value": "",
            "parameters": []
        },
        {
            "scriptid": "3",
            "name": "Detect operating system",
            "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
            "host_access": "2",
            "usrgrpid": "7",
            "groupid": "0",
            "description": "",
            "confirmation": "",
            "type": "0",
            "execute_on": "1",
            "timeout": "30s",
            "scope": "2",
            "port": "",
            "authtype": "0",
            "username": "",
            "password": "",
            "publickey": "",
            "privatekey": "",
            "menu_path": "",
            "url": "",
            "new_window": "1",
            "manualinput": "0",
            "manualinput_prompt": "",
            "manualinput_validator": "",
            "manualinput_validator_type": "0",
            "manualinput_default_value": "",
            "parameters": []
        },
        {
            "scriptid": "4",
            "name": "Webhook",
            "command": "try {\n var request = new HttpRequest(),\n response,\n data;\n\n request.addHeader('Content-Type: application/json');\n\n response = request.post('https://localhost/post', value);\n\n try {\n response = JSON.parse(response);\n }\n catch (error) {\n response = null;\n }\n\n if (request.getStatus() !== 200 || !('data' in response)) {\n throw 'Unexpected response.';\n }\n\n data = JSON.stringify(response.data);\n\n Zabbix.log(3, '[Webhook Script] response data: ' + data);\n\n return data;\n}\ncatch (error) {\n Zabbix.log(3, '[Webhook Script] script execution failed: ' + error);\n throw 'Execution failed: ' + error + '.';\n}",
            "host_access": "2",
            "usrgrpid": "7",
            "groupid": "0",
            "description": "",
            "confirmation": "",
            "type": "5",
            "execute_on": "1",
            "timeout": "30s",
            "scope": "2",
            "port": "",
            "authtype": "0",
            "username": "",
            "password": "",
            "publickey": "",
            "privatekey": "",
            "menu_path": "",
            "url": "",
            "new_window": "1",
            "manualinput": "0",
            "manualinput_prompt": "",
            "manualinput_validator": "",
            "manualinput_validator_type": "0",
            "manualinput_default_value": "",
            "parameters": [
                {
                    "name": "token",
                    "value": "{$WEBHOOK.TOKEN}"
                },
                {
                    "name": "host",
                    "value": "{HOST.HOST}"
                },
                {
                    "name": "v",
                    "value": "2.2"
                }
            ]
        },
        {
            "scriptid": "5",
            "name": "URL",
            "command": "",
            "host_access": "2",
            "usrgrpid": "0",
            "groupid": "0",
            "description": "",
            "confirmation": "Go to {HOST.NAME}?",
            "type": "6",
            "execute_on": "1",
            "timeout": "30s",
            "scope": "4",
            "port": "",
            "authtype": "0",
            "username": "",
            "password": "",
            "publickey": "",
            "privatekey": "",
            "menu_path": "",
            "url": "http://zabbix/ui/zabbix.php?action=latest.view&hostids[]={HOST.ID}",
            "new_window": "0",
            "manualinput": "0",
            "manualinput_prompt": "",
            "manualinput_validator": "",
            "manualinput_validator_type": "0",
            "manualinput_default_value": "",
            "parameters": []
        },
        {
            "scriptid": "6",
            "name": "URL with user input",
            "command": "",
            "host_access": "2",
            "usrgrpid": "0",
            "groupid": "0",
            "description": "",
            "confirmation": "Open zabbix page {MANUALINPUT}?",
            "type": "6",
            "execute_on": "1",
            "timeout": "30s",
            "scope": "2",
            "port": "",
            "authtype": "0",
            "username": "",
            "password": "",
            "publickey": "",
            "privatekey": "",
            "menu_path": "",
            "url": "http://zabbix/ui/zabbix.php?action={MANUALINPUT}",
            "new_window": "0",
            "manualinput": "1",
            "manualinput_prompt": "Select a page to open:",
            "manualinput_validator": "dashboard.view,script.list,actionlog.list",
            "manualinput_validator_type": "1",
            "parameters": []
        }
    ],
    "id": 1
}
```

[comment]: # ({/04ad24fc-6d428f32})

[comment]: # ({b0b740ec-b0b740ec})
### 另请参阅

-   [主机-object](/manual/api/reference/host/object#主机-object)
-   [主机组-object](/manual/api/reference/hostgroup/object#主机组-object)

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

[comment]: # ({90dfc753-90dfc753})
### 来源

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

[comment]: # ({/90dfc753-90dfc753})
