Zabbix Documentation 3.4

3.04.04.2 (current)In development:4.4 (devel)Unsupported:1.82.02.22.43.23.4

User Tools

Site Tools


Sidebar

zh:manual:api:reference:host:create

host.create

Description说明

object host.create(object/array hosts)

This method allows to create new hosts.此方法允许创建新的主机。

Parameters 参数

(object/array) Hosts to create.要创建的主机。

Additionally to the standard host properties, the method accepts the following parameters. 另外,对于标准主机属性,此方法接受以下参数。

参数 类型 说明
groups
(required)
object/array Host groups to add the host to.将主机添加到主机组中。

The host groups must have the groupid property defined.主机组必须已定义groupid属性。
interfaces
(required)
object/array Interfaces to be created for the host.为主机创建的接口。
templates object/array Templates to be linked to the host. 链接到主机的模板。

The templates must have the templateid property defined. 模板必须已定义过templateid属性。
macros object/array User macros to be created for the host.为主机创建的用户宏。
inventory object Host inventory properties. 主机资产清单属性。

Return values 返回值

(object) Returns an object containing the IDs of the created hosts under the hostids property. The order of the returned IDs matches the order of the passed hosts.返回一个对象其中包含在hostids属性下已创建主机的ID。返回ID的命令与传递主机的命令相匹配。

Examples范例

Creating a host 创建一个主机

Create a host called “Linux server” with an IP interface, add it to a group, link a template to it and set the MAC addresses in the host inventory.创建一个具有IP接口的“Linux Server”主机,将其添加到主机组中,链接一个模板并且把MAC地址设置到主机资产清单里。

Request:

{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "Linux server",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "192.168.3.1",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "50"
            }
        ],
        "templates": [
            {
                "templateid": "20045"
            }
        ],
        "inventory_mode": 0,
        "inventory": {
            "macaddress_a": "01234",
            "macaddress_b": "56768"
        }
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "107819"
        ]
    },
    "id": 1
}

See also参见

Source 来源

CHost::create() in frontends/php/include/classes/api/services/CHost.php.