创建监控项原型

描述

object itemprototype.create(object/array itemPrototypes)

该方法允许创建监控项原型。

此方法仅适用于管理员超级管理员用户类型。可以在用户角色设置中撤销调用该方法的权限。了解更多信息请参见用户角色

参数

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

标准监控项原型外,该方法还接受以下参数。

参数类型描述
ruleid
(required)
string监控项所属的LLD规则ID
preprocessingarray监控项原型预处理 选项。
tagsarray监控项原型标签

返回值

返回一个对象(object) ,该对象包含在 itemids 属性下创建的监控项原型的 IDs。返回的 IDs 的顺序与传递的项目原型的顺序相匹配。

案例

创建监控项原型

创建监控项原型来发现文件系统上的可用磁盘空间。发现的Zabbix客户端监控项每 30 秒更新一次的数字。

请求:

  1. {
  2. · "jsonrpc": "2.0",
  3. · "method": "itemprototype.create",
  4. · "params": {
  5. · "name": "Free disk space on {#FSNAME}",
  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. }

返回:

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

创建监控项原型预处理

先创建一个监控项,第二步在预处理中使用每秒更改和自定义乘数。

请求:

  1. {
  2. · "jsonrpc": "2.0",
  3. · "method": "itemprototype.create",
  4. · "params": {
  5. · "name": "Incoming network traffic on {#IFNAME}",
  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. · "error_handler": "0",
  19. · "error_handler_params": ""
  20. · },
  21. · {
  22. · "type": "1",
  23. · "params": "8",
  24. · "error_handler": "2",
  25. · "error_handler_params": "10"
  26. · }
  27. · ]
  28. · },
  29. · "auth": "038e1d7b1735c6a5436ee9eae095879e",
  30. · "id": 1
  31. }

返回:

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

创建依赖监控项原型

创建依赖与ID 44211监控项原型的监控项原型。 只允许依赖一些主机(模板/发现规则),因此主要监控项和依赖监控项应该具有相同的 hostid 和 ruleid。

请求:

  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. }

返回:

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

创建HTTP代理监控项原型

使用用户宏、查询字段和自定义头部创建带有URL的监控项原型。

请求:

  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. }

返回:

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

创建监控项原型脚本

使用脚本监控项原型创建一个简单的数据集合。

请求:

  1. {
  2. · "jsonrpc": "2.0",
  3. · "method": "itemprototype.create",
  4. · "params": {
  5. · "name": "Script example",
  6. · "key_": "custom.script.itemprototype",
  7. · "hostid": "12345",
  8. · "type": 21,
  9. · "value_type": 4,
  10. · "params": "var request = new CurlHttpRequest();\nreturn request.Post(\"https://postman-echo.com/post\", JSON.parse(value));",
  11. · "parameters": [{
  12. · "name": "host",
  13. · "value": "{HOST.CONN}"
  14. · }],
  15. · "timeout": "6s",
  16. · "delay": "30s"
  17. · },
  18. · "auth": "038e1d7b1735c6a5436ee9eae095879e",
  19. · "id": 2
  20. }

返回:

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

来源

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