[comment]: # translation:outdated

[comment]: # ({b243934a-450c25c2})
# 创建

[comment]: # ({/b243934a-450c25c2})

[comment]: # ({4168e8f3-74ae8b8a})
### 说明

`object itemprototype.create(object/array itemPrototypes)`

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

[comment]: # ({/4168e8f3-74ae8b8a})

[comment]: # ({c4d246d6-ace4eea1})
### 参数

`(object/array)` 需要创建的监控项原型。

除 [标准项原型属性](object#item_prototype)外，该方法还接受以下参数。

|属性                    类|描述|<|
|-----------------------------|------|-|
|**ruleid**<br>(必须)|string|该项所属的LLD规则的ID。|
|applications|array|要分配给自动发现监控项的应用程序的ID。|
|applicationPrototypes|array|要分配给监控项原型的应用程序原型的名称。|
|preprocessing|array|[预处理选项](/zh/manual/api/reference/itemprototype/object#item_prototype_preprocessing)。|

[comment]: # ({/c4d246d6-ace4eea1})

[comment]: # ({2a77ab98-4682a6ee})
### 返回值

`(object)` 返回一个对象，该对象ID包含在“itemid”属性中。
返回的ID的顺序与传递的item prototypes的顺序相对应。 `(object)`
返回一个对象，该对象包含在" itemids
"属性下创建的监控项原型的id。返回的id的顺序与传递的监控项原型的顺序相匹配。

[comment]: # ({/2a77ab98-4682a6ee})

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

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

[comment]: # ({e15f5e24-9956fee4})
#### 创建一个监控项原型

创建一个监控项原型去监控自动发现的文件系统上的磁盘空间。发现监控项
应该每30秒更新数字化的Zabbix agent监控项。

请求:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "itemprototype.create",
    "params": {
        "name": "Free disk space on $1",
        "key_": "vfs.fs.size[{#FSNAME},free]",
        "hostid": "10197",
        "ruleid": "27665",
        "type": 0,
        "value_type": 3,
        "interfaceid": "112",
        "delay": "30s"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "27666"
        ]
    },
    "id": 1
}
```

[comment]: # ({/e15f5e24-9956fee4})

[comment]: # ({6273ac6b-d22f43ae})
#### 创建一个预处理的监控项原型

创建一个使用每秒变化并带有自定义乘法器作为第二部的监控项。

请求:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "itemprototype.create",
    "params": {
        "name": "Incoming network traffic on {#IFNAME}",
        "key_": "net.if.in[{#IFNAME}]",
        "hostid": "10001",
        "ruleid": "27665",
        "type": 0,
        "value_type": 3,
        "delay": "60s",
        "units": "bps",
        "interfaceid": "1155",
        "preprocessing": [
            {
                "type": "10",
                "params": "",
                "error_handler": "0",
                "error_handler_params": ""
            },
            {
                "type": "1",
                "params": "8",
                "error_handler": "2",
                "error_handler_params": "10"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应:

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

[comment]: # ({/6273ac6b-d22f43ae})

[comment]: # ({484ea98c-76dad6d6})
#### 创建依赖监控项原型

[comment]: # ({/484ea98c-76dad6d6})

[comment]: # ({95329a59-94e7709f})
#### 创建依赖监控项原型

为ID为44211的主监控项原型创建一个依赖监控项原型。只有在同一个主机的(模板/LLD发现规则)依赖才可以被接受，因此主
监控项原型 和依赖 监控项原型 应该拥有相同的hostid和ruleid。

请求:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "itemprototype.create",
    "params": {
      "hostid": "10001",
      "ruleid": "27665",
      "name": "Dependent test item prototype",
      "key_": "dependent.prototype",
      "type": "18",
      "master_itemid": "44211",
      "value_type": "3"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "44212"
        ]
    },
    "id": 1
}
```

[comment]: # ({/95329a59-94e7709f})

[comment]: # ({40c80e5b-4f193e2e})
#### 创建 HTTP agent 监控项原型

创建带有URL使用用户宏，查询字段和自定义选项的item prototype。

请求:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "itemprototype.create",
    "params": {
        "type": "19",
        "hostid": "10254",
        "ruleid":"28256",
        "interfaceid":"2",
        "name": "api item prototype example",
        "key_": "api_http_item",
        "value_type": "3",
        "url": "{$URL_PROTOTYPE}",
        "query_fields": [
            {
                "min": "10"
            },
            {
                "max": "100"
            }
        ],
        "headers": {
            "X-Source": "api"
        },
        "delay":"35"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "28305"
        ]
    },
    "id": 1
}
```

### 来源

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

[comment]: # ({/40c80e5b-4f193e2e})
