integer/array hostprototype.get(object parameters)
该方法允许根据给定的参数检索主机原型。
此方法可供任何类型的用户使用。调用该方法的权限可以在用户角色设置中撤销。更多信息请参见User roles。
(object) 定义期望输出的参数。
该方法支持以下参数。
| 参数 | 数据类型 | 描述 | 
|---|---|---|
| hostids | ID/array | 仅返回具有指定ID的主机原型。 | 
| discoveryids | ID/array | 仅返回属于指定LLD规则的主机原型。 | 
| inherited | boolean | 如果设置为 true,则仅返回从模板继承的监控项。 | 
| selectDiscoveryRule | query | 返回一个 discoveryRule属性,包含主机原型所属的LLD规则。 | 
| selectInterfaces | query | 返回一个 interfaces属性,包含主机原型的自定义接口。 | 
| selectGroupLinks | query | 返回一个 groupLinks属性,包含主机原型的组链接。 | 
| selectGroupPrototypes | query | 返回一个 groupPrototypes属性,包含主机原型的组原型。 | 
| selectMacros | query | 返回一个 macros属性,包含主机原型的宏。 | 
| selectParentHost | query | 返回一个 parentHost属性,包含主机原型所属的主机。 | 
| selectTags | query | 返回一个 tags属性,包含主机原型的标签。 | 
| selectTemplates | query | 返回一个 templates属性,包含链接到主机原型的模板。支持 count。 | 
| sortfield | string/array | 按照指定属性对结果进行排序。 可能的值: hostid、host、name、status、discovered。 | 
| 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 参数,则为检索到的 objects 的数量。从LLD规则中获取所有主机原型及其组链接、组原型和标签。
执行请求:
{
           "jsonrpc": "2.0",
           "method": "hostprototype.get",
           "params": {
               "output": "extend",
               "selectInterfaces": "extend",
               "selectGroupLinks": "extend",
               "selectGroupPrototypes": "extend",
               "selectTags": "extend",
               "discoveryids": "23554"
           },
           "id": 1
       }响应:
{
           "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}",
                               "max_repetitions": "10"
                           }
                       }
                   ]
               }
           ],
           "id": 1
       }CHostPrototype::get() 在 ui/include/classes/api/services/CHostPrototype.php 中。