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

item.get

说明

integer/array item.get(object parameters)

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

参数

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

该方法支持以下参数。

属性 类 说明
itemids string/array 只返回具有给定 ID 的监控项
groupids string/array 只返回属于给定组的主机的监控项
templateids string/array 仅返回属于给定模板的监控项
hostids string/array 仅返回属于给定主机的监控项
proxyids string/array 仅返回由给定代理监视的监控项
interfaceids string/array 仅返回使用给定主机接口的监控项
graphids string/array 仅返回在给定图表中使用的监控项
triggerids string/array 仅返回在给定触发器中使用的监控项
applicationids string/array 仅返回属于给定应用程序的监控项
webitems flag 在结果中包含 web 监控项。
inherited boolean 如果设置为“True”,只返回从模板中承接的项。
templated boolean 如果设置为“True”,则只返回属于模板的项
monitored boolean 如果设置为“True”,则仅返回属于受监控主机的已启用项
group string 仅返回属于具有给定名称的组的项
host string 仅返回属于具有给定名称的主机的项
application string 仅返回属于具有给定名称的应用程序的项
with_triggers boolean 如果设置为“true”,则只返回在触发器中使用的监控项
selectHosts query 将该项所属的主机作为“hosts”属性中的数组返回
selectInterfaces query 将项使用的主机接口作为“interfaces”属性中的数组返回。
selectTriggers query 在“'触发器”属性中,返回该项使用的触发。

Supports count.
selectGraphs query 在“图形”属性中返回包含该项的图形。

Supports count.
selectApplications query 在“应用程序”属性中返回该项所属的应用程序
selectDiscoveryRule query 返回在“discoveryRule”属性中创建该项的LLD规则
selectItemDiscovery query 在“itemDiscovery”属性中返回项目发现对象。项发现对象将项链接到从其创建的项原型。

它具有以下属性:
itemdiscoveryid - (string) item discovery的ID
itemid - (string) 已发现Item的ID
parent_itemid - (string) 已经创建项的项原型的ID;
key_ - (string) key of the item prototype;
lastcheck - (timestamp) 最后一次发现item的时间
ts_delete - (timestamp) 不再发现的项将被删除的时间。
filter object 仅返回与给定过滤器完全匹配的结果。

接受一个数组,其中keys是属性名称,并且值是单个值或要匹配的值的数组。

支持附加的过滤器:
host - 该项所属主机的技术名称。
limitSelects integer 限制子选择返回的记录数。

适用于以下子选项:
selectGraphs - 结果将按“'name”排序;
selectTriggers - results will be sorted by description.结果将按“'description'排序。
sortfield string/array 按照给定的属性对结果进行排序。

Possible values are: itemid, name, key_, delay, history, trends, type and status. 可能的值是:itemidnamekey_delayhistorytrendstype和''status'”。
countOutput flag These parameters being common for all get methods are described in detail in the reference commentary page. 这些参数对于所有的“获取”方法是常见的,在参考评论页中有详细描述。
editable boolean
excludeSearch flag
limit integer
output query
preservekeys flag
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch flag

Return values

(integer/array) Returns either:

  • an array of objects;
  • the count of retrieved objects, if the countOutput parameter has been used.

示例

通过 Key 查询 Items

从key中具有“system”一词的ID为“10084”的主机检索所有项,并按名称进行排序。

Request:

{
           "jsonrpc": "2.0",
           "method": "item.get",
           "params": {
               "output": "extend",
               "hostids": "10084",
               "search": {
                   "key_": "system"
               },
               "sortfield": "name"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "23298",
                   "type": "0",
                   "snmp_community": "",
                   "snmp_oid": "",
                   "hostid": "10084",
                   "name": "Context switches per second",
                   "key_": "system.cpu.switches",
                   "delay": "1m",
                   "history": "7d",
                   "trends": "365d",
                   "lastvalue": "2552",
                   "lastclock": "1351090998",
                   "prevvalue": "2641",
                   "state": "0",
                   "status": "0",
                   "value_type": "3",
                   "trapper_hosts": "",
                   "units": "sps",
                   "multiplier": "0",
                   "delta": "1",
                   "snmpv3_securityname": "",
                   "snmpv3_securitylevel": "0",
                   "snmpv3_authpassphrase": "",
                   "snmpv3_privpassphrase": "",
                   "snmpv3_authprotocol": "0",
                   "snmpv3_privprotocol": "0",
                   "snmpv3_contextname": "",
                   "formula": "1",
                   "error": "",
                   "lastlogsize": "0",
                   "logtimefmt": "",
                   "templateid": "22680",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "data_type": "0",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "mtime": "0",
                   "lastns": "564054253",
                   "flags": "0",
                   "interfaceid": "1",
                   "port": "",
                   "description": "",
                   "inventory_link": "0",
                   "lifetime": "0s",
                   "evaltype": "0"
               },
               {
                   "itemid": "23299",
                   "type": "0",
                   "snmp_community": "",
                   "snmp_oid": "",
                   "hostid": "10084",
                   "name": "CPU $2 time",
                   "key_": "system.cpu.util[,idle]",
                   "delay": "1m",
                   "history": "7d",
                   "trends": "365d",
                   "lastvalue": "86.031879",
                   "lastclock": "1351090999",
                   "prevvalue": "85.306944",
                   "state": "0",
                   "status": "0",
                   "value_type": "0",
                   "trapper_hosts": "",
                   "units": "%",
                   "multiplier": "0",
                   "delta": "0",
                   "snmpv3_securityname": "",
                   "snmpv3_securitylevel": "0",
                   "snmpv3_authpassphrase": "",
                   "snmpv3_privpassphrase": "",
                   "snmpv3_authprotocol": "0",
                   "snmpv3_privprotocol": "0",
                   "snmpv3_contextname": "",
                   "formula": "1",
                   "error": "",
                   "lastlogsize": "0",
                   "logtimefmt": "",
                   "templateid": "17354",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "data_type": "0",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "mtime": "0",
                   "lastns": "564256864",
                   "flags": "0",
                   "interfaceid": "1",
                   "port": "",
                   "description": "The time the CPU has spent doing nothing.",
                   "inventory_link": "0",
                   "lifetime": "0s",
                   "evaltype": "0"
               },
               {
                   "itemid": "23300",
                   "type": "0",
                   "snmp_community": "",
                   "snmp_oid": "",
                   "hostid": "10084",
                   "name": "CPU $2 time",
                   "key_": "system.cpu.util[,interrupt]",
                   "history": "7d",
                   "trends": "365d",
                   "lastvalue": "0.008389",
                   "lastclock": "1351091000",
                   "prevvalue": "0.000000",
                   "state": "0",
                   "status": "0",
                   "value_type": "0",
                   "trapper_hosts": "",
                   "units": "%",
                   "multiplier": "0",
                   "delta": "0",
                   "snmpv3_securityname": "",
                   "snmpv3_securitylevel": "0",
                   "snmpv3_authpassphrase": "",
                   "snmpv3_privpassphrase": "",
                   "snmpv3_authprotocol": "0",
                   "snmpv3_privprotocol": "0",
                   "snmpv3_contextname": "",
                   "formula": "1",
                   "error": "",
                   "lastlogsize": "0",
                   "logtimefmt": "",
                   "templateid": "22671",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "data_type": "0",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "mtime": "0",
                   "lastns": "564661387",
                   "flags": "0",
                   "interfaceid": "1",
                   "port": "",
                   "description": "The amount of time the CPU has been servicing hardware interrupts.",
                   "inventory_link": "0",
                   "lifetime": "0s",
                   "evaltype": "0"
               }
           ],
           "id": 1
       }

参见

来源

CItem::get() in frontends/php/include/classes/api/services/CItem.php.