[comment]: # translation:outdated

[comment]: # ({959fe29c-959fe29c})
# 创建

[comment]: # ({/959fe29c-959fe29c})

[comment]: # ({a1aebf86-e3078f54})
###描述

`object item.create(object/array items)`

此方法用于创建新监控项。

::: noteclassic
无法通过 Zabbix API 创建 Web 监控项。
:::

::: noteclassic
此方法仅允许 *Admin（管理员）* 和 *Super admin（超级管理员）* 类型的用户使用。调用此方法的权限可以在用户角色设置中撤销。更多信息请参阅 [用户角色](/manual/web_interface/frontend_sections/users/user_roles)。
:::

[comment]: # ({/a1aebf86-e3078f54})

[comment]: # ({29c80a11-777e8bec})
### 参数

`(object/array)` 创建目标监控项。
 
除了 [标准监控项属性](object#host) 之外，此方法同样适用以下参数。

|参数|[类型](/manual/api/reference_commentary#data_types)|说明|
|---------|---------------------------------------------------|-----------|
|preprocessing|array|监控项 [预处理](/manual/api/reference/item/object#item_preprocessing) 选项。|
|tags|array|监控项 [标签](/manual/api/reference/item/object#item_tag) 。|

[comment]: # ({/29c80a11-777e8bec})

[comment]: # ({632959fe-632959fe})
### 返回值

`(object)` 返回一个对象，该对象包含 `itemids` 属性下创建的监控项的 ID。返回 ID 的顺序与传递监控项的顺序一致。

[comment]: # ({/632959fe-632959fe})

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

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

[comment]: # ({fcd2cbf9-6ffb1f45})
#### 创建监控项

创建含有 2 个标签的数值型 Zabbix agent 监控项，用于监控 ID 为 “30074” 主机上的可用磁盘空间。

[请求](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Free disk space on /home/joe/",
        "key_": "vfs.fs.size[/home/joe/,free]",
        "hostid": "30074",
        "type": 0,
        "value_type": 3,
        "interfaceid": "30084",
        "tags": [
            {
                "tag": "Disk usage"
            },
            {
                "tag": "Equipment",
                "value": "Workstation"
            }
        ],
        "delay": "30s"
    },
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "24758"
        ]
    },
    "id": 1
}
```

[comment]: # ({/fcd2cbf9-6ffb1f45})

[comment]: # ({91af8fa5-0f29886e})
#### 创建主机资产监控项

创建 Zabbix agent 监控项，用于增添主机的 “OS” 资产字段。

[请求](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "uname",
        "key_": "system.uname",
        "hostid": "30021",
        "type": 0,
        "interfaceid": "30007",
        "value_type": 1,
        "delay": "10s",
        "inventory_link": 5
    },
    "id": 1
}
```

响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "24759"
        ]
    },
    "id": 1
}
```

[comment]: # ({/91af8fa5-0f29886e})

[comment]: # ({aac399db-f45b1a9a})
#### 创建预处理监控项

创建自定义乘数监控项。


[请求](/manual/api#performing-requests)：

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Device uptime",
        "key_": "sysUpTime",
        "hostid": "11312",
        "type": 4,
        "snmp_oid": "SNMPv2-MIB::sysUpTime.0",
        "value_type": 1,
        "delay": "60s",
        "units": "uptime",
        "interfaceid": "1156",
        "preprocessing": [
            {
                "type": 1,
                "params": "0.01",
                "error_handler": 1,
                "error_handler_params": ""
            }
        ]
    },
    "id": 1
}
```
响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "44210"
        ]
    },
    "id": 1
}
```

[comment]: # ({/aac399db-f45b1a9a})

[comment]: # ({166357cc-6a32a64f})
#### 创建依赖监控项

创建 ID 为 24759 的主监控项的依赖监控项。仅允许依赖于同一主机，主项和依赖项要具有相同的hostid。

[请求](/manual/api#performing-requests)：

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
      "hostid": "30074",
      "name": "Dependent test item",
      "key_": "dependent.item",
      "type": 18,
      "master_itemid": "24759",
      "value_type": 2
    },
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "44211"
        ]
    },
    "id": 1
}
```

[comment]: # ({/166357cc-6a32a64f})

[comment]: # ({98de8418-70eb9eae})
#### 创建 HTTP agent 监控项

创建 JSON 响应预处理式的 POST 请求方法监控项。


[请求](/manual/api#performing-requests)：

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "url":"http://127.0.0.1/http.php",
        "query_fields": [
            {
                "name": "mode",
                "value": "json"
            },
            {
                "name": "min",
                "value": "10"
            },
            {
                "name": "max",
                "value": "100"
            }
        ],
        "interfaceid": "1",
        "type": 19,
        "hostid": "10254",
        "delay": "5s",
        "key_": "json",
        "name": "HTTP agent example JSON",
        "value_type": 0,
        "output_format": 1,
        "preprocessing": [
            {
                "type": 12,
                "params": "$.random",
                "error_handler": 0,
                "error_handler_params": ""
            }
        ]
    },
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "23865"
        ]
    },
    "id": 1
}
```

[comment]: # ({/98de8418-70eb9eae})

[comment]: # ({568de3f0-313c9999})
#### 创建脚本监控项

创建用于简单数据收集的脚本监控项。

[请求](/manual/api#performing-requests)：

```json
{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Script example",
        "key_": "custom.script.item",
        "hostid": "12345",
        "type": 21,
        "value_type": 4,
        "params": "var request = new HttpRequest();\nreturn request.post(\"https://postman-echo.com/post\", JSON.parse(value));",
        "parameters": [
            {
                "name": "host",
                "value": "{HOST.CONN}"
            }
        ],
        "timeout": "6s",
        "delay": "30s"
    },
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "23865"
        ]
    },
    "id": 1
}
```

[comment]: # ({/568de3f0-313c9999})

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

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

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