这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.
2022 Zabbix中国峰会
2022 Zabbix中国峰会

获取

说明

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 仅返回给定触发器中使用的监控项。
webitems flag 设置返回结果中包含 web 监控项。
inherited boolean 如果设置为 true ,仅返回从模板继承的监控项。
templated boolean 如果设置为 true ,仅返回属于模板的监控项。
monitored boolean 如果设置为 true ,仅返回属于受监控主机的已启用监控项。
group string 仅返回属于给定名称的组的监控项。
host string 仅返回属于给定名称的主机的监控项。
evaltype integer 标签搜索规则。

可用值:
0 - (默认) And/Or(与/或);
2 - Or(或)。
tags array of objects 仅返回给定标签的监控项。根据标签进行精确匹配,并根据运算符对标签进行区分大小写或不区分大小写搜索。
格式: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...].
空数组会返回所有监控项。

可选操作类型:
0 - (默认) Like(相似);
1 - Equal(相等);
2 - Not like(不相似);
3 - Not equal(不相等);
4 - Exists(存在);
5 - Not exists(不存在)。
with_triggers boolean 如果设置为 true ,则只返回在触发器中使用的监控项。
selectHosts query 返回 主机 属性,其中包含监控项所属主机。
selectInterfaces query 返回 接口 属性,其中包含监控项所使用的主机接口。
selectTriggers query 返回 触发器 属性,其中包含监控项所使用的触发器。

支持 count
selectGraphs query 返回 图表 属性,其中包含监控项所使用的图表。

支持 count
selectDiscoveryRule query 返回 发现规则 属性,其中包含用于创建监控项的 LLD 规则。
selectItemDiscovery query 返回 itemDiscovery 属性,其中包含监控项的发现对象。监控项发现对象将监控项链接到创建此监控项的监控项原型中。

包含属性如下:
itemdiscoveryid - (string) 监控项发现 ID ;
itemid - (string) 已发现的监控项 ID ;
parent_itemid - (string) 创建监控项的监控项原型的 ID ;
key_ - (string) 监控项原型关键字;
lastcheck - (timestamp) 监控项最后发现时间;
ts_delete - (timestamp) 监控项不再被发现,将被删除的时间。
selectPreprocessing query 返回 预处理 属性,其中包含监控项的预处理选项。

包含属性如下:
type - (string) 预处理选项类型:
1 - Custom multiplier(自定义乘数);
2 - Right trim(移除右侧空白字符);
3 - Left trim(移除左侧空白字符);
4 - Trim(移除空白字符);
5 - Regular expression matching(正则表达式匹配);
6 - Boolean to decimal(布尔值转换十进制);
7 - Octal to decimal(八进制转换十进制);
8 - Hexadecimal to decimal(十六进制转十进制);
9 - Simple change(先前值到新值的基本变化);
10 - Change per second(每秒钟变化量);
11 - XML XPath(XML 解析);
12 - JSONPath(JSON解析);
13 - In range(生成序列);
14 - Matches regular expression(匹配正则表达式);
15 - Does not match regular expression(不匹配正则表达式);
16 - Check for error in JSON(检查 JSON 错误);
17 - Check for error in XML(检查 XML 错误);
18 - Check for error using regular expression(检查正则表达式使用错误);
19 - Discard unchanged(丢弃重复数据);
20 - Discard unchanged with heartbeat(设置心跳检查周期,丢弃重复数据);
21 - JavaScript(JS格式);
22 - Prometheus pattern(Prometheus 模板);
23 - Prometheus to JSON(Prometheus 转换 JSON);
24 - CSV to JSON(CSV 转换 JSON);
25 - Replace(替换);
26 - Check for not supported value(检查不支持的值);
27 - XML to JSON(XML 转换 JSON)。

params - (string) 预处理选项使用的其他参数。多个参数由LF(\n)字符分隔。
error_handler - (string) 预处理步骤失败时使用的操作类型:
0 - Error message is set by Zabbix server(Zabbix 服务器自带错误消息);
1 - Discard value(丢弃值);
2 - Set custom value(设置自定义值);
3 - Set custom error message(设置自定义错误信息)。

error_handler_params - (string) 错误处理器参数。
selectTags query 返回 标签 属性,其中包含监控项的标签。
selectValueMap query 返回 映射表 属性,其中包含监控项的映射表。
filter object 仅返回精准匹配给定筛选条件的结果。

接受传入数组,其中键是属性名,值可以是单个值,也可以是一组要匹配的值。

支持的额外过滤选项:
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 为 “10084” 的主机包含关键字 “系统” 一词的所有监控项,并按名称排序。

请求:

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

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "23298",
                   "type": "0",
                   "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",
                   "error": "",
                   "logtimefmt": "",
                   "templateid": "22680",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "lastns": "564054253",
                   "flags": "0",
                   "interfaceid": "1",
                   "description": "",
                   "inventory_link": "0",
                   "lifetime": "0s",
                   "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",
                   "parameters": []
               },
               {
                   "itemid": "23299",
                   "type": "0",
                   "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": "%",
                   "error": "",
                   "logtimefmt": "",
                   "templateid": "17354",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "lastns": "564256864",
                   "flags": "0",
                   "interfaceid": "1",
                   "description": "The time the CPU has spent doing nothing.",
                   "inventory_link": "0",
                   "lifetime": "0s",
                   "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",
                   "parameters": []
               },
               {
                   "itemid": "23300",
                   "type": "0",
                   "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": "%",
                   "error": "",
                   "logtimefmt": "",
                   "templateid": "22671",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "lastns": "564661387",
                   "flags": "0",
                   "interfaceid": "1",
                   "description": "The amount of time the CPU has been servicing hardware interrupts.",
                   "inventory_link": "0",
                   "lifetime": "0s",
                   "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",
                   "parameters": []
               }
           ],
           "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": "",
                   "history": "90d",
                   "trends": "365d",
                   "status": "0",
                   "value_type": "3",
                   "trapper_hosts": "",
                   "units": "",
                   "formula": "",
                   "error": "",
                   "logtimefmt": "",
                   "templateid": "0",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "0",
                   "description": "",
                   "inventory_link": "0",
                   "lifetime": "30d",
                   "state": "0",
                   "evaltype": "0",
                   "master_itemid": "25545",
                   "jmx_endpoint": "",
                   "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",
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "parameters": []
               },
               {
                   "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": "",
                   "formula": "",
                   "error": "",
                   "logtimefmt": "",
                   "templateid": "0",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "0",
                   "description": "",
                   "inventory_link": "0",
                   "lifetime": "30d",
                   "state": "0",
                   "evaltype": "0",
                   "master_itemid": "25545",
                   "jmx_endpoint": "",
                   "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",
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "parameters": []
               }
           ],
           "id": 1
       }

查找 HTTP agent 监控项

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

请求:

{
           "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": "",
                   "formula": "",
                   "error": "",
                   "logtimefmt": "",
                   "templateid": "0",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "0",
                   "description": "",
                   "inventory_link": "0",
                   "lifetime": "30d",
                   "state": "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",
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "parameters": []
               }
           ],
           "id": 3
       }

检索预处理规则监控项

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

请求:

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

另请参阅

源码

ui/include/classes/api/services/CItem.php - CItem::get()