[comment]: # ({31d5554a-31d5554a})
# hostprototype.get

[comment]: # ({/31d5554a-31d5554a})

[comment]: # ({d1534f8a-d1534f8a})
### 描述

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

该方法允许根据给定参数检索主机原型。

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

:::

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

[comment]: # ({59febe2f-0d6ab1f2})
### 参数

`(object)` 定义期望输出的参数.

该方法支持以下参数.

| 参数 | [数据类型](/manual/api/reference_commentary#数据类型) | 描述 |
|--|--|------|
| hostids | string/array | 仅返回具有给定ID的主机原型. |
| discoveryids | string/array | 仅返回属于给定LLD规则的主机原型. |
| inherited | boolean | 如果设置为`true`则仅返回从模板继承的监控项. |
| selectDiscoveryRule | query | 返回一个[lld规则](/manual/api/reference/discoveryrule/object#lld规则)属性，包含主机原型所属的LLD规则. |
| selectInterfaces | query | 返回一个[自定义接口](/manual/api/reference/hostprototype/object#自定义接口)属性，包含主机原型的自定义接口. |
| selectGroupLinks | query | 返回一个[组链接](/manual/api/reference/hostprototype/object#组链接)属性，包含主机原型的组链接. |
| selectGroupPrototypes | query | 返回一个[组原型](/manual/api/reference/hostprototype/object#组原型)属性，包含主机原型的组原型. |
| selectMacros | query | 返回一个[macros](/manual/api/reference/usermacro/object)属性，包含主机原型的宏. |
| selectParentHost | query | 返回一个[parentHost](/manual/api/reference/host/object)属性，包含主机原型所属的主机. |
| selectTags | query | 返回一个[主机原型标签](/manual/api/reference/hostprototype/object#主机原型标签)属性，包含主机原型的标签. |
| selectTemplates | query | 返回一个[templates](/manual/api/reference/template/object)属性，包含链接到主机原型的模板.<br><br>支持`count`. |
| sortfield | string/array | 按给定属性排序结果.<br><br>可能的值为: `hostid`, `host`, `name`和`status`. |
| 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 | ^           |

[comment]: # ({/59febe2f-0d6ab1f2})

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

`(integer/array)` 返回以下两种结果之一:

-   一个包含array的objects数组;
-   检索到的objects数量, 如果使用了`countOutput`参数。

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

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

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

[comment]: # ({bebba1b3-a91c8b17})
#### 从LLD规则检索主机原型

从LLD规则中获取所有主机原型及其组链接、组原型和标签。

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "hostprototype.get",
    "params": {
        "output": "extend",
        "selectInterfaces": "extend",
        "selectGroupLinks": "extend",
        "selectGroupPrototypes": "extend",
        "selectTags": "extend",
        "discoveryids": "23554"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```
响应:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10092",
            "host": "{#HV.UUID}",
            "name": "{#HV.UUID}",
            "status": "0",
            "templateid": "0",
            "discover": "0",
            "custom_interfaces": "1",
            "inventory_mode": "-1",
            "groupLinks": [
                {
                    "group_prototypeid": "4",
                    "hostid": "10092",
                    "groupid": "7",
                    "templateid": "0"
                }
            ],
            "groupPrototypes": [
                {
                    "group_prototypeid": "7",
                    "hostid": "10092",
                    "name": "{#CLUSTER.NAME}",
                    "templateid": "0"
                }
            ],
            "tags": [
                {
                    "tag": "Datacenter",
                    "value": "{#DATACENTER.NAME}"
                },
                {
                    "tag": "Instance type",
                    "value": "{#INSTANCE_TYPE}"
                }
            ],
            "interfaces": [
                {
                    "main": "1",
                    "type": "2",
                    "useip": "1",
                    "ip": "127.0.0.1",
                    "dns": "",
                    "port": "161",
                    "details": {
                        "version": "2",
                        "bulk": "1",
                        "community": "{$SNMP_COMMUNITY}"
                    }
                }
            ]
        }
    ],
    "id": 1
}
```

[comment]: # ({/bebba1b3-a91c8b17})

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

-   [组链接](object#组链接)
-   [组原型](object#组原型)
-   [用户宏-object](/manual/api/reference/usermacro/object#用户宏-object)

[comment]: # ({/749ec170-749ec170})

[comment]: # ({437ab274-437ab274})
### 来源

CHostPrototype::get() 位于
*ui/include/classes/api/services/CHostPrototype.php* 文件中.

[comment]: # ({/437ab274-437ab274})
