这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.
2022 Zabbix中国峰会
2022 Zabbix中国峰会

创建监控项原型

描述

object itemprototype.create(object/array itemPrototypes)

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

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

参数

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

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

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

返回值

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

案例

创建监控项原型

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

请求:

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

返回:

{
        · "jsonrpc": "2.0",
        · "result": {
        · "itemids": [
        · "27666"
        · ]
        · },
        · "id": 1
       }

创建监控项原型预处理

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

请求:

{
        · "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
       }

返回:

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

创建依赖监控项原型

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

请求:

{
        · "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
       }

返回:

{
        · "jsonrpc": "2.0",
        · "result": {
        · "itemids": [
        · "44212"
        · ]
        · },
        · "id": 1
       }

创建HTTP代理监控项原型

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

请求:

{
        · "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
       }

返回:

{
        · "jsonrpc": "2.0",
        · "result": {
        · "itemids": [
        · "28305"
        · ]
        · },
        · "id": 1
       }

创建监控项原型脚本

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

请求:

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

返回:

{
        · "jsonrpc": "2.0",
        · "result": {
        · "itemids": [
        · "23865"
        · ]
        · },
        · "id": 3
       }

来源

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