创建
描述
object item.create(object/array items)
此方法允许创建新的监控项。
Web 监控项无法通过 Zabbix API 创建。
此方法仅适用于 Admin 和 Super admin 用户类型。 调用该方法的权限可在用户角色设置中撤销。 更多信息请参见 用户角色。
参数
(object/array) 要创建的监控项。
除了标准监控项属性外,该方法还接受以下参数。
返回值
(object) 返回一个对象,其中在 itemids 属性下包含已创建监控项的 ID。
返回的 ID 顺序与传入的监控项顺序一致。
示例
创建监控项
创建一个数值型 Zabbix agent 监控项,并使用 2 个监控项标签来监控 ID 为 "30074" 的主机上的可用磁盘空间。
请求:
{
"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": "component",
"value": "storage"
},
{
"tag": "equipment",
"value": "workstation"
}
],
"delay": "30s"
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"itemids": [
"24758"
]
},
"id": 1
}
创建主机资产监控项
创建 Zabbix agent 监控项,用于增添主机的 “OS” 资产字段。
请求:
{
"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
}
响应:
{
"jsonrpc": "2.0",
"result": {
"itemids": [
"24759"
]
},
"id": 1
}
使用预处理创建监控项
使用自定义乘数创建一个监控项。
请求:
{
"jsonrpc": "2.0",
"method": "item.create",
"params": {
"name": "Device uptime",
"key_": "sysUpTime",
"hostid": "10084",
"type": 20,
"snmp_oid": "SNMPv2-MIB::sysUpTime.0",
"value_type": 1,
"delay": "60s",
"interfaceid": "83",
"preprocessing": [
{
"type": 1,
"params": "0.01",
"error_handler": 1,
"error_handler_params": ""
}
]
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"itemids": [
"44210"
]
},
"id": 1
}
创建依赖监控项
为 ID 为 24759 的主监控项创建一个依赖监控项。
只允许依赖同一主机上的监控项,因此主监控项和依赖监控项应具有相同的 hostid。
请求:
{
"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
}
响应:
{
"jsonrpc": "2.0",
"result": {
"itemids": [
"44211"
]
},
"id": 1
}
创建 HTTP agent 监控项
创建 JSON 响应预处理式的 POST 请求方法监控项。
请求:
{
"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
}
响应:
{
"jsonrpc": "2.0",
"result": {
"itemids": [
"23865"
]
},
"id": 1
}
创建脚本监控项
创建用于简单数据收集的脚本监控项。
请求:
{
"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
}
响应:
{
"jsonrpc": "2.0",
"result": {
"itemids": [
"23865"
]
},
"id": 1
}
来源
CItem::create() in ui/include/classes/api/services/CItem.php.