itemprototype.create

Description

说明

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

This method allows to create new item prototypes. 此方法用于创建新的item prototypes(监控项原型)。

Parameters

参数

(object/array) Item prototype to create. (object/array) 需要创建的item prototypes。

Additionally to the standard item prototype properties, the method accepts the following parameters. 除标准项原型属性外,该方法还接受以下参数。

ParameterTypeDescription
ruleid
(required)
stringID of the LLD rule that the item belongs to. 该项所属的LLD规则的ID。
applicationsarrayIDs of applications to be assigned to the discovered items.要分配给自动发现item的应用程序的ID。
applicationPrototypesarrayNames of application prototypes to be assigned to the item prototype. 要分配给item prototypes的应用程序原型的名称。
preprocessingarrayItem prototype preprocessing options. Item prototype 预处理选项。

Return values

返回值

(object) Returns an object containing the IDs of the created item prototypes under the itemids property. The order of the returned IDs matches the order of the passed item prototypes. (object) 返回一个对象,该对象ID包含在“itemid”属性中。 返回的ID的顺序与传递的item prototypes的顺序相对应。

Examples

示例

Creating an item prototype

Create an item prototype to monitor free disc space on a discovered file system. Discovered items should be numeric Zabbix agent items updated every 30 seconds. 创建一个item prototype去监控自动发现的文件系统上的磁盘空间。Discovered items 应该每30秒更新数字化的Zabbix agent监控项。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "itemprototype.create",
  4. "params": {
  5. "name": "Free disk space on $1",
  6. "key_": "vfs.fs.size[{#FSNAME},free]",
  7. "hostid": "10197",
  8. "ruleid": "27665",
  9. "type": 0,
  10. "value_type": 3,
  11. "interfaceid": "112",
  12. "delay": "30s"
  13. },
  14. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  15. "id": 1
  16. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "27666"
  6. ]
  7. },
  8. "id": 1
  9. }

Creating an item prototype with preprocessing

创建一个预处理的 item prototype

Create an item using change per second and a custom multiplier as a second step. 创建一个使用每秒变化并带有自定义乘法器作为第二部的监控项。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "itemprototype.create",
  4. "params": {
  5. "name": "Incoming network traffic on $1",
  6. "key_": "net.if.in[{#IFNAME}]",
  7. "hostid": "10001",
  8. "ruleid": "27665",
  9. "type": 0,
  10. "value_type": 3,
  11. "delay": "60s",
  12. "units": "bps",
  13. "interfaceid": "1155",
  14. "preprocessing": [
  15. {
  16. "type": "10",
  17. "params": ""
  18. },
  19. {
  20. "type": "1",
  21. "params": "8"
  22. }
  23. ]
  24. },
  25. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  26. "id": 1
  27. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "44211"
  6. ]
  7. },
  8. "id": 1
  9. }

Creating dependent item prototype

创建依赖item prototype

Create Dependent item prototype for Master item prototype with ID 44211. Only dependencies on same host (template/discovery rule) are allowed, therefore Master and Dependent item should have same hostid and ruleid. 为ID为44211的主item prototype创建一个依赖item prototype。只有在同一个主机的(template/discovery rule)依赖才可以被接受,因此主 item prototype 和依赖 item prototype 应该拥有相同的hostid和ruleid。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "itemprototype.create",
  4. "params": {
  5. "hostid": "10001",
  6. "ruleid": "27665",
  7. "name": "Dependent test item prototype",
  8. "key_": "dependent.prototype",
  9. "type": "18",
  10. "master_itemid": "44211",
  11. "value_type": "3"
  12. },
  13. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  14. "id": 1
  15. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "44212"
  6. ]
  7. },
  8. "id": 1
  9. }

Create HTTP agent item prototype

创建HTTP agent item prototype

Create item prototype with URL using user macro, query fields and custom headers. 创建带有URL使用用户宏,查询字段和自定义选项的item prototype。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "itemprototype.create",
  4. "params": {
  5. "type": "19",
  6. "hostid": "10254",
  7. "ruleid":"28256",
  8. "interfaceid":"2",
  9. "name": "api item prototype example",
  10. "key_": "api_http_item",
  11. "value_type": "3",
  12. "url": "{$URL_PROTOTYPE}",
  13. "query_fields": [
  14. {
  15. "min": "10"
  16. },
  17. {
  18. "max": "100"
  19. }
  20. ],
  21. "headers": {
  22. "X-Source": "api"
  23. },
  24. "delay":"35"
  25. },
  26. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  27. "id": 1
  28. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "itemids": [
  5. "28305"
  6. ]
  7. },
  8. "id": 1
  9. }

Source

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