item.get

描述

integer/array item.get(object parameters)

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

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

参数

(object) 参数定义了期望的输出。

该方法支持以下参数。

参数 数据类型 描述
itemids ID/array 仅返回具有给定 ID 的 监控项。
groupids ID/array 仅返回属于给定组中主机的监控项。
templateids ID/array 仅返回属于给定模板的监控项。
hostids ID/array 仅返回属于给定主机的监控项。
proxyids ID/array 仅返回由给定proxies监控的监控项。
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 - (默认)And/Or;
2 - Or。
tags array 仅返回具有指定标签的监控项。根据操作符的值,按标签进行精确匹配或对标签值进行区分大小写或不区分大小写的搜索。
格式:[{"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 返回一个包含创建 监控项 的LLD规则的 discoveryRule 属性。
selectItemDiscovery query 返回一个包含 itemDiscovery 属性的属性,该属性与 监控项 自动发现 object 相关联。监控项 自动发现 object 将 监控项 与其创建来源的 监控项 原型进行关联。

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

接受一个object,其中键为属性名称,值为单个值或一个array值列表进行匹配。

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

支持额外的属性:
host - 监控项所属主机的技术名称。
limitSelects integer 限制子查询返回的记录数量。

适用于以下子查询:
selectGraphs - 结果将按照 name 排序;
selectTriggers - 结果将按照 description 排序。
sortfield string/array 按照指定属性对结果进行排序。

可能的值:itemidnamekey_delayhistorytrendstypestatus
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) 返回以下之一:

  • objects 的 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"
           },
           "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_resolved": "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 agent 监控项

查找 HTTP agent 监控项,其 post body 类型为 XML,并针对特定的 主机 ID。

执行请求:

{
           "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 的所有 监控项 及其预处理规则。

执行请求:

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

另请参阅

来源

ui/include/classes/api/services/CItem.php 中的 CItem::get()。