[comment]: # translation:outdated

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

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

[comment]: # ({8e611812-29074792})
### 描述

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

此方法允许获取给定参数的主机接口记录。

::: noteclassic
该方法适用于*管理员*和*超级管理员*用户类型。可以在用户角色设置中撤销调用该方法的权限。有关详细信息，参阅[用户角色](/manual/web_interface/frontend_sections/administration/user_roles)。:::

[comment]: # ({/8e611812-29074792})

[comment]: # ({fa26a42b-a40e6018})
### 参数

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

该方法支持以下参数：

|参数|[类型](/manual/api/reference_commentary#data_types)|描述|
|---------|---------------------------------------------------|-----------|
|hostids|字符串/数组|返回给定主机使用的主机接口。|
|interfaceids|字符串/数组|返回给定ID的主机接口。|
|itemids|字符串/数组|返回给定监控项使用的主机接口。|
|triggerids|字符串/数组|返回给定的触发器中监控项使用的主机接口。|
|selectItems|查询|返回[监控项](/manual/api/reference/host/object) 属性。其中包括使用该接口的监控项<br><br>支持 `count`.|
|selectHosts|查询|返回 [主机](/manual/api/reference/host/object)属性，其中包括使用该接口的主机数组。|
|limitSelects|整型|限制子选择返回的记录数<br><br>适用于以下子选择:<br>`selectItems`。|
|sortfield|字符串/数组|对给定属性的结果进行排序。<br><br>可能的值有: `interfaceid`, `dns`, `ip`。|
|countOutput|布尔值| 该参数对于[参考注释](/manual/api/reference_commentary#common_get_method_parameters)页面中所有`get`详细描述的方法都适用。|
|editable|布尔值|^|
|excludeSearch|布尔值|^|
|filter|对象|^|
|limit|整型|^|
|nodeids|字符串/数组|^|
|output|查询|^|
|preservekeys|布尔值|^|
|search|对象|^|
|searchByAny|布尔值|^|
|searchWildcardsEnabled|布尔值|^|
|sortorder|字符串/数组|^|
|startSearch|布尔值|^|

[comment]: # ({/fa26a42b-a40e6018})

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

`(integer/array)` 返回:

-   一组对象;
-  如果设置了`countOutput`参数,则返回获取到的对象数量。

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

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

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

[comment]: # ({3daf5edb-cbd2e952})
#### 获取主机接口

获取ID为30057的主机使用的接口所有数据。

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "hostinterface.get",
    "params": {
        "output": "extend",
        "hostids": "30057"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "interfaceid": "50039",
            "hostid": "30057",
            "main": "1",
            "type": "1",
            "useip": "1",
            "ip": "::1",
            "dns": "",
            "port": "10050",
            "available": "0",
            "error": "",
            "errors_from": "0",
            "disable_until": "0",
            "details": []
        },
        {
            "interfaceid": "55082",
            "hostid": "30057",
            "main": "0",
            "type": "1",
            "useip": "1",
            "ip": "127.0.0.1",
            "dns": "",
            "port": "10051",
            "available": "0",
            "error": "",
            "errors_from": "0",
            "disable_until": "0",
            "details": {
                "version": "2",
                "bulk": "0",
                "community": "{$SNMP_COMMUNITY}"
            }
        }
    ],
    "id": 1
}
```

[comment]: # ({/3daf5edb-cbd2e952})

[comment]: # ({1c57700e-1c57700e})
### 参考

-   [主机](/manual/api/reference/host/object#host)
-   [监控项](/manual/api/reference/item/object#item)

[comment]: # ({/1c57700e-1c57700e})

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

CHostInterface::get() in
*ui/include/classes/api/services/CHostInterface.php*.

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