这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.

创建

描述

object host.create(object/array hosts)

这个方法可以用来创建主机。

这个方法仅允许 管理员超级管理员 用户类型。可以在用户角色中撤销调用方法的权限设置。参考 User roles获取详情

参数

(对象/数组) 要创建的主机。

另外,对于标准的主机属性,该方法接受下列参数。

参数 类型 描述
groups
(必选)
object/array 把主机添加到目标

主机组必须已定义 groupid 属性。
interfaces object/array 为主机创建的接口
tags object/array 主机标签
templates object/array 主机连接的模板

模板必须已定义templateid属性。
macros object/array 为主机创建的用户宏
inventory object 主机资产清单属性。

返回值

(对象) 返回包含已创建主机ID的属性 hostids ,返回ID的顺序与传入主机的顺序一致。

示例

创建一个主机

创建一个具有IP接口和标签的“Linux Server”主机,将其添加到主机组中,链接一个模板并且把MAC地址设置到主机资产清单里。

请求:

{
           "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"
                   }
               ],
               "tags": [
                   {
                       "tag": "Host name",
                       "value": "Linux server"
                   }
               ],
               "templates": [
                   {
                       "templateid": "20045"
                   }
               ],
               "macros": [
                   {
                       "macro": "{$USER_ID}",
                       "value": "123321"
                   },
                   {
                       "macro": "{$USER_LOCATION}",
                       "value": "0:0:0",
                       "description": "latitude, longitude and altitude coordinates"
                   }
               ],
               "inventory_mode": 0,
               "inventory": {
                   "macaddress_a": "01234",
                   "macaddress_b": "56768"
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }
Copy
✔ Copied

响应:

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

创建一个具有SNMP接口的主机

创建一个名为“SNMP host”的主机,并创建SNMPv3接口。

请求:

{
           "jsonrpc": "2.0",
           "method": "host.create",
           "params": {
               "host": "SNMP host",
               "interfaces": [
                   {
                       "type": 2,
                       "main": 1,
                       "useip": 1,
                       "ip": "127.0.0.1",
                       "dns": "",
                       "port": "161",
                       "details": {
                           "version": 3,
                           "bulk": 0,
                           "securityname": "mysecurityname",
                           "contextname": "",
                           "securitylevel": 1
                       }
                   }
               ],
               "groups": [
                   {
                       "groupid": "4"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }
Copy
✔ Copied

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10658"
               ]
           },
           "id": 1
       }
Copy
✔ Copied

Creating a host with PSK encryption configured

Create a host called "PSK host" with PSK encryption configured only for connections from Zabbix server to host. Note that the Zabbix agent that is installed on the host has to be configured to use PSK.

Request:

{
           "jsonrpc": "2.0",
           "method": "host.create",
           "params": {
               "host": "PSK host",
               "interfaces": [
                   {
                       "type": 1,
                       "ip": "192.168.3.1",
                       "dns": "",
                       "port": "10050",
                       "useip": 1,
                       "main": 1
                   }
               ],
               "groups": [
                   {
                       "groupid": "2"
                   }
               ],
               "tls_connect": 2,
               "tls_psk_identity": "PSK 001",
               "tls_psk": "af8ced32dfe8714e548694e2d29e1a14ba6fa13f216cb35c19d0feb1084b0429"
           },
           "id": 1
       }
Copy
✔ Copied

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10590"
               ]
           },
           "id": 1
       }
Copy
✔ Copied

参考

源代码

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

To toggle search highlight, press Ctrl+Alt+H
Have an improvement suggestion for this page? Select the text that could be improved and press Ctrl+Enter to send it to the editors.