2022 Zabbix中国峰会
2022 Zabbix中国峰会

获取

描述

integer/array item.get(object parameters)

此方法允许根据给定的参数检索监控项。

此方法适用于任何类型的用户。可以在用户角色设置中撤销调用此方法的权限。更多信息请参阅用户角色

参数

(object) 定义所需输出的参数。

该方法支持以下参数。

参数 类型 描述
itemids ID/array 只返回具有给定ID的监控项。
groupids ID/array 只返回属于给定组的监控项。
templateids ID/array 只返回属于给定模板的监控项。
hostids ID/array 只返回属于给定主机的监控项。
proxyids ID/array 只返回由给定代理监控的监控项。
interfaceids ID/array 只返回使用给定主机接口的监控项。
graphids ID/array 只返回在给定图表中使用的监控项。
triggerids ID/array 只返回在给定触发器中使用的监控项。
webitems flag 在结果中包含网页监控项。
inherited boolean 如果设置为true,则只返回从模板继承的监控项。
templated boolean 如果设置为true,则只返回属于模板的监控项。
monitored boolean 如果设置为true,则只返回属于被监控主机的启用的监控项。
group string 只返回属于具有给定名称的组的监控项。
host string 只返回属于具有给定名称的主机的监控项。
evaltype integer 标签搜索规则。

可能的值:
0 - (默认)与/或;
2 - 或。
tags array 只返回具有给定标签的监控项。根据操作符的值,可以进行精确匹配标签,或者进行大小写敏感或不敏感的标签值搜索。
格式:[{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...]
空数组返回所有监控项。
可能的操作符类型:
0 - (默认)类似;
1 - 等于;
2 - 不类似;
3 - 不等于;
4 - 存在;
5 - 不存在。
with_triggers boolean 如果设置为true,则只返回在触发器中使用的监控项。
selectHosts query 返回一个hosts属性,包含监控项所属的主机数组。
selectInterfaces query 返回一个interfaces属性,包含监控项使用的主机接口数组。
selectTriggers query 返回一个triggers属性,包含监控项使用的触发器。
支持count
selectGraphs query 返回一个graphs属性,包含包含监控项的图表。
支持count
selectDiscoveryRule query 返回一个discoveryRule属性,包含创建监控项的LLD规则。
selectItemDiscovery query 返回一个itemDiscovery属性,包含监控项发现对象。该对象链接了监控项与其原型。

包含以下属性:
itemdiscoveryid - 监控项发现的ID;
itemid - 被发现监控项的ID;
parent_itemid - 创建监控项的原型ID;
key_ - 监控项原型的键;
lastcheck - 上次发现监控项的时间;
status - 监控项发现状态:
0 - (默认) 监控项已发现,
1 - 监控项不再被发现;
ts_delete - 不再被发现的监控项将被删除的时间;
ts_disable - 不再被发现的监控项将被禁用的时间;
disable_source - 监控项是被LLD规则还是手动禁用的指示器:
0 - (默认) 自动禁用,
1 - 由LLD规则禁用。
selectPreprocessing query 返回一个preprocessing属性,包含监控项预处理选项。
selectTags query 返回tags属性中的监控项标签。
selectValueMap query 返回一个valuemap属性,包含监控项的值映射。
filter object 只返回完全符合给定过滤器的结果。

接受一个对象,其中键是属性名称,值是单一值或值数组。

不支持text 数据类型的属性。

支持额外属性:
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 参数,则检索对象的计数。

示例

按照关键字查找监控项

检索特定主机ID中用于触发器的所有监控项,这些监控项的项键中包含单词“system.cpu”,并按名称排序结果。

请求

{
           "jsonrpc": "2.0",
           "method": "item.get",
           "params": {
               "output": "extend",
               "hostids": "10084",
               "with_triggers": true,
               "search": {
                   "key_": "system.cpu"
               },
               "sortfield": "name"
           },
           "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": "",
                   "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",
                   "name_resolved": "CPU utilization"
               },
               {
                   "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": "",
                   "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",
                   "name_resolved": "Load average (15m avg)"
               },
               {
                   "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": "",
                   "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",
                   "name": "Load average (1m avg)"
               },
               {
                   "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": "",
                   "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",
                   "name_resolved": "Load average (5m avg)"
               },
               {
                   "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": "",
                   "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",
                   "name_resolved": "Number of CPUs"
               }
           ],
           "id": 1
       }

按关键字查找依赖监控项

检索目标 ID 为 “10116” 的主机,包含关键字 “apache” 的所有依赖监控项。

请求

{
           "jsonrpc": "2.0",
           "method": "item.get",
           "params": {
               "output": "extend",
               "hostids": "10116",
               "search": {
                   "key_": "apache"
               },
               "filter": {
                   "type": 18
               }
           },
           "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": "",
                   "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",
                   "name_resolved": "Days"
               },
               {
                   "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": "",
                   "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",
                   "name_resolved": "Hours"
               }
           ],
           "id": 1
       }

查找 HTTP 代理的监控项

查找具有特定主机 id 的 post 正文类型 XML 的 HTTP agent 监控项。

请求

{
           "jsonrpc": "2.0",
           "method": "item.get",
           "params": {
               "hostids": "10255",
               "filter": {
                   "type": 19,
                   "post_type": 3
               }
           },
           "id": 1
       }

响应:

{
           "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": "",
                   "url": "localhost",
                   "query_fields": [
                       {
                           "name": "mode",
                           "value": "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": "",
                   "name_resolved": "template item"
               }
           ],
           "id": 1
       }

检索预处理规则监控项

检索 ID 为 “10254” 的主机所有监控项及其预处理规则。

请求

{
           "jsonrpc": "2.0",
           "method": "item.get",
           "params": {
               "output": ["itemid", "name", "key_"],
               "selectPreprocessing": "extend",
               "hostids": "10254"
           },
           "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() in ui/include/classes/api/services/CItem.php.