获取

描述

integer/array hostprototype.get(object parameters)

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

T任何类型的用户都可以使用该方法。调用该方法的权限可在用户角色设置中撤销。 更多信息请参阅 用户角色

参数

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

该方法支持以下参数。

参数 类型 描述
hostids ID/数组 仅返回具有指定ID的主机原型。
discoveryids ID/数组 仅返回属于指定LLD规则的主机原型。
inherited 布尔型 如果设置为true,仅返回从模板继承的项目。
selectDiscoveryRule 查询 返回一个discoveryRule属性,其中包含主机原型所属的LLD规则。
selectInterfaces 查询 返回一个interfaces属性,其中包含主机原型的自定义接口。
selectGroupLinks 查询 返回一个groupLinks属性,其中包含主机原型的组链接。
selectGroupPrototypes 查询 返回一个groupPrototypes属性,其中包含主机原型的组原型。
selectMacros 查询 返回一个macros属性,其中包含主机原型的宏。
selectParentHost 查询 返回一个parentHost属性,其中包含主机原型所属的主机。
selectTags 查询 返回一个tags属性,其中包含主机原型的标签。
selectTemplates 查询 返回一个templates属性,其中包含链接到主机原型的模板。

支持count
sortfield 字符串/数组 根据给定属性对结果进行排序。

可能的值:hostidhostnamestatusdiscovered
countOutput 布尔型 这些参数在参考说明中描述。
editable 布尔型
excludeSearch 布尔型
filter 对象
limit 整数
output 查询
preservekeys 布尔型
search 对象
searchByAny 布尔型
searchWildcardsEnabled 布尔型
sortorder 字符串/数组
startSearch 布尔型

返回值

(integer/array) 返回二者之一:

  • 一个对象数组;
  • 如果使用了 countOutput 参数,则读取的对象数量。

示例

从LLD规则中检索主机原型

从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() in ui/include/classes/api/services/CHostPrototype.php