integer/array item.get(object parameters)
该方法允许根据给定参数检索监控项。
此方法可供任何类型的用户使用。调用该方法的权限可以在用户角色设置中撤销。更多信息请参阅User roles。
(object)
定义输出结果的参数。
该方法支持以下参数。
参数 | 数据类型 | 描述 |
---|---|---|
itemids | string/array | 仅返回具有指定ID的监控项。 |
groupids | string/array | 仅返回属于指定组中主机的监控项。 |
templateids | string/array | 仅返回属于指定模板的监控项。 |
hostids | string/array | 仅返回属于指定主机的监控项。 |
proxyids | string/array | 仅返回由指定proxies监控的监控项。 |
interfaceids | string/array | 仅返回使用指定主机接口的监控项。 |
graphids | string/array | 仅返回在指定图形中使用的监控项。 |
triggerids | string/array | 仅返回在指定触发器中使用的监控项。 |
webitems | flag | 在结果中包含Web 监控项。 |
inherited | boolean | 如果设置为true ,仅返回从模板继承的监控项。 |
templated | boolean | 如果设置为true ,仅返回属于模板的监控项。 |
monitored | boolean | 如果设置为true ,仅返回属于受监控主机的已启用监控项。 |
group | string | 仅返回属于具有指定名称的组的监控项。 |
host | string | 仅返回属于具有指定名称的主机的监控项。 |
evaltype | integer | 标签搜索规则。 可能的值: 0 - (默认)与/或; 2 - 或。 |
tags | array of objects | 仅返回具有指定标签的监控项。根据操作符值,对标签进行精确匹配或对标签值进行大小写敏感/不敏感的搜索。 格式: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...] 。空的array返回所有监控项。 可能的操作符类型: 0 - (默认)类似; 1 - 等于; 2 - 不类似; 3 - 不等于; 4 - 存在; 5 - 不存在。 |
with_triggers | boolean | 如果设置为true ,仅返回在触发器中使用的监控项。 |
selectHosts | query | 返回一个hosts属性,包含监控项所属主机的array。 |
selectInterfaces | query | 返回一个interfaces属性,包含监控项使用的主机接口的array。 |
selectTriggers | query | 返回一个triggers属性,包含使用监控项的触发器。 支持 count 。 |
selectGraphs | query | 返回一个graphs属性,包含包含监控项的图形。 支持 count 。 |
selectDiscoveryRule | query | 返回一个discoveryRule属性,包含创建监控项的LLD规则。 |
selectItemDiscovery | query | 返回一个itemDiscovery 属性,包含监控项的发现object。监控项的发现object将监控项链接到创建它的监控项原型。具有以下属性: itemdiscoveryid - (string) 监控项发现的ID;itemid - (string) 发现的监控项的ID;parent_itemid - (string) 创建监控项的监控项原型的ID;key_ - (string) 监控项原型的键;lastcheck - (timestamp) 监控项上次被发现的时间;ts_delete - (timestamp) 不再发现的监控项将被删除的时间。 |
selectPreprocessing | query | 返回一个预处理属性,包含监控项预处理选项。 具有以下属性: type - (string) 预处理选项类型:1 - 自定义乘数; 2 - 右修剪; 3 - 左修剪; 4 - 修剪; 5 - 正则表达式匹配; 6 - boolean转十进制; 7 - 八进制转十进制; 8 - 十六进制转十进制; 9 - 简单变更; 10 - 每秒变更; 11 - XML XPath; 12 - JSONPath; 13 - 在范围内; 14 - 匹配正则表达式; 15 - 不匹配正则表达式; 16 - 检查JSON中的错误; 17 - 检查XML中的错误; 18 - 使用正则表达式检查错误; 19 - 丢弃未更改; 20 - 带心跳的丢弃未更改; 21 - JavaScript; 22 - Prometheus模式; 23 - Prometheus转JSON; 24 - CSV转JSON; 25 - 替换; 26 - 检查不支持的值; 27 - XML转JSON。 params - (string) 预处理选项使用的附加参数。多个参数由LF(\n)字符分隔。error_handler - (string) 预处理步骤失败时使用的操作类型:0 - 错误消息由Zabbix server设置; 1 - 丢弃值; 2 - 设置自定义值; 3 - 设置自定义错误消息。 error_handler_params - (string) 错误处理程序参数。 |
selectTags | query | 返回监控项-标签属性中的监控项标签。 |
selectValueMap | query | 返回一个valuemap属性,包含监控项的值映射。 |
filter | object | 仅返回与指定过滤器完全匹配的结果。 接受一个array,其中键是属性名称,值是要匹配的单个值或array。 支持附加过滤器: host - 监控项所属主机的技术名称。 |
limitSelects | integer | 限制子查询返回的记录数。 适用于以下子查询: selectGraphs - 结果将按name 排序;selectTriggers - 结果将按description 排序。 |
sortfield | string/array | 按指定属性对结果进行排序。 可能的值为: itemid , name , key_ , delay , history , trends , type 和status 。 |
countOutput | boolean | 这些参数在通用get方法参数中描述。 |
editable | boolean | |
excludeSearch | boolean | |
limit | integer | |
output | query | |
preservekeys | boolean | |
search | object | |
searchByAny | boolean | |
searchWildcardsEnabled | boolean | |
sortorder | string/array | |
startSearch | boolean |
(integer/array)
返回以下两种结果之一:
countOutput
参数,则返回检索到的objects数量。检索特定主机 ID中所有触发器使用的包含"system.cpu"关键字的监控项,并按名称排序结果。
请求:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": "extend",
"hostids": "10084",
"with_triggers": true,
"search": {
"key_": "system.cpu"
},
"sortfield": "name"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "42269",
"type": "18",
"snmp_oid": "",
"hostid": "10084",
"name": "CPU utilization",
"key_": "system.cpu.util",
"delay": "0",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "0",
"trapper_hosts": "",
"units": "%",
"logtimefmt": "",
"templateid": "42267",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "0",
"description": "CPU utilization in %.",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "42264",
"timeout": "3s",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0"
},
{
"itemid": "42259",
"type": "0",
"snmp_oid": "",
"hostid": "10084",
"name": "Load average (15m avg)",
"key_": "system.cpu.load[all,avg15]",
"delay": "1m",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "0",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "42219",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "1",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "3s",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0"
},
{
"itemid": "42249",
"type": "0",
"snmp_oid": "",
"hostid": "10084",
"name": "Load average (1m avg)",
"key_": "system.cpu.load[all,avg1]",
"delay": "1m",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "0",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "42209",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "1",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "3s",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0"
},
{
"itemid": "42257",
"type": "0",
"snmp_oid": "",
"hostid": "10084",
"name": "Load average (5m avg)",
"key_": "system.cpu.load[all,avg5]",
"delay": "1m",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "0",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "42217",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "1",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "3s",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0"
},
{
"itemid": "42260",
"type": "0",
"snmp_oid": "",
"hostid": "10084",
"name": "Number of CPUs",
"key_": "system.cpu.num",
"delay": "1m",
"history": "7d",
"trends": "365d",
"status": "0",
"value_type": "3",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "42220",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "1",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "3s",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0"
}
],
"id": 1
}
从ID为"10116"的主机中检索所有键名包含"apache"的依赖监控项。
请求:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": "extend",
"hostids": "10116",
"search": {
"key_": "apache"
},
"filter": {
"type": 18
}
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "25550",
"type": "18",
"snmp_oid": "",
"hostid": "10116",
"name": "Days",
"key_": "apache.status.uptime.days",
"delay": "0",
"history": "90d",
"trends": "365d",
"status": "0",
"value_type": "3",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "0",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "0",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "25545",
"timeout": "3s",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0"
},
{
"itemid": "25555",
"type": "18",
"snmp_oid": "",
"hostid": "10116",
"name": "Hours",
"key_": "apache.status.uptime.hours",
"delay": "0",
"history": "90d",
"trends": "365d",
"status": "0",
"value_type": "3",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "0",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "0",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "25545",
"timeout": "3s",
"url": "",
"query_fields": [],
"posts": "",
"status_codes": "200",
"follow_redirects": "1",
"post_type": "0",
"http_proxy": "",
"headers": [],
"retrieve_mode": "0",
"request_method": "0",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "0",
"prevvalue": "0"
}
],
"id": 1
}
查找具有XML请求体类型的HTTP agent 监控项,针对特定主机 ID。
请求:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"hostids": "10255",
"filter": {
"type": 19,
"post_type": 3
}
},
"id": 3,
"auth": "d678e0b85688ce578ff061bd29a20d3b"
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "28252",
"type": "19",
"snmp_oid": "",
"hostid": "10255",
"name": "template item",
"key_": "ti",
"delay": "30s",
"history": "90d",
"trends": "365d",
"status": "0",
"value_type": "3",
"trapper_hosts": "",
"units": "",
"logtimefmt": "",
"templateid": "0",
"valuemapid": "0",
"params": "",
"ipmi_sensor": "",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"flags": "0",
"interfaceid": "0",
"description": "",
"inventory_link": "0",
"evaltype": "0",
"jmx_endpoint": "",
"master_itemid": "0",
"timeout": "3s",
"url": "localhost",
"query_fields": [
{
"mode": "xml"
}
],
"posts": "<body>\r\n<![CDATA[{$MACRO}<foo></bar>]]>\r\n</body>",
"status_codes": "200",
"follow_redirects": "0",
"post_type": "3",
"http_proxy": "",
"headers": [],
"retrieve_mode": "1",
"request_method": "3",
"output_format": "0",
"ssl_cert_file": "",
"ssl_key_file": "",
"ssl_key_password": "",
"verify_peer": "0",
"verify_host": "0",
"allow_traps": "0",
"uuid": "",
"state": "0",
"error": "",
"parameters": [],
"lastclock": "0",
"lastns": "0",
"lastvalue": "",
"prevvalue": ""
}
],
"id": 3
}
获取指定主机 ID的所有监控项及其预处理规则。
请求:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": ["itemid", "name", "key_"],
"selectPreprocessing": "extend",
"hostids": "10254"
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"itemid": "23865",
"name": "HTTP agent example JSON",
"key_": "json",
"preprocessing": [
{
"type": "12",
"params": "$.random",
"error_handler": "1",
"error_handler_params": ""
}
]
},
"id": 1
}
CItem::get() 位于 ui/include/classes/api/services/CItem.php 文件中。